EntityAIFollowOwner .java

net.minecraft.entity.ai.EntityAIFollowOwner (class): members: field_75343_h, field_75344_i, petPathfinder, followSpeed, theOwner, maxDist, minDist, thePet.

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

API Surface (5)

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

Fields & Constants (9)

thePet
theOwner
theWorld
followSpeed
petPathfinder
field_75343_h
maxDist
minDist
field_75344_i

String literals (1)

"Unsupported mob type for FollowOwnerGoal"

Full Source

EntityAIFollowOwner.java150 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.ai;
2
3
import net.minecraft.block.Block;
4
import net.minecraft.block.state.IBlockState;
5
import net.minecraft.entity.EntityLivingBase;
6
import net.minecraft.entity.passive.EntityTameable;
7
import net.minecraft.entity.player.EntityPlayer;
8
import net.minecraft.init.Blocks;
9
import net.minecraft.pathfinding.PathNavigate;
10
import net.minecraft.pathfinding.PathNavigateGround;
11
import net.minecraft.util.BlockPos;
12
import net.minecraft.util.MathHelper;
13
import net.minecraft.world.World;
14
15
public class EntityAIFollowOwner extends EntityAIBase
16
{
17
    private EntityTameable thePet;
18
    private EntityLivingBase theOwner;
19
    World theWorld;
20
    private double followSpeed;
21
    private PathNavigate petPathfinder;
22
    private int field_75343_h;
23
    float maxDist;
24
    float minDist;
25
    private boolean field_75344_i;
26
27
    public EntityAIFollowOwner(EntityTameable thePetIn, double followSpeedIn, float minDistIn, float maxDistIn)
28
    {
29
        this.thePet = thePetIn;
30
        this.theWorld = thePetIn.worldObj;
31
        this.followSpeed = followSpeedIn;
32
        this.petPathfinder = thePetIn.getNavigator();
33
        this.minDist = minDistIn;
34
        this.maxDist = maxDistIn;
35
        this.setMutexBits(3);
36
37
        if (!(thePetIn.getNavigator() instanceof PathNavigateGround))
38
        {
39
            throw new IllegalArgumentException("Unsupported mob type for FollowOwnerGoal");
40
        }
41
    }
42
43
    /**
44
     * Returns whether the EntityAIBase should begin execution.
45
     */
46
    public boolean shouldExecute()
47
    {
48
        EntityLivingBase entitylivingbase = this.thePet.getOwner();
49
50
        if (entitylivingbase == null)
51
        {
52
            return false;
53
        }
54
        else if (entitylivingbase instanceof EntityPlayer && ((EntityPlayer)entitylivingbase).isSpectator())
55
        {
56
            return false;
57
        }
58
        else if (this.thePet.isSitting())
59
        {
60
            return false;
61
        }
62
        else if (this.thePet.getDistanceSqToEntity(entitylivingbase) < (double)(this.minDist * this.minDist))
63
        {
64
            return false;
65
        }
66
        else
67
        {
68
            this.theOwner = entitylivingbase;
69
            return true;
70
        }
71
    }
72
73
    /**
74
     * Returns whether an in-progress EntityAIBase should continue executing
75
     */
76
    public boolean continueExecuting()
77
    {
78
        return !this.petPathfinder.noPath() && this.thePet.getDistanceSqToEntity(this.theOwner) > (double)(this.maxDist * this.maxDist) && !this.thePet.isSitting();
79
    }
80
81
    /**
82
     * Execute a one shot task or start executing a continuous task
83
     */
84
    public void startExecuting()
85
    {
86
        this.field_75343_h = 0;
87
        this.field_75344_i = ((PathNavigateGround)this.thePet.getNavigator()).getAvoidsWater();
88
        ((PathNavigateGround)this.thePet.getNavigator()).setAvoidsWater(false);
89
    }
90
91
    /**
92
     * Resets the task
93
     */
94
    public void resetTask()
95
    {
96
        this.theOwner = null;
97
        this.petPathfinder.clearPathEntity();
98
        ((PathNavigateGround)this.thePet.getNavigator()).setAvoidsWater(true);
99
    }
100
101
    private boolean func_181065_a(BlockPos p_181065_1_)
102
    {
103
        IBlockState iblockstate = this.theWorld.getBlockState(p_181065_1_);
104
        Block block = iblockstate.getBlock();
105
        return block == Blocks.air ? true : !block.isFullCube();
106
    }
107
108
    /**
109
     * Updates the task
110
     */
111
    public void updateTask()
112
    {
113
        this.thePet.getLookHelper().setLookPositionWithEntity(this.theOwner, 10.0F, (float)this.thePet.getVerticalFaceSpeed());
114
115
        if (!this.thePet.isSitting())
116
        {
117
            if (--this.field_75343_h <= 0)
118
            {
119
                this.field_75343_h = 10;
120
121
                if (!this.petPathfinder.tryMoveToEntityLiving(this.theOwner, this.followSpeed))
122
                {
123
                    if (!this.thePet.getLeashed())
124
                    {
125
                        if (this.thePet.getDistanceSqToEntity(this.theOwner) >= 144.0D)
126
                        {
127
                            int i = MathHelper.floor_double(this.theOwner.posX) - 2;
128
                            int j = MathHelper.floor_double(this.theOwner.posZ) - 2;
129
                            int k = MathHelper.floor_double(this.theOwner.getEntityBoundingBox().minY);
130
131
                            for (int l = 0; l <= 4; ++l)
132
                            {
133
                                for (int i1 = 0; i1 <= 4; ++i1)
134
                                {
135
                                    if ((l < 1 || i1 < 1 || l > 3 || i1 > 3) && World.doesBlockHaveSolidTopSurface(this.theWorld, new BlockPos(i + l, k - 1, j + i1)) && this.func_181065_a(new BlockPos(i + l, k, j + i1)) && this.func_181065_a(new BlockPos(i + l, k + 1, j + i1)))
136
                                    {
137
                                        this.thePet.setLocationAndAngles((double)((float)(i + l) + 0.5F), (double)k, (double)((float)(j + i1) + 0.5F), this.thePet.rotationYaw, this.thePet.rotationPitch);
138
                                        this.petPathfinder.clearPathEntity();
139
                                        return;
140
                                    }
141
                                }
142
                            }
143
                        }
144
                    }
145
                }
146
            }
147
        }
148
    }
149
}
150

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