initial commit

This commit is contained in:
Sen 2025-03-11 00:23:54 +01:00 committed by Sen
parent 3c9ee26b06
commit 22186c33b9
1458 changed files with 282792 additions and 0 deletions

View file

@ -0,0 +1,118 @@
package game.ai;
import java.util.function.Predicate;
import game.Predicates;
import game.block.BlockTallGrass;
import game.entity.animal.EntitySheep;
import game.init.BlockRegistry;
import game.init.Blocks;
import game.init.Config;
import game.pattern.BlockStateHelper;
import game.world.BlockPos;
import game.world.State;
import game.world.World;
public class EntityAIEatGrass extends EntityAIBase
{
private static final Predicate<State> field_179505_b = BlockStateHelper.forBlock(Blocks.tallgrass).where(BlockTallGrass.TYPE, Predicates.equalTo(BlockTallGrass.EnumType.GRASS));
private EntitySheep grassEaterEntity;
private World entityWorld;
int eatingGrassTimer;
public EntityAIEatGrass(EntitySheep grassEaterEntityIn)
{
this.grassEaterEntity = grassEaterEntityIn;
this.entityWorld = grassEaterEntityIn.worldObj;
this.setMutexBits(7);
}
/**
* Returns whether the EntityAIBase should begin execution.
*/
public boolean shouldExecute()
{
if (this.grassEaterEntity.getRNG().zrange(this.grassEaterEntity.isChild() ? 50 : 1000) != 0)
{
return false;
}
else
{
BlockPos blockpos = new BlockPos(this.grassEaterEntity.posX, this.grassEaterEntity.posY, this.grassEaterEntity.posZ);
return field_179505_b.test(this.entityWorld.getState(blockpos)) ? true : this.entityWorld.getState(blockpos.down()).getBlock() == Blocks.grass;
}
}
/**
* Execute a one shot task or start executing a continuous task
*/
public void startExecuting()
{
this.eatingGrassTimer = 40;
this.entityWorld.setEntityState(this.grassEaterEntity, (byte)10);
this.grassEaterEntity.getNavigator().clearPathEntity();
}
/**
* Resets the task
*/
public void resetTask()
{
this.eatingGrassTimer = 0;
}
/**
* Returns whether an in-progress EntityAIBase should continue executing
*/
public boolean continueExecuting()
{
return this.eatingGrassTimer > 0;
}
/**
* Number of ticks since the entity started to eat grass
*/
public int getEatingGrassTimer()
{
return this.eatingGrassTimer;
}
/**
* Updates the task
*/
public void updateTask()
{
this.eatingGrassTimer = Math.max(0, this.eatingGrassTimer - 1);
if (this.eatingGrassTimer == 4)
{
BlockPos blockpos = new BlockPos(this.grassEaterEntity.posX, this.grassEaterEntity.posY, this.grassEaterEntity.posZ);
if (field_179505_b.test(this.entityWorld.getState(blockpos)))
{
if (Config.mobGrief)
{
this.entityWorld.destroyBlock(blockpos, false);
}
this.grassEaterEntity.eatGrassBonus();
}
else
{
BlockPos blockpos1 = blockpos.down();
if (this.entityWorld.getState(blockpos1).getBlock() == Blocks.grass)
{
if (Config.mobGrief)
{
this.entityWorld.playAuxSFX(2001, blockpos1, BlockRegistry.getIdFromBlock(Blocks.grass));
this.entityWorld.setState(blockpos1, Blocks.dirt.getState(), 2);
}
this.grassEaterEntity.eatGrassBonus();
}
}
}
}
}