EntityAIDoorInteract .java

net.minecraft.entity.ai.EntityAIDoorInteract (class): members: hasStoppedDoorInteraction, entityPositionX, entityPositionZ, doorPosition, doorBlock.

net.minecraft.entity.aiclass119 linescommonextends EntityAIBase3.9 KB

API Surface (4)

boolean shouldExecute()
boolean continueExecuting()
void startExecuting()
void updateTask()

Fields & Constants (6)

theEntity
doorPosition
doorBlock
hasStoppedDoorInteraction
entityPositionX
entityPositionZ

String literals (1)

"Unsupported mob type for DoorInteractGoal"

Full Source

EntityAIDoorInteract.java119 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.ai;
2
3
import net.minecraft.block.Block;
4
import net.minecraft.block.BlockDoor;
5
import net.minecraft.block.material.Material;
6
import net.minecraft.entity.EntityLiving;
7
import net.minecraft.pathfinding.PathEntity;
8
import net.minecraft.pathfinding.PathNavigateGround;
9
import net.minecraft.pathfinding.PathPoint;
10
import net.minecraft.util.BlockPos;
11
12
public abstract class EntityAIDoorInteract extends EntityAIBase
13
{
14
    protected EntityLiving theEntity;
15
    protected BlockPos doorPosition = BlockPos.ORIGIN;
16
17
    /** The wooden door block */
18
    protected BlockDoor doorBlock;
19
20
    /**
21
     * If is true then the Entity has stopped Door Interaction and compoleted the task.
22
     */
23
    boolean hasStoppedDoorInteraction;
24
    float entityPositionX;
25
    float entityPositionZ;
26
27
    public EntityAIDoorInteract(EntityLiving entityIn)
28
    {
29
        this.theEntity = entityIn;
30
31
        if (!(entityIn.getNavigator() instanceof PathNavigateGround))
32
        {
33
            throw new IllegalArgumentException("Unsupported mob type for DoorInteractGoal");
34
        }
35
    }
36
37
    /**
38
     * Returns whether the EntityAIBase should begin execution.
39
     */
40
    public boolean shouldExecute()
41
    {
42
        if (!this.theEntity.isCollidedHorizontally)
43
        {
44
            return false;
45
        }
46
        else
47
        {
48
            PathNavigateGround pathnavigateground = (PathNavigateGround)this.theEntity.getNavigator();
49
            PathEntity pathentity = pathnavigateground.getPath();
50
51
            if (pathentity != null && !pathentity.isFinished() && pathnavigateground.getEnterDoors())
52
            {
53
                for (int i = 0; i < Math.min(pathentity.getCurrentPathIndex() + 2, pathentity.getCurrentPathLength()); ++i)
54
                {
55
                    PathPoint pathpoint = pathentity.getPathPointFromIndex(i);
56
                    this.doorPosition = new BlockPos(pathpoint.xCoord, pathpoint.yCoord + 1, pathpoint.zCoord);
57
58
                    if (this.theEntity.getDistanceSq((double)this.doorPosition.getX(), this.theEntity.posY, (double)this.doorPosition.getZ()) <= 2.25D)
59
                    {
60
                        this.doorBlock = this.getBlockDoor(this.doorPosition);
61
62
                        if (this.doorBlock != null)
63
                        {
64
                            return true;
65
                        }
66
                    }
67
                }
68
69
                this.doorPosition = (new BlockPos(this.theEntity)).up();
70
                this.doorBlock = this.getBlockDoor(this.doorPosition);
71
                return this.doorBlock != null;
72
            }
73
            else
74
            {
75
                return false;
76
            }
77
        }
78
    }
79
80
    /**
81
     * Returns whether an in-progress EntityAIBase should continue executing
82
     */
83
    public boolean continueExecuting()
84
    {
85
        return !this.hasStoppedDoorInteraction;
86
    }
87
88
    /**
89
     * Execute a one shot task or start executing a continuous task
90
     */
91
    public void startExecuting()
92
    {
93
        this.hasStoppedDoorInteraction = false;
94
        this.entityPositionX = (float)((double)((float)this.doorPosition.getX() + 0.5F) - this.theEntity.posX);
95
        this.entityPositionZ = (float)((double)((float)this.doorPosition.getZ() + 0.5F) - this.theEntity.posZ);
96
    }
97
98
    /**
99
     * Updates the task
100
     */
101
    public void updateTask()
102
    {
103
        float f = (float)((double)((float)this.doorPosition.getX() + 0.5F) - this.theEntity.posX);
104
        float f1 = (float)((double)((float)this.doorPosition.getZ() + 0.5F) - this.theEntity.posZ);
105
        float f2 = this.entityPositionX * f + this.entityPositionZ * f1;
106
107
        if (f2 < 0.0F)
108
        {
109
            this.hasStoppedDoorInteraction = true;
110
        }
111
    }
112
113
    private BlockDoor getBlockDoor(BlockPos pos)
114
    {
115
        Block block = this.theEntity.worldObj.getBlockState(pos).getBlock();
116
        return block instanceof BlockDoor && block.getMaterial() == Material.wood ? (BlockDoor)block : null;
117
    }
118
}
119

Deobfuscated MCP 1.8.9 source of EntityAIDoorInteract from Marcelektro/MavenMCP-1.8.9 (net/minecraft/entity/ai/EntityAIDoorInteract.java), stored verbatim.