EntityAITempt .java

net.minecraft.entity.ai.EntityAITempt (class): members: scaredByPlayerMovement, delayTemptCounter, temptingPlayer, temptedEntity, avoidWater, temptItem.

net.minecraft.entity.aiclass172 linescommonextends EntityAIBase5.2 KB

API Surface (6)

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

Fields & Constants (13)

temptedEntity
speed
targetX
targetY
targetZ
pitch
yaw
temptingPlayer
delayTemptCounter
isRunning
temptItem
scaredByPlayerMovement
avoidWater

String literals (1)

"Unsupported mob type for TemptGoal"

Code Graph: Dependencies (6)

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

Full Source

EntityAITempt.java172 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.ai;
2
3
import net.minecraft.entity.EntityCreature;
4
import net.minecraft.entity.player.EntityPlayer;
5
import net.minecraft.item.Item;
6
import net.minecraft.item.ItemStack;
7
import net.minecraft.pathfinding.PathNavigateGround;
8
9
public class EntityAITempt extends EntityAIBase
10
{
11
    /** The entity using this AI that is tempted by the player. */
12
    private EntityCreature temptedEntity;
13
    private double speed;
14
15
    /** X position of player tempting this mob */
16
    private double targetX;
17
18
    /** Y position of player tempting this mob */
19
    private double targetY;
20
21
    /** Z position of player tempting this mob */
22
    private double targetZ;
23
24
    /** Tempting player's pitch */
25
    private double pitch;
26
27
    /** Tempting player's yaw */
28
    private double yaw;
29
30
    /** The player that is tempting the entity that is using this AI. */
31
    private EntityPlayer temptingPlayer;
32
33
    /**
34
     * A counter that is decremented each time the shouldExecute method is called. The shouldExecute method will always
35
     * return false if delayTemptCounter is greater than 0.
36
     */
37
    private int delayTemptCounter;
38
39
    /** True if this EntityAITempt task is running */
40
    private boolean isRunning;
41
    private Item temptItem;
42
43
    /**
44
     * Whether the entity using this AI will be scared by the tempter's sudden movement.
45
     */
46
    private boolean scaredByPlayerMovement;
47
    private boolean avoidWater;
48
49
    public EntityAITempt(EntityCreature temptedEntityIn, double speedIn, Item temptItemIn, boolean scaredByPlayerMovementIn)
50
    {
51
        this.temptedEntity = temptedEntityIn;
52
        this.speed = speedIn;
53
        this.temptItem = temptItemIn;
54
        this.scaredByPlayerMovement = scaredByPlayerMovementIn;
55
        this.setMutexBits(3);
56
57
        if (!(temptedEntityIn.getNavigator() instanceof PathNavigateGround))
58
        {
59
            throw new IllegalArgumentException("Unsupported mob type for TemptGoal");
60
        }
61
    }
62
63
    /**
64
     * Returns whether the EntityAIBase should begin execution.
65
     */
66
    public boolean shouldExecute()
67
    {
68
        if (this.delayTemptCounter > 0)
69
        {
70
            --this.delayTemptCounter;
71
            return false;
72
        }
73
        else
74
        {
75
            this.temptingPlayer = this.temptedEntity.worldObj.getClosestPlayerToEntity(this.temptedEntity, 10.0D);
76
77
            if (this.temptingPlayer == null)
78
            {
79
                return false;
80
            }
81
            else
82
            {
83
                ItemStack itemstack = this.temptingPlayer.getCurrentEquippedItem();
84
                return itemstack == null ? false : itemstack.getItem() == this.temptItem;
85
            }
86
        }
87
    }
88
89
    /**
90
     * Returns whether an in-progress EntityAIBase should continue executing
91
     */
92
    public boolean continueExecuting()
93
    {
94
        if (this.scaredByPlayerMovement)
95
        {
96
            if (this.temptedEntity.getDistanceSqToEntity(this.temptingPlayer) < 36.0D)
97
            {
98
                if (this.temptingPlayer.getDistanceSq(this.targetX, this.targetY, this.targetZ) > 0.010000000000000002D)
99
                {
100
                    return false;
101
                }
102
103
                if (Math.abs((double)this.temptingPlayer.rotationPitch - this.pitch) > 5.0D || Math.abs((double)this.temptingPlayer.rotationYaw - this.yaw) > 5.0D)
104
                {
105
                    return false;
106
                }
107
            }
108
            else
109
            {
110
                this.targetX = this.temptingPlayer.posX;
111
                this.targetY = this.temptingPlayer.posY;
112
                this.targetZ = this.temptingPlayer.posZ;
113
            }
114
115
            this.pitch = (double)this.temptingPlayer.rotationPitch;
116
            this.yaw = (double)this.temptingPlayer.rotationYaw;
117
        }
118
119
        return this.shouldExecute();
120
    }
121
122
    /**
123
     * Execute a one shot task or start executing a continuous task
124
     */
125
    public void startExecuting()
126
    {
127
        this.targetX = this.temptingPlayer.posX;
128
        this.targetY = this.temptingPlayer.posY;
129
        this.targetZ = this.temptingPlayer.posZ;
130
        this.isRunning = true;
131
        this.avoidWater = ((PathNavigateGround)this.temptedEntity.getNavigator()).getAvoidsWater();
132
        ((PathNavigateGround)this.temptedEntity.getNavigator()).setAvoidsWater(false);
133
    }
134
135
    /**
136
     * Resets the task
137
     */
138
    public void resetTask()
139
    {
140
        this.temptingPlayer = null;
141
        this.temptedEntity.getNavigator().clearPathEntity();
142
        this.delayTemptCounter = 100;
143
        this.isRunning = false;
144
        ((PathNavigateGround)this.temptedEntity.getNavigator()).setAvoidsWater(this.avoidWater);
145
    }
146
147
    /**
148
     * Updates the task
149
     */
150
    public void updateTask()
151
    {
152
        this.temptedEntity.getLookHelper().setLookPositionWithEntity(this.temptingPlayer, 30.0F, (float)this.temptedEntity.getVerticalFaceSpeed());
153
154
        if (this.temptedEntity.getDistanceSqToEntity(this.temptingPlayer) < 6.25D)
155
        {
156
            this.temptedEntity.getNavigator().clearPathEntity();
157
        }
158
        else
159
        {
160
            this.temptedEntity.getNavigator().tryMoveToEntityLiving(this.temptingPlayer, this.speed);
161
        }
162
    }
163
164
    /**
165
     * @see #isRunning
166
     */
167
    public boolean isRunning()
168
    {
169
        return this.isRunning;
170
    }
171
}
172

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