EntityEnderEye .java

net.minecraft.entity.item.EntityEnderEye (class, 238 lines): members: shatterOrDrop, despawnTimer, moveTowards, targetX, targetY, targetZ, setVelocity.

net.minecraft.entity.itemclass238 linescommonextends Entity7.1 KB

API Surface (10)

void entityInit()
boolean isInRangeToRenderDist(double distance)
void moveTowards(BlockPos p_180465_1_)
void setVelocity(double x, double y, double z)
void onUpdate()
void writeEntityToNBT(NBTTagCompound tagCompound)
void readEntityFromNBT(NBTTagCompound tagCompund)
float getBrightness(float partialTicks)
int getBrightnessForRender(float partialTicks)
boolean canAttackWithItem()

Fields & Constants (5)

targetX
targetY
targetZ
despawnTimer
shatterOrDrop

Full Source

EntityEnderEye.java238 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.item;
2
3
import net.minecraft.entity.Entity;
4
import net.minecraft.init.Items;
5
import net.minecraft.item.ItemStack;
6
import net.minecraft.nbt.NBTTagCompound;
7
import net.minecraft.util.BlockPos;
8
import net.minecraft.util.EnumParticleTypes;
9
import net.minecraft.util.MathHelper;
10
import net.minecraft.world.World;
11
12
public class EntityEnderEye extends Entity
13
{
14
    /** 'x' location the eye should float towards. */
15
    private double targetX;
16
17
    /** 'y' location the eye should float towards. */
18
    private double targetY;
19
20
    /** 'z' location the eye should float towards. */
21
    private double targetZ;
22
    private int despawnTimer;
23
    private boolean shatterOrDrop;
24
25
    public EntityEnderEye(World worldIn)
26
    {
27
        super(worldIn);
28
        this.setSize(0.25F, 0.25F);
29
    }
30
31
    protected void entityInit()
32
    {
33
    }
34
35
    /**
36
     * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge
37
     * length * 64 * renderDistanceWeight Args: distance
38
     */
39
    public boolean isInRangeToRenderDist(double distance)
40
    {
41
        double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 4.0D;
42
43
        if (Double.isNaN(d0))
44
        {
45
            d0 = 4.0D;
46
        }
47
48
        d0 = d0 * 64.0D;
49
        return distance < d0 * d0;
50
    }
51
52
    public EntityEnderEye(World worldIn, double x, double y, double z)
53
    {
54
        super(worldIn);
55
        this.despawnTimer = 0;
56
        this.setSize(0.25F, 0.25F);
57
        this.setPosition(x, y, z);
58
    }
59
60
    public void moveTowards(BlockPos p_180465_1_)
61
    {
62
        double d0 = (double)p_180465_1_.getX();
63
        int i = p_180465_1_.getY();
64
        double d1 = (double)p_180465_1_.getZ();
65
        double d2 = d0 - this.posX;
66
        double d3 = d1 - this.posZ;
67
        float f = MathHelper.sqrt_double(d2 * d2 + d3 * d3);
68
69
        if (f > 12.0F)
70
        {
71
            this.targetX = this.posX + d2 / (double)f * 12.0D;
72
            this.targetZ = this.posZ + d3 / (double)f * 12.0D;
73
            this.targetY = this.posY + 8.0D;
74
        }
75
        else
76
        {
77
            this.targetX = d0;
78
            this.targetY = (double)i;
79
            this.targetZ = d1;
80
        }
81
82
        this.despawnTimer = 0;
83
        this.shatterOrDrop = this.rand.nextInt(5) > 0;
84
    }
85
86
    /**
87
     * Sets the velocity to the args. Args: x, y, z
88
     */
89
    public void setVelocity(double x, double y, double z)
90
    {
91
        this.motionX = x;
92
        this.motionY = y;
93
        this.motionZ = z;
94
95
        if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
96
        {
97
            float f = MathHelper.sqrt_double(x * x + z * z);
98
            this.prevRotationYaw = this.rotationYaw = (float)(MathHelper.atan2(x, z) * 180.0D / Math.PI);
99
            this.prevRotationPitch = this.rotationPitch = (float)(MathHelper.atan2(y, (double)f) * 180.0D / Math.PI);
100
        }
101
    }
102
103
    /**
104
     * Called to update the entity's position/logic.
105
     */
106
    public void onUpdate()
107
    {
108
        this.lastTickPosX = this.posX;
109
        this.lastTickPosY = this.posY;
110
        this.lastTickPosZ = this.posZ;
111
        super.onUpdate();
112
        this.posX += this.motionX;
113
        this.posY += this.motionY;
114
        this.posZ += this.motionZ;
115
        float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
116
        this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
117
118
        for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
119
        {
120
            ;
121
        }
122
123
        while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
124
        {
125
            this.prevRotationPitch += 360.0F;
126
        }
127
128
        while (this.rotationYaw - this.prevRotationYaw < -180.0F)
129
        {
130
            this.prevRotationYaw -= 360.0F;
131
        }
132
133
        while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
134
        {
135
            this.prevRotationYaw += 360.0F;
136
        }
137
138
        this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
139
        this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
140
141
        if (!this.worldObj.isRemote)
142
        {
143
            double d0 = this.targetX - this.posX;
144
            double d1 = this.targetZ - this.posZ;
145
            float f1 = (float)Math.sqrt(d0 * d0 + d1 * d1);
146
            float f2 = (float)MathHelper.atan2(d1, d0);
147
            double d2 = (double)f + (double)(f1 - f) * 0.0025D;
148
149
            if (f1 < 1.0F)
150
            {
151
                d2 *= 0.8D;
152
                this.motionY *= 0.8D;
153
            }
154
155
            this.motionX = Math.cos((double)f2) * d2;
156
            this.motionZ = Math.sin((double)f2) * d2;
157
158
            if (this.posY < this.targetY)
159
            {
160
                this.motionY += (1.0D - this.motionY) * 0.014999999664723873D;
161
            }
162
            else
163
            {
164
                this.motionY += (-1.0D - this.motionY) * 0.014999999664723873D;
165
            }
166
        }
167
168
        float f3 = 0.25F;
169
170
        if (this.isInWater())
171
        {
172
            for (int i = 0; i < 4; ++i)
173
            {
174
                this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * (double)f3, this.posY - this.motionY * (double)f3, this.posZ - this.motionZ * (double)f3, this.motionX, this.motionY, this.motionZ, new int[0]);
175
            }
176
        }
177
        else
178
        {
179
            this.worldObj.spawnParticle(EnumParticleTypes.PORTAL, this.posX - this.motionX * (double)f3 + this.rand.nextDouble() * 0.6D - 0.3D, this.posY - this.motionY * (double)f3 - 0.5D, this.posZ - this.motionZ * (double)f3 + this.rand.nextDouble() * 0.6D - 0.3D, this.motionX, this.motionY, this.motionZ, new int[0]);
180
        }
181
182
        if (!this.worldObj.isRemote)
183
        {
184
            this.setPosition(this.posX, this.posY, this.posZ);
185
            ++this.despawnTimer;
186
187
            if (this.despawnTimer > 80 && !this.worldObj.isRemote)
188
            {
189
                this.setDead();
190
191
                if (this.shatterOrDrop)
192
                {
193
                    this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, new ItemStack(Items.ender_eye)));
194
                }
195
                else
196
                {
197
                    this.worldObj.playAuxSFX(2003, new BlockPos(this), 0);
198
                }
199
            }
200
        }
201
    }
202
203
    /**
204
     * (abstract) Protected helper method to write subclass entity data to NBT.
205
     */
206
    public void writeEntityToNBT(NBTTagCompound tagCompound)
207
    {
208
    }
209
210
    /**
211
     * (abstract) Protected helper method to read subclass entity data from NBT.
212
     */
213
    public void readEntityFromNBT(NBTTagCompound tagCompund)
214
    {
215
    }
216
217
    /**
218
     * Gets how bright this entity is.
219
     */
220
    public float getBrightness(float partialTicks)
221
    {
222
        return 1.0F;
223
    }
224
225
    public int getBrightnessForRender(float partialTicks)
226
    {
227
        return 15728880;
228
    }
229
230
    /**
231
     * If returns false, the item will not inflict any damage against entities.
232
     */
233
    public boolean canAttackWithItem()
234
    {
235
        return false;
236
    }
237
}
238

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