EntityAIRunAroundLikeCrazy .java

net.minecraft.entity.ai.EntityAIRunAroundLikeCrazy (class, 95 lines): members: horseHost, targetX, targetY, targetZ, speed, updateTask, continueExecuting.

net.minecraft.entity.aiclass95 linescommonextends EntityAIBase2.6 KB

API Surface (4)

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

Fields & Constants (5)

horseHost
speed
targetX
targetY
targetZ

Code Graph: Dependencies (6)

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

Full Source

EntityAIRunAroundLikeCrazy.java95 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.ai;
2
3
import net.minecraft.entity.Entity;
4
import net.minecraft.entity.passive.EntityHorse;
5
import net.minecraft.entity.player.EntityPlayer;
6
import net.minecraft.util.Vec3;
7
8
public class EntityAIRunAroundLikeCrazy extends EntityAIBase
9
{
10
    private EntityHorse horseHost;
11
    private double speed;
12
    private double targetX;
13
    private double targetY;
14
    private double targetZ;
15
16
    public EntityAIRunAroundLikeCrazy(EntityHorse horse, double speedIn)
17
    {
18
        this.horseHost = horse;
19
        this.speed = speedIn;
20
        this.setMutexBits(1);
21
    }
22
23
    /**
24
     * Returns whether the EntityAIBase should begin execution.
25
     */
26
    public boolean shouldExecute()
27
    {
28
        if (!this.horseHost.isTame() && this.horseHost.riddenByEntity != null)
29
        {
30
            Vec3 vec3 = RandomPositionGenerator.findRandomTarget(this.horseHost, 5, 4);
31
32
            if (vec3 == null)
33
            {
34
                return false;
35
            }
36
            else
37
            {
38
                this.targetX = vec3.xCoord;
39
                this.targetY = vec3.yCoord;
40
                this.targetZ = vec3.zCoord;
41
                return true;
42
            }
43
        }
44
        else
45
        {
46
            return false;
47
        }
48
    }
49
50
    /**
51
     * Execute a one shot task or start executing a continuous task
52
     */
53
    public void startExecuting()
54
    {
55
        this.horseHost.getNavigator().tryMoveToXYZ(this.targetX, this.targetY, this.targetZ, this.speed);
56
    }
57
58
    /**
59
     * Returns whether an in-progress EntityAIBase should continue executing
60
     */
61
    public boolean continueExecuting()
62
    {
63
        return !this.horseHost.getNavigator().noPath() && this.horseHost.riddenByEntity != null;
64
    }
65
66
    /**
67
     * Updates the task
68
     */
69
    public void updateTask()
70
    {
71
        if (this.horseHost.getRNG().nextInt(50) == 0)
72
        {
73
            if (this.horseHost.riddenByEntity instanceof EntityPlayer)
74
            {
75
                int i = this.horseHost.getTemper();
76
                int j = this.horseHost.getMaxTemper();
77
78
                if (j > 0 && this.horseHost.getRNG().nextInt(j) < i)
79
                {
80
                    this.horseHost.setTamedBy((EntityPlayer)this.horseHost.riddenByEntity);
81
                    this.horseHost.worldObj.setEntityState(this.horseHost, (byte)7);
82
                    return;
83
                }
84
85
                this.horseHost.increaseTemper(5);
86
            }
87
88
            this.horseHost.riddenByEntity.mountEntity((Entity)null);
89
            this.horseHost.riddenByEntity = null;
90
            this.horseHost.makeHorseRearWithSound();
91
            this.horseHost.worldObj.setEntityState(this.horseHost, (byte)6);
92
        }
93
    }
94
}
95

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