EntityAIMoveThroughVillage .java

net.minecraft.entity.ai.EntityAIMoveThroughVillage (class): members: isNocturnal, doorList, entityPathNavigate, doorInfo, movementSpeed, theEntity.

net.minecraft.entity.aiclass173 linescommonextends EntityAIBase5.5 KB

API Surface (4)

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

Fields & Constants (6)

theEntity
movementSpeed
entityPathNavigate
doorInfo
isNocturnal
doorList

String literals (1)

"Unsupported mob for MoveThroughVillageGoal"

Full Source

EntityAIMoveThroughVillage.java173 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.ai;
2
3
import com.google.common.collect.Lists;
4
import java.util.List;
5
import net.minecraft.entity.EntityCreature;
6
import net.minecraft.pathfinding.PathEntity;
7
import net.minecraft.pathfinding.PathNavigateGround;
8
import net.minecraft.util.BlockPos;
9
import net.minecraft.util.MathHelper;
10
import net.minecraft.util.Vec3;
11
import net.minecraft.village.Village;
12
import net.minecraft.village.VillageDoorInfo;
13
14
public class EntityAIMoveThroughVillage extends EntityAIBase
15
{
16
    private EntityCreature theEntity;
17
    private double movementSpeed;
18
19
    /** The PathNavigate of our entity. */
20
    private PathEntity entityPathNavigate;
21
    private VillageDoorInfo doorInfo;
22
    private boolean isNocturnal;
23
    private List<VillageDoorInfo> doorList = Lists.<VillageDoorInfo>newArrayList();
24
25
    public EntityAIMoveThroughVillage(EntityCreature theEntityIn, double movementSpeedIn, boolean isNocturnalIn)
26
    {
27
        this.theEntity = theEntityIn;
28
        this.movementSpeed = movementSpeedIn;
29
        this.isNocturnal = isNocturnalIn;
30
        this.setMutexBits(1);
31
32
        if (!(theEntityIn.getNavigator() instanceof PathNavigateGround))
33
        {
34
            throw new IllegalArgumentException("Unsupported mob for MoveThroughVillageGoal");
35
        }
36
    }
37
38
    /**
39
     * Returns whether the EntityAIBase should begin execution.
40
     */
41
    public boolean shouldExecute()
42
    {
43
        this.resizeDoorList();
44
45
        if (this.isNocturnal && this.theEntity.worldObj.isDaytime())
46
        {
47
            return false;
48
        }
49
        else
50
        {
51
            Village village = this.theEntity.worldObj.getVillageCollection().getNearestVillage(new BlockPos(this.theEntity), 0);
52
53
            if (village == null)
54
            {
55
                return false;
56
            }
57
            else
58
            {
59
                this.doorInfo = this.findNearestDoor(village);
60
61
                if (this.doorInfo == null)
62
                {
63
                    return false;
64
                }
65
                else
66
                {
67
                    PathNavigateGround pathnavigateground = (PathNavigateGround)this.theEntity.getNavigator();
68
                    boolean flag = pathnavigateground.getEnterDoors();
69
                    pathnavigateground.setBreakDoors(false);
70
                    this.entityPathNavigate = pathnavigateground.getPathToPos(this.doorInfo.getDoorBlockPos());
71
                    pathnavigateground.setBreakDoors(flag);
72
73
                    if (this.entityPathNavigate != null)
74
                    {
75
                        return true;
76
                    }
77
                    else
78
                    {
79
                        Vec3 vec3 = RandomPositionGenerator.findRandomTargetBlockTowards(this.theEntity, 10, 7, new Vec3((double)this.doorInfo.getDoorBlockPos().getX(), (double)this.doorInfo.getDoorBlockPos().getY(), (double)this.doorInfo.getDoorBlockPos().getZ()));
80
81
                        if (vec3 == null)
82
                        {
83
                            return false;
84
                        }
85
                        else
86
                        {
87
                            pathnavigateground.setBreakDoors(false);
88
                            this.entityPathNavigate = this.theEntity.getNavigator().getPathToXYZ(vec3.xCoord, vec3.yCoord, vec3.zCoord);
89
                            pathnavigateground.setBreakDoors(flag);
90
                            return this.entityPathNavigate != null;
91
                        }
92
                    }
93
                }
94
            }
95
        }
96
    }
97
98
    /**
99
     * Returns whether an in-progress EntityAIBase should continue executing
100
     */
101
    public boolean continueExecuting()
102
    {
103
        if (this.theEntity.getNavigator().noPath())
104
        {
105
            return false;
106
        }
107
        else
108
        {
109
            float f = this.theEntity.width + 4.0F;
110
            return this.theEntity.getDistanceSq(this.doorInfo.getDoorBlockPos()) > (double)(f * f);
111
        }
112
    }
113
114
    /**
115
     * Execute a one shot task or start executing a continuous task
116
     */
117
    public void startExecuting()
118
    {
119
        this.theEntity.getNavigator().setPath(this.entityPathNavigate, this.movementSpeed);
120
    }
121
122
    /**
123
     * Resets the task
124
     */
125
    public void resetTask()
126
    {
127
        if (this.theEntity.getNavigator().noPath() || this.theEntity.getDistanceSq(this.doorInfo.getDoorBlockPos()) < 16.0D)
128
        {
129
            this.doorList.add(this.doorInfo);
130
        }
131
    }
132
133
    private VillageDoorInfo findNearestDoor(Village villageIn)
134
    {
135
        VillageDoorInfo villagedoorinfo = null;
136
        int i = Integer.MAX_VALUE;
137
138
        for (VillageDoorInfo villagedoorinfo1 : villageIn.getVillageDoorInfoList())
139
        {
140
            int j = villagedoorinfo1.getDistanceSquared(MathHelper.floor_double(this.theEntity.posX), MathHelper.floor_double(this.theEntity.posY), MathHelper.floor_double(this.theEntity.posZ));
141
142
            if (j < i && !this.doesDoorListContain(villagedoorinfo1))
143
            {
144
                villagedoorinfo = villagedoorinfo1;
145
                i = j;
146
            }
147
        }
148
149
        return villagedoorinfo;
150
    }
151
152
    private boolean doesDoorListContain(VillageDoorInfo doorInfoIn)
153
    {
154
        for (VillageDoorInfo villagedoorinfo : this.doorList)
155
        {
156
            if (doorInfoIn.getDoorBlockPos().equals(villagedoorinfo.getDoorBlockPos()))
157
            {
158
                return true;
159
            }
160
        }
161
162
        return false;
163
    }
164
165
    private void resizeDoorList()
166
    {
167
        if (this.doorList.size() > 15)
168
        {
169
            this.doorList.remove(0);
170
        }
171
    }
172
}
173

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