-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature of zombie converting to villager
Showing
13 changed files
with
369 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# 0.2.0 | ||
- Zombie now can be cured into villager, using potion of weakness and enchanted golden apple. | ||
- Add hidden challenge "Real Zombie Doctor" advancement after "Zombie Veterinarian". | ||
|
||
# 0.1.0 | ||
- Zombiefied piglin and zoglin can be cured into piglin and hoglin, using potion of weakness and golden apple. | ||
- Add "Zombie Veterinarian" advancement after "Zombie Doctor" of minecraft. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/jimenezli/ZombieVeterinarian/advancements/CuredZombieTrigger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package jimenezli.ZombieVeterinarian.advancements; | ||
|
||
import com.google.gson.JsonObject; | ||
import jimenezli.ZombieVeterinarian.ZombieVeterinarianMod; | ||
import net.minecraft.advancements.criterion.AbstractCriterionTrigger; | ||
import net.minecraft.advancements.criterion.CriterionInstance; | ||
import net.minecraft.advancements.criterion.EntityPredicate; | ||
import net.minecraft.entity.player.ServerPlayerEntity; | ||
import net.minecraft.loot.ConditionArrayParser; | ||
import net.minecraft.loot.ConditionArraySerializer; | ||
import net.minecraft.util.ResourceLocation; | ||
|
||
public class CuredZombieTrigger extends AbstractCriterionTrigger<CuredZombieTrigger.Instance> { | ||
private static final ResourceLocation ID = ZombieVeterinarianMod.prefix("cured_zombie"); | ||
@Override | ||
public ResourceLocation getId() { | ||
return ID; | ||
} | ||
|
||
public CuredZombieTrigger.Instance createInstance(JsonObject p_230241_1_, EntityPredicate.AndPredicate p_230241_2_, ConditionArrayParser p_230241_3_) { | ||
EntityPredicate.AndPredicate entitypredicate$andpredicate = EntityPredicate.AndPredicate.fromJson(p_230241_1_, "zombie", p_230241_3_); | ||
EntityPredicate.AndPredicate entitypredicate$andpredicate1 = EntityPredicate.AndPredicate.fromJson(p_230241_1_, "villager", p_230241_3_); | ||
return new CuredZombieTrigger.Instance(p_230241_2_, entitypredicate$andpredicate, entitypredicate$andpredicate1); | ||
} | ||
public void trigger(ServerPlayerEntity p_192183_1_) { | ||
this.trigger(p_192183_1_, m -> true); | ||
} | ||
|
||
public static class Instance extends CriterionInstance { | ||
private final EntityPredicate.AndPredicate zombiepig; | ||
private final EntityPredicate.AndPredicate pig; | ||
|
||
public Instance(EntityPredicate.AndPredicate p_i231535_1_, EntityPredicate.AndPredicate p_i231535_2_, EntityPredicate.AndPredicate p_i231535_3_) { | ||
super(CuredZombieTrigger.ID, p_i231535_1_); | ||
this.zombiepig = p_i231535_2_; | ||
this.pig = p_i231535_3_; | ||
} | ||
|
||
public JsonObject serializeToJson(ConditionArraySerializer p_230240_1_) { | ||
JsonObject jsonobject = super.serializeToJson(p_230240_1_); | ||
jsonobject.add("zombie", this.zombiepig.toJson(p_230240_1_)); | ||
jsonobject.add("villager", this.pig.toJson(p_230240_1_)); | ||
return jsonobject; | ||
} | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/jimenezli/ZombieVeterinarian/entity/ConvertingZombieEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package jimenezli.ZombieVeterinarian.entity; | ||
|
||
import jimenezli.ZombieVeterinarian.advancements.Advancements; | ||
import jimenezli.ZombieVeterinarian.util.IConverting; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.ILivingEntityData; | ||
import net.minecraft.entity.SpawnReason; | ||
import net.minecraft.entity.merchant.villager.VillagerEntity; | ||
import net.minecraft.entity.monster.ZombieEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.player.ServerPlayerEntity; | ||
import net.minecraft.nbt.CompoundNBT; | ||
import net.minecraft.potion.EffectInstance; | ||
import net.minecraft.potion.Effects; | ||
import net.minecraft.util.SoundEvents; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.server.ServerWorld; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
|
||
import java.util.UUID; | ||
|
||
public class ConvertingZombieEntity extends ZombieEntity implements IConverting { | ||
private int conversionTime; | ||
private UUID conversionStarter; | ||
|
||
@Override | ||
public EntityType<?> getType() { | ||
return EntityType.ZOMBIE; | ||
} | ||
|
||
public void addAdditionalSaveData(CompoundNBT compoundNBT) { | ||
super.addAdditionalSaveData(compoundNBT); | ||
compoundNBT.putInt("ConversionTime", this.conversionTime); | ||
} | ||
|
||
public void readAdditionalSaveData(CompoundNBT compoundNBT) { | ||
super.readAdditionalSaveData(compoundNBT); | ||
if (compoundNBT.contains("ConversionTime")) { | ||
this.conversionTime = compoundNBT.getInt("ConversionTime"); | ||
this.conversionStarter = (compoundNBT.hasUUID("ConversionPlayer") ? compoundNBT.getUUID("ConversionPlayer") : null); | ||
} | ||
} | ||
|
||
public void setConversionStarter(UUID playerUUID) { | ||
this.conversionStarter = playerUUID; | ||
} | ||
|
||
public ConvertingZombieEntity(EntityType<? extends ZombieEntity> entityType, World world) { | ||
super(entityType, world); | ||
conversionTime = getTotalConversionTime(); | ||
conversionStarter = null; | ||
} | ||
|
||
public void tick() { | ||
if (!this.level.isClientSide && this.isAlive()) { | ||
int i = this.getConversionProgress(); | ||
this.conversionTime -= i; | ||
if (this.conversionTime <= 0 && net.minecraftforge.event.ForgeEventFactory.canLivingConvert(this, EntityType.VILLAGER, (timer) -> this.conversionTime = timer)) { | ||
this.finishConversion((ServerWorld)this.level); | ||
} | ||
} | ||
|
||
super.tick(); | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public void handleEntityEvent(byte b) { | ||
if (b == 16) { | ||
if (!this.isSilent()) { | ||
this.level.playLocalSound(this.getX(), this.getEyeY(), this.getZ(), SoundEvents.ZOMBIE_VILLAGER_CURE, this.getSoundSource(), 1.0F + this.random.nextFloat(), this.random.nextFloat() * 0.7F + 0.3F, false); | ||
} | ||
|
||
} else { | ||
super.handleEntityEvent(b); | ||
} | ||
} | ||
|
||
@Override | ||
public void finishConversion(ServerWorld world) { | ||
VillagerEntity villagerEntity = this.convertTo(EntityType.VILLAGER, true); | ||
if (villagerEntity != null) { | ||
villagerEntity.finalizeSpawn(world, world.getCurrentDifficultyAt(villagerEntity.blockPosition()), SpawnReason.CONVERSION, (ILivingEntityData) null, (CompoundNBT) null); | ||
villagerEntity.addEffect(new EffectInstance(Effects.CONFUSION, 200, 0)); | ||
net.minecraftforge.event.ForgeEventFactory.onLivingConvert(this, villagerEntity); | ||
} | ||
|
||
if (this.conversionStarter != null) { | ||
PlayerEntity playerEntity = world.getPlayerByUUID(this.conversionStarter); | ||
if (playerEntity instanceof ServerPlayerEntity) { | ||
Advancements.CURED_ZOMBIE.trigger((ServerPlayerEntity) playerEntity); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
{ | ||
"entity.zombieveterinarian.converting_zombified_piglin": "Converting Zombified Piglin", | ||
"entity.zombieveterinarian.converting_zoglin": "Converting Zoglin", | ||
"entity.zombieveterinarian.converting_zombie": "Converting Zombie", | ||
|
||
"advancements.zombieveterinarian.cure_zombie.title": "Real Zombie Doctor", | ||
"advancements.zombieveterinarian.cure_zombie.description": "Weaken and then cure a Zombie", | ||
"advancements.zombieveterinarian.cure_zombie_pig.title": "Zombie Veterinarian", | ||
"advancements.zombieveterinarian.cure_zombie_pig.description": "Weaken and then cure a Zombiefied Piglin or Zoglin" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
{ | ||
"entity.zombieveterinarian.converting_zombified_piglin": "转变中的僵尸猪灵", | ||
"entity.zombieveterinarian.converting_zoglin": "转变中的僵尸疣猪兽", | ||
"entity.zombieveterinarian.converting_zombie": "转变中的僵尸", | ||
|
||
"advancements.zombieveterinarian.cure_zombie_pig.title": "僵尸科兽医", | ||
"advancements.zombieveterinarian.cure_zombie_pig.description": "弱化并治疗一只僵尸猪灵或僵尸疣猪兽" | ||
"advancements.zombieveterinarian.cure_zombie_pig.description": "弱化并治疗一只僵尸猪灵或僵尸疣猪兽", | ||
"advancements.zombieveterinarian.cure_zombie.title": "真·僵尸科医生", | ||
"advancements.zombieveterinarian.cure_zombie.description": "弱化并治疗一只僵尸" | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/resources/data/zombieveterinarian/advancements/cure_zombie.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"display": { | ||
"icon": { | ||
"item": "minecraft:enchanted_golden_apple" | ||
}, | ||
"title": { | ||
"translate": "advancements.zombieveterinarian.cure_zombie.title" | ||
}, | ||
"description": { | ||
"translate": "advancements.zombieveterinarian.cure_zombie.description" | ||
}, | ||
"frame": "challenge", | ||
"show_toast": true, | ||
"announce_to_chat": true, | ||
"hidden": true | ||
}, | ||
"rewards": { | ||
"experience": 100 | ||
}, | ||
"parent": "zombieveterinarian:cure_zombie_pig", | ||
"criteria": { | ||
"cured_zombie_pig": { | ||
"trigger": "zombieveterinarian:cured_zombie", | ||
"conditions": {} | ||
} | ||
}, | ||
"requirements": [ | ||
[ | ||
"cured_zombie_pig" | ||
] | ||
] | ||
} |