EntityAIBeg .java

net.minecraft.entity.ai.EntityAIBeg (class, 78 lines): members: minPlayerDistance, worldObject, theWolf, timeoutCounter, thePlayer, updateTask, resetTask.

net.minecraft.entity.aiclass78 linescommonextends EntityAIBase2.4 KB

API Surface (5)

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

Fields & Constants (5)

theWolf
thePlayer
worldObject
minPlayerDistance
timeoutCounter

Code Graph: Dependencies (6)

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

Full Source

EntityAIBeg.java78 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.ai;
2
3
import net.minecraft.entity.passive.EntityWolf;
4
import net.minecraft.entity.player.EntityPlayer;
5
import net.minecraft.init.Items;
6
import net.minecraft.item.ItemStack;
7
import net.minecraft.world.World;
8
9
public class EntityAIBeg extends EntityAIBase
10
{
11
    private EntityWolf theWolf;
12
    private EntityPlayer thePlayer;
13
    private World worldObject;
14
    private float minPlayerDistance;
15
    private int timeoutCounter;
16
17
    public EntityAIBeg(EntityWolf wolf, float minDistance)
18
    {
19
        this.theWolf = wolf;
20
        this.worldObject = wolf.worldObj;
21
        this.minPlayerDistance = minDistance;
22
        this.setMutexBits(2);
23
    }
24
25
    /**
26
     * Returns whether the EntityAIBase should begin execution.
27
     */
28
    public boolean shouldExecute()
29
    {
30
        this.thePlayer = this.worldObject.getClosestPlayerToEntity(this.theWolf, (double)this.minPlayerDistance);
31
        return this.thePlayer == null ? false : this.hasPlayerGotBoneInHand(this.thePlayer);
32
    }
33
34
    /**
35
     * Returns whether an in-progress EntityAIBase should continue executing
36
     */
37
    public boolean continueExecuting()
38
    {
39
        return !this.thePlayer.isEntityAlive() ? false : (this.theWolf.getDistanceSqToEntity(this.thePlayer) > (double)(this.minPlayerDistance * this.minPlayerDistance) ? false : this.timeoutCounter > 0 && this.hasPlayerGotBoneInHand(this.thePlayer));
40
    }
41
42
    /**
43
     * Execute a one shot task or start executing a continuous task
44
     */
45
    public void startExecuting()
46
    {
47
        this.theWolf.setBegging(true);
48
        this.timeoutCounter = 40 + this.theWolf.getRNG().nextInt(40);
49
    }
50
51
    /**
52
     * Resets the task
53
     */
54
    public void resetTask()
55
    {
56
        this.theWolf.setBegging(false);
57
        this.thePlayer = null;
58
    }
59
60
    /**
61
     * Updates the task
62
     */
63
    public void updateTask()
64
    {
65
        this.theWolf.getLookHelper().setLookPosition(this.thePlayer.posX, this.thePlayer.posY + (double)this.thePlayer.getEyeHeight(), this.thePlayer.posZ, 10.0F, (float)this.theWolf.getVerticalFaceSpeed());
66
        --this.timeoutCounter;
67
    }
68
69
    /**
70
     * Gets if the Player has the Bone in the hand.
71
     */
72
    private boolean hasPlayerGotBoneInHand(EntityPlayer player)
73
    {
74
        ItemStack itemstack = player.inventory.getCurrentItem();
75
        return itemstack == null ? false : (!this.theWolf.isTamed() && itemstack.getItem() == Items.bone ? true : this.theWolf.isBreedingItem(itemstack));
76
    }
77
}
78

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