From 6f2cf2e2a3bf0d0311ec03fa95fdc175c5044162 Mon Sep 17 00:00:00 2001 From: Me <135455255+IcarussOne@users.noreply.github.com> Date: Tue, 1 Oct 2024 05:18:44 -0500 Subject: [PATCH] Finalize zombies --- .../entity/EntityTFLoyalZombie.java | 229 ++++++++++-------- .../item/scepter/ItemTFScepterZombie.java | 4 +- 2 files changed, 130 insertions(+), 103 deletions(-) diff --git a/src/main/java/twilightforest/entity/EntityTFLoyalZombie.java b/src/main/java/twilightforest/entity/EntityTFLoyalZombie.java index f94f98d855..04db8a1f23 100644 --- a/src/main/java/twilightforest/entity/EntityTFLoyalZombie.java +++ b/src/main/java/twilightforest/entity/EntityTFLoyalZombie.java @@ -24,112 +24,137 @@ import net.minecraft.entity.passive.EntityTameable; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.SoundEvents; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import twilightforest.util.ParticleHelper; public class EntityTFLoyalZombie extends EntityTameable { - - public EntityTFLoyalZombie(World world) { - super(world); - this.setSize(0.6F, 1.8F); - } - - @Override - protected void initEntityAI() { - this.tasks.addTask(1, new EntityAISwimming(this)); - this.tasks.addTask(4, new EntityAIAttackMelee(this, 1.0D, true)); - this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F)); - this.tasks.addTask(7, new EntityAIWanderAvoidWater(this, 1.0D)); - this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); - this.tasks.addTask(9, new EntityAILookIdle(this)); - this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this)); - this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this)); - this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true)); - this.targetTasks.addTask(4, new EntityAINearestAttackableTarget<>(this, EntityMob.class, true)); - } - - @Override - public EntityAnimal createChild(EntityAgeable entityanimal) { - return null; - } - - @Override - protected void applyEntityAttributes() { - super.applyEntityAttributes(); - this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(40.0D); - this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.3D); - this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(3.0D); - } - - @Override - public boolean attackEntityAsMob(Entity entity) { - boolean success = entity.attackEntityFrom(DamageSource.causeMobDamage(this), 5); - - if (success) { - entity.motionY += 0.2; - } - - return success; - } - - /*@Override - public void onLivingUpdate() { - // once our damage boost effect wears out, start to burn - // the effect here is that we die shortly after our 60 second lifespan - if (!this.world.isRemote && this.getActivePotionEffect(MobEffects.STRENGTH) == null) { - this.setFire(100); - } - - super.onLivingUpdate(); - }*/ - - // [VanillaCopy] EntityWolf.shouldAttackEntity, substituting with our class - @Override - public boolean shouldAttackEntity(EntityLivingBase target, EntityLivingBase owner) { - if (!(target instanceof EntityCreeper) && !(target instanceof EntityGhast)) { - if (target instanceof EntityTFLoyalZombie) { - EntityTFLoyalZombie zombie = (EntityTFLoyalZombie) target; - - if (zombie.isTamed() && zombie.getOwner() == owner) { - return false; - } - } - - return target instanceof EntityPlayer && owner instanceof EntityPlayer && !((EntityPlayer) owner).canAttackPlayer((EntityPlayer) target) ? false : !(target instanceof AbstractHorse) || !((AbstractHorse) target).isTame(); - } else { - return false; - } - } - - @Override - protected boolean canDespawn() { - return true; - } - - @Override - protected SoundEvent getAmbientSound() { - return SoundEvents.ENTITY_ZOMBIE_AMBIENT; - } - - @Override - protected SoundEvent getHurtSound(DamageSource source) { - return SoundEvents.ENTITY_ZOMBIE_HURT; - } - - @Override - protected SoundEvent getDeathSound() { - return SoundEvents.ENTITY_ZOMBIE_DEATH; - } - - @Override - protected void playStepSound(BlockPos pos, Block block) { - playSound(SoundEvents.ENTITY_ZOMBIE_STEP, 0.15F, 1.0F); - } - - @Override - public EnumCreatureAttribute getCreatureAttribute() { - return EnumCreatureAttribute.UNDEAD; - } + protected int limitedLifeTicks; + + public EntityTFLoyalZombie(World world) { + super(world); + this.setSize(0.6F, 1.8F); + this.limitedLifeTicks = -1; + } + + @Override + protected void initEntityAI() { + this.tasks.addTask(1, new EntityAISwimming(this)); + this.tasks.addTask(4, new EntityAIAttackMelee(this, 1.0D, true)); + this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F)); + this.tasks.addTask(7, new EntityAIWanderAvoidWater(this, 1.0D)); + this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); + this.tasks.addTask(9, new EntityAILookIdle(this)); + this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this)); + this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this)); + this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true)); + this.targetTasks.addTask(4, new EntityAINearestAttackableTarget<>(this, EntityMob.class, true)); + } + + @Override + public EntityAnimal createChild(EntityAgeable entityanimal) { + return null; + } + + @Override + protected void applyEntityAttributes() { + super.applyEntityAttributes(); + this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(40.0D); + this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.3D); + this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(3.0D); + } + + public void setLimitedLife(int limitedLifeTicksIn) { + if (limitedLifeTicksIn != 0) { + this.limitedLifeTicks = limitedLifeTicksIn; + } + } + + @Override + public boolean attackEntityAsMob(Entity entity) { + boolean success = entity.attackEntityFrom(DamageSource.causeMobDamage(this), 5); + + if (success) { + entity.motionY += 0.2; + } + + return success; + } + + @Override + public void onUpdate() { + if (this.isTamed() && this.limitedLifeTicks >= 0 && this.ticksExisted >= this.limitedLifeTicks || this.isTamed() && this.getOwner() == null) { + if (!this.world.isRemote) { + ParticleHelper.spawnParticles(this, EnumParticleTypes.EXPLOSION_NORMAL, 20, 0.02D); + } + + this.setDead(); + } + + super.onUpdate(); + } + + // [VanillaCopy] EntityWolf.shouldAttackEntity, substituting with our class + @Override + public boolean shouldAttackEntity(EntityLivingBase target, EntityLivingBase owner) { + if (!(target instanceof EntityCreeper) && !(target instanceof EntityGhast)) { + if (target instanceof EntityTFLoyalZombie) { + EntityTFLoyalZombie zombie = (EntityTFLoyalZombie) target; + + if (zombie.isTamed() && zombie.getOwner() == owner) { + return false; + } + } + + return target instanceof EntityPlayer && owner instanceof EntityPlayer && !((EntityPlayer) owner).canAttackPlayer((EntityPlayer) target) ? false : !(target instanceof AbstractHorse) || !((AbstractHorse) target).isTame(); + } else { + return false; + } + } + + @Override + public void readEntityFromNBT(NBTTagCompound compound) { + super.readEntityFromNBT(compound); + this.setLimitedLife(compound.getInteger("LifeTicks")); + } + + @Override + public void writeEntityToNBT(NBTTagCompound compound) { + super.writeEntityToNBT(compound); + compound.setInteger("LifeTicks", this.limitedLifeTicks - this.ticksExisted); + } + + @Override + protected boolean canDespawn() { + return !this.isTamed(); + } + + @Override + protected SoundEvent getAmbientSound() { + return SoundEvents.ENTITY_ZOMBIE_AMBIENT; + } + + @Override + protected SoundEvent getHurtSound(DamageSource source) { + return SoundEvents.ENTITY_ZOMBIE_HURT; + } + + @Override + protected SoundEvent getDeathSound() { + return SoundEvents.ENTITY_ZOMBIE_DEATH; + } + + @Override + protected void playStepSound(BlockPos pos, Block block) { + playSound(SoundEvents.ENTITY_ZOMBIE_STEP, 0.15F, 1.0F); + } + + @Override + public EnumCreatureAttribute getCreatureAttribute() { + return EnumCreatureAttribute.UNDEAD; + } } diff --git a/src/main/java/twilightforest/item/scepter/ItemTFScepterZombie.java b/src/main/java/twilightforest/item/scepter/ItemTFScepterZombie.java index 9530d9e955..08b78e6f53 100644 --- a/src/main/java/twilightforest/item/scepter/ItemTFScepterZombie.java +++ b/src/main/java/twilightforest/item/scepter/ItemTFScepterZombie.java @@ -52,13 +52,15 @@ public ActionResult onItemRightClick(@Nonnull World world, EntityPlay zombie.setPositionAndRotation(ray.hitVec.x, ray.hitVec.y, ray.hitVec.z, 1.0F, 1.0F); zombie.setTamed(true); zombie.setOwnerId(player.getUniqueID()); + zombie.addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 30 * 20, 0)); + zombie.setLimitedLife(90 * 20); world.spawnEntity(zombie); stack.damageItem(1, player); } if (!player.isCreative()) - player.getCooldownTracker().setCooldown(this, 140); + player.getCooldownTracker().setCooldown(this, 100); } return ActionResult.newResult(EnumActionResult.SUCCESS, stack);