From 24b023bacffb7a65e5c6c9cadd96b8c65507b3d9 Mon Sep 17 00:00:00 2001 From: itsmeow Date: Tue, 12 Nov 2019 09:44:06 -0500 Subject: [PATCH] Finish turkey AI and add drops, todo turkey food block --- .../common/entity/EntityTurkey.java | 70 ++++++++++++++++--- .../betteranimalsplus/init/ModLootTables.java | 3 + .../betteranimalsplus/loot_tables/turkey.json | 31 ++++++++ 3 files changed, 95 insertions(+), 9 deletions(-) create mode 100644 src/main/resources/assets/betteranimalsplus/loot_tables/turkey.json diff --git a/src/main/java/its_meow/betteranimalsplus/common/entity/EntityTurkey.java b/src/main/java/its_meow/betteranimalsplus/common/entity/EntityTurkey.java index 21bce64c..9a30303b 100644 --- a/src/main/java/its_meow/betteranimalsplus/common/entity/EntityTurkey.java +++ b/src/main/java/its_meow/betteranimalsplus/common/entity/EntityTurkey.java @@ -3,9 +3,14 @@ import javax.annotation.Nullable; import its_meow.betteranimalsplus.init.ModItems; +import its_meow.betteranimalsplus.init.ModLootTables; import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.EntityAIAttackMelee; import net.minecraft.entity.ai.EntityAIFollowParent; +import net.minecraft.entity.ai.EntityAIHurtByTarget; import net.minecraft.entity.ai.EntityAIMate; import net.minecraft.entity.ai.EntityAIPanic; import net.minecraft.entity.ai.EntityAISwimming; @@ -37,6 +42,8 @@ public class EntityTurkey extends EntityAnimalWithTypes { public float oFlap; public float wingRotDelta = 0.3F; public int timeUntilNextEgg; + public int attacksLeft = 0; + public int lastAttackTime = 0; public EntityTurkey(World worldIn) { super(worldIn); @@ -49,12 +56,46 @@ public EntityTurkey(World worldIn) { @Override protected void initEntityAI() { this.tasks.addTask(0, new EntityAISwimming(this)); - this.tasks.addTask(1, new EntityAIPanic(this, 1.4D)); - this.tasks.addTask(2, new EntityAIMate(this, 1.0D)); - this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Items.WHEAT_SEEDS, false)); - this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D)); - this.tasks.addTask(5, new EntityAIWanderAvoidWater(this, 1.0D)); - this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F)); + this.tasks.addTask(1, new EntityAIAttackMelee(this, 1.1D, false) { + @Override + public void startExecuting() { + attacksLeft = this.attacker.getRNG().nextInt(2) + 1; + super.startExecuting(); + } + + @Override + public boolean shouldExecute() { + return super.shouldExecute() && this.attacker.ticksExisted - lastAttackTime > 300; + } + + @Override + public boolean shouldContinueExecuting() { + return attacksLeft > 0 && super.shouldContinueExecuting(); + } + + protected void checkAndPerformAttack(EntityLivingBase p_190102_1_, double p_190102_2_) { + if(attacksLeft > 0) { + super.checkAndPerformAttack(p_190102_1_, p_190102_2_); + } else { + this.resetTask(); + } + } + + @Override + public void resetTask() { + super.resetTask(); + if(attacksLeft <= 0) { + this.attacker.setAttackTarget(null); + } + } + }); + this.tasks.addTask(2, new EntityAIPanic(this, 1.4D)); + this.tasks.addTask(3, new EntityAIMate(this, 1.0D)); + this.tasks.addTask(4, new EntityAITempt(this, 1.0D, Items.PUMPKIN_SEEDS, false)); + this.tasks.addTask(5, new EntityAIFollowParent(this, 1.1D)); + this.tasks.addTask(6, new EntityAIWanderAvoidWater(this, 1.0D)); + this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F)); + this.targetTasks.addTask(0, new EntityAIHurtByTarget(this, false, new Class[0])); } @Override @@ -62,6 +103,18 @@ protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(4.0D); this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.25D); + this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE); + this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(1D); + } + + @Override + public boolean attackEntityAsMob(Entity entityIn) { + if(attacksLeft > 0) { + attacksLeft--; + } + float f = (float) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); + this.lastAttackTime = this.ticksExisted; + return entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), f); } private int getNewPeck() { @@ -114,7 +167,7 @@ public void onLivingUpdate() { public boolean processInteract(EntityPlayer player, EnumHand hand) { ItemStack itemstack = player.getHeldItem(hand); - if(itemstack.getItem() == Items.WHEAT_SEEDS && !this.isChild()) { + if(itemstack.getItem() == Items.PUMPKIN_SEEDS && !this.isChild()) { this.setInLove(player); if(!player.capabilities.isCreativeMode) { itemstack.shrink(1); @@ -147,8 +200,7 @@ protected void playStepSound(BlockPos pos, Block blockIn) { @Override @Nullable protected ResourceLocation getLootTable() { - return null; - //return ModLootTables.turkey; + return ModLootTables.TURKEY; } @Override diff --git a/src/main/java/its_meow/betteranimalsplus/init/ModLootTables.java b/src/main/java/its_meow/betteranimalsplus/init/ModLootTables.java index dbf4982c..3d575dfb 100644 --- a/src/main/java/its_meow/betteranimalsplus/init/ModLootTables.java +++ b/src/main/java/its_meow/betteranimalsplus/init/ModLootTables.java @@ -29,6 +29,8 @@ public class ModLootTables { public static final ResourceLocation SHARK = new ResourceLocation(Ref.MOD_ID, "shark"); + public static final ResourceLocation TURKEY = new ResourceLocation(Ref.MOD_ID, "turkey"); + public static void register() { LootTableList.register(deer); LootTableList.register(lammergeier); @@ -47,6 +49,7 @@ public static void register() { LootTableList.register(BEAR_BLACK); LootTableList.register(BEAR_KERMODE); LootTableList.register(SHARK); + LootTableList.register(TURKEY); } } diff --git a/src/main/resources/assets/betteranimalsplus/loot_tables/turkey.json b/src/main/resources/assets/betteranimalsplus/loot_tables/turkey.json new file mode 100644 index 00000000..5978a031 --- /dev/null +++ b/src/main/resources/assets/betteranimalsplus/loot_tables/turkey.json @@ -0,0 +1,31 @@ +{ + "pools": [ + { + "name": "turkey-feather", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "minecraft:feather", + "weight": 1, + "functions": [ + { + "function": "set_count", + "count": { + "min": 1, + "max": 2 + } + }, + { + "function": "looting_enchant", + "count": { + "min": 0, + "max": 1 + } + } + ] + } + ] + } + ] +}