EntityAIPlay .java

net.minecraft.entity.ai.EntityAIPlay (class, 125 lines): members: targetVillager, villagerObj, playTime, speed, updateTask, resetTask, continueExecuting.

net.minecraft.entity.aiclass125 linescommonextends EntityAIBase3.2 KB

API Surface (5)

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

Fields & Constants (4)

villagerObj
targetVillager
speed
playTime

Code Graph: Dependencies (5)

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

Full Source

EntityAIPlay.java125 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.ai;
2
3
import java.util.List;
4
import net.minecraft.entity.EntityLivingBase;
5
import net.minecraft.entity.passive.EntityVillager;
6
import net.minecraft.util.Vec3;
7
8
public class EntityAIPlay extends EntityAIBase
9
{
10
    private EntityVillager villagerObj;
11
    private EntityLivingBase targetVillager;
12
    private double speed;
13
    private int playTime;
14
15
    public EntityAIPlay(EntityVillager villagerObjIn, double speedIn)
16
    {
17
        this.villagerObj = villagerObjIn;
18
        this.speed = speedIn;
19
        this.setMutexBits(1);
20
    }
21
22
    /**
23
     * Returns whether the EntityAIBase should begin execution.
24
     */
25
    public boolean shouldExecute()
26
    {
27
        if (this.villagerObj.getGrowingAge() >= 0)
28
        {
29
            return false;
30
        }
31
        else if (this.villagerObj.getRNG().nextInt(400) != 0)
32
        {
33
            return false;
34
        }
35
        else
36
        {
37
            List<EntityVillager> list = this.villagerObj.worldObj.<EntityVillager>getEntitiesWithinAABB(EntityVillager.class, this.villagerObj.getEntityBoundingBox().expand(6.0D, 3.0D, 6.0D));
38
            double d0 = Double.MAX_VALUE;
39
40
            for (EntityVillager entityvillager : list)
41
            {
42
                if (entityvillager != this.villagerObj && !entityvillager.isPlaying() && entityvillager.getGrowingAge() < 0)
43
                {
44
                    double d1 = entityvillager.getDistanceSqToEntity(this.villagerObj);
45
46
                    if (d1 <= d0)
47
                    {
48
                        d0 = d1;
49
                        this.targetVillager = entityvillager;
50
                    }
51
                }
52
            }
53
54
            if (this.targetVillager == null)
55
            {
56
                Vec3 vec3 = RandomPositionGenerator.findRandomTarget(this.villagerObj, 16, 3);
57
58
                if (vec3 == null)
59
                {
60
                    return false;
61
                }
62
            }
63
64
            return true;
65
        }
66
    }
67
68
    /**
69
     * Returns whether an in-progress EntityAIBase should continue executing
70
     */
71
    public boolean continueExecuting()
72
    {
73
        return this.playTime > 0;
74
    }
75
76
    /**
77
     * Execute a one shot task or start executing a continuous task
78
     */
79
    public void startExecuting()
80
    {
81
        if (this.targetVillager != null)
82
        {
83
            this.villagerObj.setPlaying(true);
84
        }
85
86
        this.playTime = 1000;
87
    }
88
89
    /**
90
     * Resets the task
91
     */
92
    public void resetTask()
93
    {
94
        this.villagerObj.setPlaying(false);
95
        this.targetVillager = null;
96
    }
97
98
    /**
99
     * Updates the task
100
     */
101
    public void updateTask()
102
    {
103
        --this.playTime;
104
105
        if (this.targetVillager != null)
106
        {
107
            if (this.villagerObj.getDistanceSqToEntity(this.targetVillager) > 4.0D)
108
            {
109
                this.villagerObj.getNavigator().tryMoveToEntityLiving(this.targetVillager, this.speed);
110
            }
111
        }
112
        else if (this.villagerObj.getNavigator().noPath())
113
        {
114
            Vec3 vec3 = RandomPositionGenerator.findRandomTarget(this.villagerObj, 16, 3);
115
116
            if (vec3 == null)
117
            {
118
                return;
119
            }
120
121
            this.villagerObj.getNavigator().tryMoveToXYZ(vec3.xCoord, vec3.yCoord, vec3.zCoord, this.speed);
122
        }
123
    }
124
}
125

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