EntityCreature .java

net.minecraft.entity.EntityCreature (class, 166 lines): members: isWithinHomeDistanceCurrentPosition, isWithinHomeDistanceFromPosition, getHomePosition.

net.minecraft.entityclass166 linescommonextends EntityLiving4.9 KB

API Surface (12)

float getBlockPathWeight(BlockPos pos)
boolean getCanSpawnHere()
boolean hasPath()
boolean isWithinHomeDistanceCurrentPosition()
boolean isWithinHomeDistanceFromPosition(BlockPos pos)
void setHomePosAndDistance(BlockPos pos, int distance)
BlockPos getHomePosition()
float getMaximumHomeDistance()
void detachHome()
boolean hasHome()
void updateLeashedState()
void func_142017_o(float p_142017_1_)

Fields & Constants (6)

FLEEING_SPEED_MODIFIER_UUID
FLEEING_SPEED_MODIFIER
homePosition
maximumHomeDistance
aiBase
isMovementAITaskSet

String literals (1)

"Fleeing speed bonus"

Full Source

EntityCreature.java166 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity;
2
3
import java.util.UUID;
4
import net.minecraft.entity.ai.EntityAIBase;
5
import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
6
import net.minecraft.entity.ai.attributes.AttributeModifier;
7
import net.minecraft.entity.passive.EntityTameable;
8
import net.minecraft.pathfinding.PathNavigateGround;
9
import net.minecraft.util.BlockPos;
10
import net.minecraft.world.World;
11
12
public abstract class EntityCreature extends EntityLiving
13
{
14
    public static final UUID FLEEING_SPEED_MODIFIER_UUID = UUID.fromString("E199AD21-BA8A-4C53-8D13-6182D5C69D3A");
15
    public static final AttributeModifier FLEEING_SPEED_MODIFIER = (new AttributeModifier(FLEEING_SPEED_MODIFIER_UUID, "Fleeing speed bonus", 2.0D, 2)).setSaved(false);
16
    private BlockPos homePosition = BlockPos.ORIGIN;
17
18
    /** If -1 there is no maximum distance */
19
    private float maximumHomeDistance = -1.0F;
20
    private EntityAIBase aiBase = new EntityAIMoveTowardsRestriction(this, 1.0D);
21
    private boolean isMovementAITaskSet;
22
23
    public EntityCreature(World worldIn)
24
    {
25
        super(worldIn);
26
    }
27
28
    public float getBlockPathWeight(BlockPos pos)
29
    {
30
        return 0.0F;
31
    }
32
33
    /**
34
     * Checks if the entity's current position is a valid location to spawn this entity.
35
     */
36
    public boolean getCanSpawnHere()
37
    {
38
        return super.getCanSpawnHere() && this.getBlockPathWeight(new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ)) >= 0.0F;
39
    }
40
41
    /**
42
     * if the entity got a PathEntity it returns true, else false
43
     */
44
    public boolean hasPath()
45
    {
46
        return !this.navigator.noPath();
47
    }
48
49
    public boolean isWithinHomeDistanceCurrentPosition()
50
    {
51
        return this.isWithinHomeDistanceFromPosition(new BlockPos(this));
52
    }
53
54
    public boolean isWithinHomeDistanceFromPosition(BlockPos pos)
55
    {
56
        return this.maximumHomeDistance == -1.0F ? true : this.homePosition.distanceSq(pos) < (double)(this.maximumHomeDistance * this.maximumHomeDistance);
57
    }
58
59
    /**
60
     * Sets home position and max distance for it
61
     */
62
    public void setHomePosAndDistance(BlockPos pos, int distance)
63
    {
64
        this.homePosition = pos;
65
        this.maximumHomeDistance = (float)distance;
66
    }
67
68
    public BlockPos getHomePosition()
69
    {
70
        return this.homePosition;
71
    }
72
73
    public float getMaximumHomeDistance()
74
    {
75
        return this.maximumHomeDistance;
76
    }
77
78
    public void detachHome()
79
    {
80
        this.maximumHomeDistance = -1.0F;
81
    }
82
83
    /**
84
     * Returns whether a home area is defined for this entity.
85
     */
86
    public boolean hasHome()
87
    {
88
        return this.maximumHomeDistance != -1.0F;
89
    }
90
91
    /**
92
     * Applies logic related to leashes, for example dragging the entity or breaking the leash.
93
     */
94
    protected void updateLeashedState()
95
    {
96
        super.updateLeashedState();
97
98
        if (this.getLeashed() && this.getLeashedToEntity() != null && this.getLeashedToEntity().worldObj == this.worldObj)
99
        {
100
            Entity entity = this.getLeashedToEntity();
101
            this.setHomePosAndDistance(new BlockPos((int)entity.posX, (int)entity.posY, (int)entity.posZ), 5);
102
            float f = this.getDistanceToEntity(entity);
103
104
            if (this instanceof EntityTameable && ((EntityTameable)this).isSitting())
105
            {
106
                if (f > 10.0F)
107
                {
108
                    this.clearLeashed(true, true);
109
                }
110
111
                return;
112
            }
113
114
            if (!this.isMovementAITaskSet)
115
            {
116
                this.tasks.addTask(2, this.aiBase);
117
118
                if (this.getNavigator() instanceof PathNavigateGround)
119
                {
120
                    ((PathNavigateGround)this.getNavigator()).setAvoidsWater(false);
121
                }
122
123
                this.isMovementAITaskSet = true;
124
            }
125
126
            this.func_142017_o(f);
127
128
            if (f > 4.0F)
129
            {
130
                this.getNavigator().tryMoveToEntityLiving(entity, 1.0D);
131
            }
132
133
            if (f > 6.0F)
134
            {
135
                double d0 = (entity.posX - this.posX) / (double)f;
136
                double d1 = (entity.posY - this.posY) / (double)f;
137
                double d2 = (entity.posZ - this.posZ) / (double)f;
138
                this.motionX += d0 * Math.abs(d0) * 0.4D;
139
                this.motionY += d1 * Math.abs(d1) * 0.4D;
140
                this.motionZ += d2 * Math.abs(d2) * 0.4D;
141
            }
142
143
            if (f > 10.0F)
144
            {
145
                this.clearLeashed(true, true);
146
            }
147
        }
148
        else if (!this.getLeashed() && this.isMovementAITaskSet)
149
        {
150
            this.isMovementAITaskSet = false;
151
            this.tasks.removeTask(this.aiBase);
152
153
            if (this.getNavigator() instanceof PathNavigateGround)
154
            {
155
                ((PathNavigateGround)this.getNavigator()).setAvoidsWater(true);
156
            }
157
158
            this.detachHome();
159
        }
160
    }
161
162
    protected void func_142017_o(float p_142017_1_)
163
    {
164
    }
165
}
166

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