EntityAIFleeSun .java

net.minecraft.entity.ai.EntityAIFleeSun (class, 95 lines): members: theCreature, shelterX, shelterY, shelterZ, movementSpeed, theWorld, continueExecuting.

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

API Surface (3)

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

Fields & Constants (6)

theCreature
shelterX
shelterY
shelterZ
movementSpeed
theWorld

Code Graph: Dependencies (5)

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

Full Source

EntityAIFleeSun.java95 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.ai;
2
3
import java.util.Random;
4
import net.minecraft.entity.EntityCreature;
5
import net.minecraft.util.BlockPos;
6
import net.minecraft.util.Vec3;
7
import net.minecraft.world.World;
8
9
public class EntityAIFleeSun extends EntityAIBase
10
{
11
    private EntityCreature theCreature;
12
    private double shelterX;
13
    private double shelterY;
14
    private double shelterZ;
15
    private double movementSpeed;
16
    private World theWorld;
17
18
    public EntityAIFleeSun(EntityCreature theCreatureIn, double movementSpeedIn)
19
    {
20
        this.theCreature = theCreatureIn;
21
        this.movementSpeed = movementSpeedIn;
22
        this.theWorld = theCreatureIn.worldObj;
23
        this.setMutexBits(1);
24
    }
25
26
    /**
27
     * Returns whether the EntityAIBase should begin execution.
28
     */
29
    public boolean shouldExecute()
30
    {
31
        if (!this.theWorld.isDaytime())
32
        {
33
            return false;
34
        }
35
        else if (!this.theCreature.isBurning())
36
        {
37
            return false;
38
        }
39
        else if (!this.theWorld.canSeeSky(new BlockPos(this.theCreature.posX, this.theCreature.getEntityBoundingBox().minY, this.theCreature.posZ)))
40
        {
41
            return false;
42
        }
43
        else
44
        {
45
            Vec3 vec3 = this.findPossibleShelter();
46
47
            if (vec3 == null)
48
            {
49
                return false;
50
            }
51
            else
52
            {
53
                this.shelterX = vec3.xCoord;
54
                this.shelterY = vec3.yCoord;
55
                this.shelterZ = vec3.zCoord;
56
                return true;
57
            }
58
        }
59
    }
60
61
    /**
62
     * Returns whether an in-progress EntityAIBase should continue executing
63
     */
64
    public boolean continueExecuting()
65
    {
66
        return !this.theCreature.getNavigator().noPath();
67
    }
68
69
    /**
70
     * Execute a one shot task or start executing a continuous task
71
     */
72
    public void startExecuting()
73
    {
74
        this.theCreature.getNavigator().tryMoveToXYZ(this.shelterX, this.shelterY, this.shelterZ, this.movementSpeed);
75
    }
76
77
    private Vec3 findPossibleShelter()
78
    {
79
        Random random = this.theCreature.getRNG();
80
        BlockPos blockpos = new BlockPos(this.theCreature.posX, this.theCreature.getEntityBoundingBox().minY, this.theCreature.posZ);
81
82
        for (int i = 0; i < 10; ++i)
83
        {
84
            BlockPos blockpos1 = blockpos.add(random.nextInt(20) - 10, random.nextInt(6) - 3, random.nextInt(20) - 10);
85
86
            if (!this.theWorld.canSeeSky(blockpos1) && this.theCreature.getBlockPathWeight(blockpos1) < 0.0F)
87
            {
88
                return new Vec3((double)blockpos1.getX(), (double)blockpos1.getY(), (double)blockpos1.getZ());
89
            }
90
        }
91
92
        return null;
93
    }
94
}
95

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