package net.minecraft.entity.ai; import net.minecraft.block.Block; import net.minecraft.block.BlockDoor; import net.minecraft.entity.EntityLiving; import net.minecraft.init.Blocks; import net.minecraft.pathfinding.PathEntity; import net.minecraft.pathfinding.PathNavigate; import net.minecraft.pathfinding.PathPoint; import net.minecraft.util.MathHelper; public abstract class EntityAIDoorInteract extends EntityAIBase { protected EntityLiving theEntity; protected int entityPosX; protected int entityPosY; protected int entityPosZ; /** The wooden door block */ protected BlockDoor doorBlock; /** If is true then the Entity has stopped Door Interaction and compoleted the task. */ boolean hasStoppedDoorInteraction; float entityPositionX; float entityPositionZ; private static final String __OBFID = "CL_00001581"; public EntityAIDoorInteract(EntityLiving p_i1621_1_) { this.theEntity = p_i1621_1_; } /** * Returns whether the EntityAIBase should begin execution. */ public boolean shouldExecute() { if (!this.theEntity.isCollidedHorizontally) { return false; } else { PathNavigate pathnavigate = this.theEntity.getNavigator(); PathEntity pathentity = pathnavigate.getPath(); if (pathentity != null && !pathentity.isFinished() && pathnavigate.getCanBreakDoors()) { for (int i = 0; i < Math.min(pathentity.getCurrentPathIndex() + 2, pathentity.getCurrentPathLength()); ++i) { PathPoint pathpoint = pathentity.getPathPointFromIndex(i); this.entityPosX = pathpoint.xCoord; this.entityPosY = pathpoint.yCoord + 1; this.entityPosZ = pathpoint.zCoord; if (this.theEntity.getDistanceSq((double)this.entityPosX, this.theEntity.posY, (double)this.entityPosZ) <= 2.25D) { this.doorBlock = this.getWoodenDoorBlock(this.entityPosX, this.entityPosY, this.entityPosZ); if (this.doorBlock != null) { return true; } } } this.entityPosX = MathHelper.floor_double(this.theEntity.posX); this.entityPosY = MathHelper.floor_double(this.theEntity.posY + 1.0D); this.entityPosZ = MathHelper.floor_double(this.theEntity.posZ); this.doorBlock = this.getWoodenDoorBlock(this.entityPosX, this.entityPosY, this.entityPosZ); return this.doorBlock != null; } else { return false; } } } /** * Returns whether an in-progress EntityAIBase should continue executing */ public boolean continueExecuting() { return !this.hasStoppedDoorInteraction; } /** * Execute a one shot task or start executing a continuous task */ public void startExecuting() { this.hasStoppedDoorInteraction = false; this.entityPositionX = (float)((double)((float)this.entityPosX + 0.5F) - this.theEntity.posX); this.entityPositionZ = (float)((double)((float)this.entityPosZ + 0.5F) - this.theEntity.posZ); } /** * Updates the task */ public void updateTask() { float f = (float)((double)((float)this.entityPosX + 0.5F) - this.theEntity.posX); float f1 = (float)((double)((float)this.entityPosZ + 0.5F) - this.theEntity.posZ); float f2 = this.entityPositionX * f + this.entityPositionZ * f1; if (f2 < 0.0F) { this.hasStoppedDoorInteraction = true; } } /** * Returns the block at the specified position, null if that block is not a wooden door. Args : x, y, z */ private BlockDoor getWoodenDoorBlock(int p_151503_1_, int p_151503_2_, int p_151503_3_) { Block block = this.theEntity.worldObj.getBlock(p_151503_1_, p_151503_2_, p_151503_3_); return block != Blocks.wooden_door ? null : (BlockDoor)block; } }