| 1 | package net.minecraft.entity.ai;
|
| 2 |
|
| 3 | import net.minecraft.block.Block;
|
| 4 | import net.minecraft.block.BlockBed;
|
| 5 | import net.minecraft.block.state.IBlockState;
|
| 6 | import net.minecraft.entity.passive.EntityOcelot;
|
| 7 | import net.minecraft.init.Blocks;
|
| 8 | import net.minecraft.tileentity.TileEntity;
|
| 9 | import net.minecraft.tileentity.TileEntityChest;
|
| 10 | import net.minecraft.util.BlockPos;
|
| 11 | import net.minecraft.world.World;
|
| 12 |
|
| 13 | public class EntityAIOcelotSit extends EntityAIMoveToBlock
|
| 14 | {
|
| 15 | private final EntityOcelot ocelot;
|
| 16 |
|
| 17 | public EntityAIOcelotSit(EntityOcelot ocelotIn, double p_i45315_2_)
|
| 18 | {
|
| 19 | super(ocelotIn, p_i45315_2_, 8);
|
| 20 | this.ocelot = ocelotIn;
|
| 21 | }
|
| 22 |
|
| 23 | /**
|
| 24 | * Returns whether the EntityAIBase should begin execution.
|
| 25 | */
|
| 26 | public boolean shouldExecute()
|
| 27 | {
|
| 28 | return this.ocelot.isTamed() && !this.ocelot.isSitting() && super.shouldExecute();
|
| 29 | }
|
| 30 |
|
| 31 | /**
|
| 32 | * Returns whether an in-progress EntityAIBase should continue executing
|
| 33 | */
|
| 34 | public boolean continueExecuting()
|
| 35 | {
|
| 36 | return super.continueExecuting();
|
| 37 | }
|
| 38 |
|
| 39 | /**
|
| 40 | * Execute a one shot task or start executing a continuous task
|
| 41 | */
|
| 42 | public void startExecuting()
|
| 43 | {
|
| 44 | super.startExecuting();
|
| 45 | this.ocelot.getAISit().setSitting(false);
|
| 46 | }
|
| 47 |
|
| 48 | /**
|
| 49 | * Resets the task
|
| 50 | */
|
| 51 | public void resetTask()
|
| 52 | {
|
| 53 | super.resetTask();
|
| 54 | this.ocelot.setSitting(false);
|
| 55 | }
|
| 56 |
|
| 57 | /**
|
| 58 | * Updates the task
|
| 59 | */
|
| 60 | public void updateTask()
|
| 61 | {
|
| 62 | super.updateTask();
|
| 63 | this.ocelot.getAISit().setSitting(false);
|
| 64 |
|
| 65 | if (!this.getIsAboveDestination())
|
| 66 | {
|
| 67 | this.ocelot.setSitting(false);
|
| 68 | }
|
| 69 | else if (!this.ocelot.isSitting())
|
| 70 | {
|
| 71 | this.ocelot.setSitting(true);
|
| 72 | }
|
| 73 | }
|
| 74 |
|
| 75 | /**
|
| 76 | * Return true to set given position as destination
|
| 77 | */
|
| 78 | protected boolean shouldMoveTo(World worldIn, BlockPos pos)
|
| 79 | {
|
| 80 | if (!worldIn.isAirBlock(pos.up()))
|
| 81 | {
|
| 82 | return false;
|
| 83 | }
|
| 84 | else
|
| 85 | {
|
| 86 | IBlockState iblockstate = worldIn.getBlockState(pos);
|
| 87 | Block block = iblockstate.getBlock();
|
| 88 |
|
| 89 | if (block == Blocks.chest)
|
| 90 | {
|
| 91 | TileEntity tileentity = worldIn.getTileEntity(pos);
|
| 92 |
|
| 93 | if (tileentity instanceof TileEntityChest && ((TileEntityChest)tileentity).numPlayersUsing < 1)
|
| 94 | {
|
| 95 | return true;
|
| 96 | }
|
| 97 | }
|
| 98 | else
|
| 99 | {
|
| 100 | if (block == Blocks.lit_furnace)
|
| 101 | {
|
| 102 | return true;
|
| 103 | }
|
| 104 |
|
| 105 | if (block == Blocks.bed && iblockstate.getValue(BlockBed.PART) != BlockBed.EnumPartType.HEAD)
|
| 106 | {
|
| 107 | return true;
|
| 108 | }
|
| 109 | }
|
| 110 |
|
| 111 | return false;
|
| 112 | }
|
| 113 | }
|
| 114 | }
|
| 115 |
|