Skip to content

Commit

Permalink
Reduce moose knockback taken, prevent pushing moose, make moose break…
Browse files Browse the repository at this point in the history
… lilypads, tweak water movement and stop them from swimming
  • Loading branch information
itsmeow committed Nov 11, 2019
1 parent 7acb303 commit 830b750
Showing 1 changed file with 62 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<EntityPlayer>(this, EntityPlayer.class, 75, true, true, e -> e.getDistance(this) < 15));
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 830b750

Please sign in to comment.