EntityAIMoveToBlock .java

net.minecraft.entity.ai.EntityAIMoveToBlock (class): members: getIsAboveDestination, isAboveDestination, destinationBlock, field_179490_f, searchLength.

net.minecraft.entity.aiclass138 linescommonextends EntityAIBase4.2 KB

API Surface (6)

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

Fields & Constants (8)

theEntity
movementSpeed
runDelay
timeoutCounter
field_179490_f
destinationBlock
isAboveDestination
searchLength

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

EntityAIMoveToBlock.java138 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.ai;
2
3
import net.minecraft.entity.EntityCreature;
4
import net.minecraft.util.BlockPos;
5
import net.minecraft.world.World;
6
7
public abstract class EntityAIMoveToBlock extends EntityAIBase
8
{
9
    private final EntityCreature theEntity;
10
    private final double movementSpeed;
11
12
    /** Controls task execution delay */
13
    protected int runDelay;
14
    private int timeoutCounter;
15
    private int field_179490_f;
16
17
    /** Block to move to */
18
    protected BlockPos destinationBlock = BlockPos.ORIGIN;
19
    private boolean isAboveDestination;
20
    private int searchLength;
21
22
    public EntityAIMoveToBlock(EntityCreature creature, double speedIn, int length)
23
    {
24
        this.theEntity = creature;
25
        this.movementSpeed = speedIn;
26
        this.searchLength = length;
27
        this.setMutexBits(5);
28
    }
29
30
    /**
31
     * Returns whether the EntityAIBase should begin execution.
32
     */
33
    public boolean shouldExecute()
34
    {
35
        if (this.runDelay > 0)
36
        {
37
            --this.runDelay;
38
            return false;
39
        }
40
        else
41
        {
42
            this.runDelay = 200 + this.theEntity.getRNG().nextInt(200);
43
            return this.searchForDestination();
44
        }
45
    }
46
47
    /**
48
     * Returns whether an in-progress EntityAIBase should continue executing
49
     */
50
    public boolean continueExecuting()
51
    {
52
        return this.timeoutCounter >= -this.field_179490_f && this.timeoutCounter <= 1200 && this.shouldMoveTo(this.theEntity.worldObj, this.destinationBlock);
53
    }
54
55
    /**
56
     * Execute a one shot task or start executing a continuous task
57
     */
58
    public void startExecuting()
59
    {
60
        this.theEntity.getNavigator().tryMoveToXYZ((double)((float)this.destinationBlock.getX()) + 0.5D, (double)(this.destinationBlock.getY() + 1), (double)((float)this.destinationBlock.getZ()) + 0.5D, this.movementSpeed);
61
        this.timeoutCounter = 0;
62
        this.field_179490_f = this.theEntity.getRNG().nextInt(this.theEntity.getRNG().nextInt(1200) + 1200) + 1200;
63
    }
64
65
    /**
66
     * Resets the task
67
     */
68
    public void resetTask()
69
    {
70
    }
71
72
    /**
73
     * Updates the task
74
     */
75
    public void updateTask()
76
    {
77
        if (this.theEntity.getDistanceSqToCenter(this.destinationBlock.up()) > 1.0D)
78
        {
79
            this.isAboveDestination = false;
80
            ++this.timeoutCounter;
81
82
            if (this.timeoutCounter % 40 == 0)
83
            {
84
                this.theEntity.getNavigator().tryMoveToXYZ((double)((float)this.destinationBlock.getX()) + 0.5D, (double)(this.destinationBlock.getY() + 1), (double)((float)this.destinationBlock.getZ()) + 0.5D, this.movementSpeed);
85
            }
86
        }
87
        else
88
        {
89
            this.isAboveDestination = true;
90
            --this.timeoutCounter;
91
        }
92
    }
93
94
    protected boolean getIsAboveDestination()
95
    {
96
        return this.isAboveDestination;
97
    }
98
99
    /**
100
     * Searches and sets new destination block and returns true if a suitable block (specified in {@link
101
     * net.minecraft.entity.ai.EntityAIMoveToBlock#shouldMoveTo(World, BlockPos) EntityAIMoveToBlock#shouldMoveTo(World,
102
     * BlockPos)}) can be found.
103
     */
104
    private boolean searchForDestination()
105
    {
106
        int i = this.searchLength;
107
        int j = 1;
108
        BlockPos blockpos = new BlockPos(this.theEntity);
109
110
        for (int k = 0; k <= 1; k = k > 0 ? -k : 1 - k)
111
        {
112
            for (int l = 0; l < i; ++l)
113
            {
114
                for (int i1 = 0; i1 <= l; i1 = i1 > 0 ? -i1 : 1 - i1)
115
                {
116
                    for (int j1 = i1 < l && i1 > -l ? l : 0; j1 <= l; j1 = j1 > 0 ? -j1 : 1 - j1)
117
                    {
118
                        BlockPos blockpos1 = blockpos.add(i1, k - 1, j1);
119
120
                        if (this.theEntity.isWithinHomeDistanceFromPosition(blockpos1) && this.shouldMoveTo(this.theEntity.worldObj, blockpos1))
121
                        {
122
                            this.destinationBlock = blockpos1;
123
                            return true;
124
                        }
125
                    }
126
                }
127
            }
128
        }
129
130
        return false;
131
    }
132
133
    /**
134
     * Return true to set given position as destination
135
     */
136
    protected abstract boolean shouldMoveTo(World worldIn, BlockPos pos);
137
}
138

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