From 830b750cfafba40da799f8a001060955bbf0533c Mon Sep 17 00:00:00 2001 From: itsmeow Date: Mon, 11 Nov 2019 03:28:07 -0500 Subject: [PATCH] Reduce moose knockback taken, prevent pushing moose, make moose break lilypads, tweak water movement and stop them from swimming --- .../common/entity/EntityMoose.java | 67 +++++++++++++++++-- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/src/main/java/its_meow/betteranimalsplus/common/entity/EntityMoose.java b/src/main/java/its_meow/betteranimalsplus/common/entity/EntityMoose.java index bf184835..fd012d1c 100644 --- a/src/main/java/its_meow/betteranimalsplus/common/entity/EntityMoose.java +++ b/src/main/java/its_meow/betteranimalsplus/common/entity/EntityMoose.java @@ -4,19 +4,26 @@ import its_meow.betteranimalsplus.common.entity.ai.EntityAIEatGrassCustom; import its_meow.betteranimalsplus.util.HeadTypes; +import net.minecraft.block.state.IBlockState; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IEntityLivingData; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIAttackMelee; import net.minecraft.entity.ai.EntityAIHurtByTarget; +import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityAINearestAttackableTarget; -import net.minecraft.entity.ai.EntityAISwimming; import net.minecraft.entity.ai.EntityAIWander; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; import net.minecraft.util.EnumFacing; +import net.minecraft.util.ReportedException; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.DifficultyInstance; import net.minecraft.world.World; @@ -26,14 +33,15 @@ public class EntityMoose extends EntityAnimalEatsGrassWithTypes { public EntityMoose(World worldIn) { super(worldIn, 5); this.setSize(2.25F, 3F); + this.stepHeight = 1F; } @Override protected void initEntityAI() { super.initEntityAI(); - this.tasks.addTask(0, new EntityAISwimming(this)); - this.tasks.addTask(1, new EntityAIWander(this, 0.55D)); + this.tasks.addTask(1, new EntityAIWander(this, 0.65D)); this.tasks.addTask(2, new EntityAIAttackMelee(this, 0.65D, false)); + this.tasks.addTask(3, new EntityAILookIdle(this)); this.targetTasks.addTask(0, new EntityAIHurtByTarget(this, false, (Class) null)); this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 75, true, true, e -> e.getDistance(this) < 15)); } @@ -45,12 +53,17 @@ protected void applyEntityAttributes() { this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.6D); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE); this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(4.5D); - this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(0.5D); + this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(0.7D); } @Override protected float getWaterSlowDown() { - return 0.98F; + return 0.9F; + } + + @Override + protected void collideWithNearbyEntities() { + // prevent pushing } protected EntityAIEatGrassCustom provideEatTask() { @@ -80,6 +93,50 @@ public void onDeath(DamageSource cause) { } } + protected void doBlockCollisions() + { + AxisAlignedBB axisalignedbb = this.getEntityBoundingBox(); + BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain(axisalignedbb.minX + 0.001D, axisalignedbb.minY + 0.001D, axisalignedbb.minZ + 0.001D); + BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos1 = BlockPos.PooledMutableBlockPos.retain(axisalignedbb.maxX - 0.001D, axisalignedbb.maxY - 0.001D, axisalignedbb.maxZ - 0.001D); + BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos2 = BlockPos.PooledMutableBlockPos.retain(); + + if (this.world.isAreaLoaded(blockpos$pooledmutableblockpos, blockpos$pooledmutableblockpos1)) + { + for (int i = blockpos$pooledmutableblockpos.getX(); i <= blockpos$pooledmutableblockpos1.getX(); ++i) + { + for (int j = blockpos$pooledmutableblockpos.getY(); j <= blockpos$pooledmutableblockpos1.getY(); ++j) + { + for (int k = blockpos$pooledmutableblockpos.getZ(); k <= blockpos$pooledmutableblockpos1.getZ(); ++k) + { + blockpos$pooledmutableblockpos2.setPos(i, j, k); + IBlockState iblockstate = this.world.getBlockState(blockpos$pooledmutableblockpos2); + + try + { + iblockstate.getBlock().onEntityCollidedWithBlock(this.world, blockpos$pooledmutableblockpos2, iblockstate, this); + this.onInsideBlock(iblockstate); + if(iblockstate.getBlock() == Blocks.WATERLILY) { + iblockstate.getBlock().dropBlockAsItem(world, blockpos$pooledmutableblockpos2.toImmutable(), iblockstate, 0); + world.setBlockToAir(blockpos$pooledmutableblockpos2.toImmutable()); + } + } + catch (Throwable throwable) + { + CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Colliding entity with block"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Block being collided with"); + CrashReportCategory.addBlockInfo(crashreportcategory, blockpos$pooledmutableblockpos2, iblockstate); + throw new ReportedException(crashreport); + } + } + } + } + } + + blockpos$pooledmutableblockpos.release(); + blockpos$pooledmutableblockpos1.release(); + blockpos$pooledmutableblockpos2.release(); + } + @Override public int getVariantMax() { return 4;