EntityFirework .java

net.minecraft.client.particle.EntityFirework (class): members: OverlayFX, StarterFX, SparkFX, Factory. strings: "twinkle_far", "fireworks.", "largeBlast".

net.minecraft.client.particleclass433 linesclient19.1 KB

API Surface (15)

EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_)
void renderParticle(WorldRenderer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ)
void setTrail(boolean trailIn)
void setTwinkle(boolean twinkleIn)
void setColour(int colour)
void setFadeColour(int faceColour)
AxisAlignedBB getCollisionBoundingBox()
boolean canBePushed()
void renderParticle(WorldRenderer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ)
void onUpdate()
int getBrightnessForRender(float partialTicks)
float getBrightness(float partialTicks)
void renderParticle(WorldRenderer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ)
void onUpdate()
int getFXLayer()

String literals (11)

"Explosions"
"Flicker"
"fireworks."
"largeBlast"
"blast"
"_far"
"Trail"
"Colors"
"FadeColors"
"twinkle_far"
"twinkle"

Full Source

EntityFirework.java433 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.particle;
2
3
import net.minecraft.client.Minecraft;
4
import net.minecraft.client.renderer.WorldRenderer;
5
import net.minecraft.entity.Entity;
6
import net.minecraft.item.ItemDye;
7
import net.minecraft.nbt.NBTTagCompound;
8
import net.minecraft.nbt.NBTTagList;
9
import net.minecraft.util.AxisAlignedBB;
10
import net.minecraft.util.MathHelper;
11
import net.minecraft.world.World;
12
13
public class EntityFirework
14
{
15
    public static class Factory implements IParticleFactory
16
    {
17
        public EntityFX getEntityFX(int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... p_178902_15_)
18
        {
19
            EntityFirework.SparkFX entityfirework$sparkfx = new EntityFirework.SparkFX(worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn, Minecraft.getMinecraft().effectRenderer);
20
            entityfirework$sparkfx.setAlphaF(0.99F);
21
            return entityfirework$sparkfx;
22
        }
23
    }
24
25
    public static class OverlayFX extends EntityFX
26
    {
27
        protected OverlayFX(World p_i46466_1_, double p_i46466_2_, double p_i46466_4_, double p_i46466_6_)
28
        {
29
            super(p_i46466_1_, p_i46466_2_, p_i46466_4_, p_i46466_6_);
30
            this.particleMaxAge = 4;
31
        }
32
33
        public void renderParticle(WorldRenderer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ)
34
        {
35
            float f = 0.25F;
36
            float f1 = 0.5F;
37
            float f2 = 0.125F;
38
            float f3 = 0.375F;
39
            float f4 = 7.1F * MathHelper.sin(((float)this.particleAge + partialTicks - 1.0F) * 0.25F * (float)Math.PI);
40
            this.particleAlpha = 0.6F - ((float)this.particleAge + partialTicks - 1.0F) * 0.25F * 0.5F;
41
            float f5 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)partialTicks - interpPosX);
42
            float f6 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)partialTicks - interpPosY);
43
            float f7 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)partialTicks - interpPosZ);
44
            int i = this.getBrightnessForRender(partialTicks);
45
            int j = i >> 16 & 65535;
46
            int k = i & 65535;
47
            worldRendererIn.pos((double)(f5 - rotationX * f4 - rotationXY * f4), (double)(f6 - rotationZ * f4), (double)(f7 - rotationYZ * f4 - rotationXZ * f4)).tex(0.5D, 0.375D).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex();
48
            worldRendererIn.pos((double)(f5 - rotationX * f4 + rotationXY * f4), (double)(f6 + rotationZ * f4), (double)(f7 - rotationYZ * f4 + rotationXZ * f4)).tex(0.5D, 0.125D).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex();
49
            worldRendererIn.pos((double)(f5 + rotationX * f4 + rotationXY * f4), (double)(f6 + rotationZ * f4), (double)(f7 + rotationYZ * f4 + rotationXZ * f4)).tex(0.25D, 0.125D).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex();
50
            worldRendererIn.pos((double)(f5 + rotationX * f4 - rotationXY * f4), (double)(f6 - rotationZ * f4), (double)(f7 + rotationYZ * f4 - rotationXZ * f4)).tex(0.25D, 0.375D).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex();
51
        }
52
    }
53
54
    public static class SparkFX extends EntityFX
55
    {
56
        private int baseTextureIndex = 160;
57
        private boolean trail;
58
        private boolean twinkle;
59
        private final EffectRenderer field_92047_az;
60
        private float fadeColourRed;
61
        private float fadeColourGreen;
62
        private float fadeColourBlue;
63
        private boolean hasFadeColour;
64
65
        public SparkFX(World p_i46465_1_, double p_i46465_2_, double p_i46465_4_, double p_i46465_6_, double p_i46465_8_, double p_i46465_10_, double p_i46465_12_, EffectRenderer p_i46465_14_)
66
        {
67
            super(p_i46465_1_, p_i46465_2_, p_i46465_4_, p_i46465_6_);
68
            this.motionX = p_i46465_8_;
69
            this.motionY = p_i46465_10_;
70
            this.motionZ = p_i46465_12_;
71
            this.field_92047_az = p_i46465_14_;
72
            this.particleScale *= 0.75F;
73
            this.particleMaxAge = 48 + this.rand.nextInt(12);
74
            this.noClip = false;
75
        }
76
77
        public void setTrail(boolean trailIn)
78
        {
79
            this.trail = trailIn;
80
        }
81
82
        public void setTwinkle(boolean twinkleIn)
83
        {
84
            this.twinkle = twinkleIn;
85
        }
86
87
        public void setColour(int colour)
88
        {
89
            float f = (float)((colour & 16711680) >> 16) / 255.0F;
90
            float f1 = (float)((colour & 65280) >> 8) / 255.0F;
91
            float f2 = (float)((colour & 255) >> 0) / 255.0F;
92
            float f3 = 1.0F;
93
            this.setRBGColorF(f * f3, f1 * f3, f2 * f3);
94
        }
95
96
        public void setFadeColour(int faceColour)
97
        {
98
            this.fadeColourRed = (float)((faceColour & 16711680) >> 16) / 255.0F;
99
            this.fadeColourGreen = (float)((faceColour & 65280) >> 8) / 255.0F;
100
            this.fadeColourBlue = (float)((faceColour & 255) >> 0) / 255.0F;
101
            this.hasFadeColour = true;
102
        }
103
104
        public AxisAlignedBB getCollisionBoundingBox()
105
        {
106
            return null;
107
        }
108
109
        public boolean canBePushed()
110
        {
111
            return false;
112
        }
113
114
        public void renderParticle(WorldRenderer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ)
115
        {
116
            if (!this.twinkle || this.particleAge < this.particleMaxAge / 3 || (this.particleAge + this.particleMaxAge) / 3 % 2 == 0)
117
            {
118
                super.renderParticle(worldRendererIn, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ);
119
            }
120
        }
121
122
        public void onUpdate()
123
        {
124
            this.prevPosX = this.posX;
125
            this.prevPosY = this.posY;
126
            this.prevPosZ = this.posZ;
127
128
            if (this.particleAge++ >= this.particleMaxAge)
129
            {
130
                this.setDead();
131
            }
132
133
            if (this.particleAge > this.particleMaxAge / 2)
134
            {
135
                this.setAlphaF(1.0F - ((float)this.particleAge - (float)(this.particleMaxAge / 2)) / (float)this.particleMaxAge);
136
137
                if (this.hasFadeColour)
138
                {
139
                    this.particleRed += (this.fadeColourRed - this.particleRed) * 0.2F;
140
                    this.particleGreen += (this.fadeColourGreen - this.particleGreen) * 0.2F;
141
                    this.particleBlue += (this.fadeColourBlue - this.particleBlue) * 0.2F;
142
                }
143
            }
144
145
            this.setParticleTextureIndex(this.baseTextureIndex + (7 - this.particleAge * 8 / this.particleMaxAge));
146
            this.motionY -= 0.004D;
147
            this.moveEntity(this.motionX, this.motionY, this.motionZ);
148
            this.motionX *= 0.9100000262260437D;
149
            this.motionY *= 0.9100000262260437D;
150
            this.motionZ *= 0.9100000262260437D;
151
152
            if (this.onGround)
153
            {
154
                this.motionX *= 0.699999988079071D;
155
                this.motionZ *= 0.699999988079071D;
156
            }
157
158
            if (this.trail && this.particleAge < this.particleMaxAge / 2 && (this.particleAge + this.particleMaxAge) % 2 == 0)
159
            {
160
                EntityFirework.SparkFX entityfirework$sparkfx = new EntityFirework.SparkFX(this.worldObj, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, this.field_92047_az);
161
                entityfirework$sparkfx.setAlphaF(0.99F);
162
                entityfirework$sparkfx.setRBGColorF(this.particleRed, this.particleGreen, this.particleBlue);
163
                entityfirework$sparkfx.particleAge = entityfirework$sparkfx.particleMaxAge / 2;
164
165
                if (this.hasFadeColour)
166
                {
167
                    entityfirework$sparkfx.hasFadeColour = true;
168
                    entityfirework$sparkfx.fadeColourRed = this.fadeColourRed;
169
                    entityfirework$sparkfx.fadeColourGreen = this.fadeColourGreen;
170
                    entityfirework$sparkfx.fadeColourBlue = this.fadeColourBlue;
171
                }
172
173
                entityfirework$sparkfx.twinkle = this.twinkle;
174
                this.field_92047_az.addEffect(entityfirework$sparkfx);
175
            }
176
        }
177
178
        public int getBrightnessForRender(float partialTicks)
179
        {
180
            return 15728880;
181
        }
182
183
        public float getBrightness(float partialTicks)
184
        {
185
            return 1.0F;
186
        }
187
    }
188
189
    public static class StarterFX extends EntityFX
190
    {
191
        private int fireworkAge;
192
        private final EffectRenderer theEffectRenderer;
193
        private NBTTagList fireworkExplosions;
194
        boolean twinkle;
195
196
        public StarterFX(World p_i46464_1_, double p_i46464_2_, double p_i46464_4_, double p_i46464_6_, double p_i46464_8_, double p_i46464_10_, double p_i46464_12_, EffectRenderer p_i46464_14_, NBTTagCompound p_i46464_15_)
197
        {
198
            super(p_i46464_1_, p_i46464_2_, p_i46464_4_, p_i46464_6_, 0.0D, 0.0D, 0.0D);
199
            this.motionX = p_i46464_8_;
200
            this.motionY = p_i46464_10_;
201
            this.motionZ = p_i46464_12_;
202
            this.theEffectRenderer = p_i46464_14_;
203
            this.particleMaxAge = 8;
204
205
            if (p_i46464_15_ != null)
206
            {
207
                this.fireworkExplosions = p_i46464_15_.getTagList("Explosions", 10);
208
209
                if (this.fireworkExplosions.tagCount() == 0)
210
                {
211
                    this.fireworkExplosions = null;
212
                }
213
                else
214
                {
215
                    this.particleMaxAge = this.fireworkExplosions.tagCount() * 2 - 1;
216
217
                    for (int i = 0; i < this.fireworkExplosions.tagCount(); ++i)
218
                    {
219
                        NBTTagCompound nbttagcompound = this.fireworkExplosions.getCompoundTagAt(i);
220
221
                        if (nbttagcompound.getBoolean("Flicker"))
222
                        {
223
                            this.twinkle = true;
224
                            this.particleMaxAge += 15;
225
                            break;
226
                        }
227
                    }
228
                }
229
            }
230
        }
231
232
        public void renderParticle(WorldRenderer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ)
233
        {
234
        }
235
236
        public void onUpdate()
237
        {
238
            if (this.fireworkAge == 0 && this.fireworkExplosions != null)
239
            {
240
                boolean flag = this.func_92037_i();
241
                boolean flag1 = false;
242
243
                if (this.fireworkExplosions.tagCount() >= 3)
244
                {
245
                    flag1 = true;
246
                }
247
                else
248
                {
249
                    for (int i = 0; i < this.fireworkExplosions.tagCount(); ++i)
250
                    {
251
                        NBTTagCompound nbttagcompound = this.fireworkExplosions.getCompoundTagAt(i);
252
253
                        if (nbttagcompound.getByte("Type") == 1)
254
                        {
255
                            flag1 = true;
256
                            break;
257
                        }
258
                    }
259
                }
260
261
                String s1 = "fireworks." + (flag1 ? "largeBlast" : "blast") + (flag ? "_far" : "");
262
                this.worldObj.playSound(this.posX, this.posY, this.posZ, s1, 20.0F, 0.95F + this.rand.nextFloat() * 0.1F, true);
263
            }
264
265
            if (this.fireworkAge % 2 == 0 && this.fireworkExplosions != null && this.fireworkAge / 2 < this.fireworkExplosions.tagCount())
266
            {
267
                int k = this.fireworkAge / 2;
268
                NBTTagCompound nbttagcompound1 = this.fireworkExplosions.getCompoundTagAt(k);
269
                int l = nbttagcompound1.getByte("Type");
270
                boolean flag4 = nbttagcompound1.getBoolean("Trail");
271
                boolean flag2 = nbttagcompound1.getBoolean("Flicker");
272
                int[] aint = nbttagcompound1.getIntArray("Colors");
273
                int[] aint1 = nbttagcompound1.getIntArray("FadeColors");
274
275
                if (aint.length == 0)
276
                {
277
                    aint = new int[] {ItemDye.dyeColors[0]};
278
                }
279
280
                if (l == 1)
281
                {
282
                    this.createBall(0.5D, 4, aint, aint1, flag4, flag2);
283
                }
284
                else if (l == 2)
285
                {
286
                    this.createShaped(0.5D, new double[][] {{0.0D, 1.0D}, {0.3455D, 0.309D}, {0.9511D, 0.309D}, {0.3795918367346939D, -0.12653061224489795D}, {0.6122448979591837D, -0.8040816326530612D}, {0.0D, -0.35918367346938773D}}, aint, aint1, flag4, flag2, false);
287
                }
288
                else if (l == 3)
289
                {
290
                    this.createShaped(0.5D, new double[][] {{0.0D, 0.2D}, {0.2D, 0.2D}, {0.2D, 0.6D}, {0.6D, 0.6D}, {0.6D, 0.2D}, {0.2D, 0.2D}, {0.2D, 0.0D}, {0.4D, 0.0D}, {0.4D, -0.6D}, {0.2D, -0.6D}, {0.2D, -0.4D}, {0.0D, -0.4D}}, aint, aint1, flag4, flag2, true);
291
                }
292
                else if (l == 4)
293
                {
294
                    this.createBurst(aint, aint1, flag4, flag2);
295
                }
296
                else
297
                {
298
                    this.createBall(0.25D, 2, aint, aint1, flag4, flag2);
299
                }
300
301
                int j = aint[0];
302
                float f = (float)((j & 16711680) >> 16) / 255.0F;
303
                float f1 = (float)((j & 65280) >> 8) / 255.0F;
304
                float f2 = (float)((j & 255) >> 0) / 255.0F;
305
                EntityFirework.OverlayFX entityfirework$overlayfx = new EntityFirework.OverlayFX(this.worldObj, this.posX, this.posY, this.posZ);
306
                entityfirework$overlayfx.setRBGColorF(f, f1, f2);
307
                this.theEffectRenderer.addEffect(entityfirework$overlayfx);
308
            }
309
310
            ++this.fireworkAge;
311
312
            if (this.fireworkAge > this.particleMaxAge)
313
            {
314
                if (this.twinkle)
315
                {
316
                    boolean flag3 = this.func_92037_i();
317
                    String s = "fireworks." + (flag3 ? "twinkle_far" : "twinkle");
318
                    this.worldObj.playSound(this.posX, this.posY, this.posZ, s, 20.0F, 0.9F + this.rand.nextFloat() * 0.15F, true);
319
                }
320
321
                this.setDead();
322
            }
323
        }
324
325
        private boolean func_92037_i()
326
        {
327
            Minecraft minecraft = Minecraft.getMinecraft();
328
            return minecraft == null || minecraft.getRenderViewEntity() == null || minecraft.getRenderViewEntity().getDistanceSq(this.posX, this.posY, this.posZ) >= 256.0D;
329
        }
330
331
        private void createParticle(double p_92034_1_, double p_92034_3_, double p_92034_5_, double p_92034_7_, double p_92034_9_, double p_92034_11_, int[] p_92034_13_, int[] p_92034_14_, boolean p_92034_15_, boolean p_92034_16_)
332
        {
333
            EntityFirework.SparkFX entityfirework$sparkfx = new EntityFirework.SparkFX(this.worldObj, p_92034_1_, p_92034_3_, p_92034_5_, p_92034_7_, p_92034_9_, p_92034_11_, this.theEffectRenderer);
334
            entityfirework$sparkfx.setAlphaF(0.99F);
335
            entityfirework$sparkfx.setTrail(p_92034_15_);
336
            entityfirework$sparkfx.setTwinkle(p_92034_16_);
337
            int i = this.rand.nextInt(p_92034_13_.length);
338
            entityfirework$sparkfx.setColour(p_92034_13_[i]);
339
340
            if (p_92034_14_ != null && p_92034_14_.length > 0)
341
            {
342
                entityfirework$sparkfx.setFadeColour(p_92034_14_[this.rand.nextInt(p_92034_14_.length)]);
343
            }
344
345
            this.theEffectRenderer.addEffect(entityfirework$sparkfx);
346
        }
347
348
        private void createBall(double speed, int size, int[] colours, int[] fadeColours, boolean trail, boolean twinkleIn)
349
        {
350
            double d0 = this.posX;
351
            double d1 = this.posY;
352
            double d2 = this.posZ;
353
354
            for (int i = -size; i <= size; ++i)
355
            {
356
                for (int j = -size; j <= size; ++j)
357
                {
358
                    for (int k = -size; k <= size; ++k)
359
                    {
360
                        double d3 = (double)j + (this.rand.nextDouble() - this.rand.nextDouble()) * 0.5D;
361
                        double d4 = (double)i + (this.rand.nextDouble() - this.rand.nextDouble()) * 0.5D;
362
                        double d5 = (double)k + (this.rand.nextDouble() - this.rand.nextDouble()) * 0.5D;
363
                        double d6 = (double)MathHelper.sqrt_double(d3 * d3 + d4 * d4 + d5 * d5) / speed + this.rand.nextGaussian() * 0.05D;
364
                        this.createParticle(d0, d1, d2, d3 / d6, d4 / d6, d5 / d6, colours, fadeColours, trail, twinkleIn);
365
366
                        if (i != -size && i != size && j != -size && j != size)
367
                        {
368
                            k += size * 2 - 1;
369
                        }
370
                    }
371
                }
372
            }
373
        }
374
375
        private void createShaped(double speed, double[][] shape, int[] colours, int[] fadeColours, boolean trail, boolean twinkleIn, boolean p_92038_8_)
376
        {
377
            double d0 = shape[0][0];
378
            double d1 = shape[0][1];
379
            this.createParticle(this.posX, this.posY, this.posZ, d0 * speed, d1 * speed, 0.0D, colours, fadeColours, trail, twinkleIn);
380
            float f = this.rand.nextFloat() * (float)Math.PI;
381
            double d2 = p_92038_8_ ? 0.034D : 0.34D;
382
383
            for (int i = 0; i < 3; ++i)
384
            {
385
                double d3 = (double)f + (double)((float)i * (float)Math.PI) * d2;
386
                double d4 = d0;
387
                double d5 = d1;
388
389
                for (int j = 1; j < shape.length; ++j)
390
                {
391
                    double d6 = shape[j][0];
392
                    double d7 = shape[j][1];
393
394
                    for (double d8 = 0.25D; d8 <= 1.0D; d8 += 0.25D)
395
                    {
396
                        double d9 = (d4 + (d6 - d4) * d8) * speed;
397
                        double d10 = (d5 + (d7 - d5) * d8) * speed;
398
                        double d11 = d9 * Math.sin(d3);
399
                        d9 = d9 * Math.cos(d3);
400
401
                        for (double d12 = -1.0D; d12 <= 1.0D; d12 += 2.0D)
402
                        {
403
                            this.createParticle(this.posX, this.posY, this.posZ, d9 * d12, d10, d11 * d12, colours, fadeColours, trail, twinkleIn);
404
                        }
405
                    }
406
407
                    d4 = d6;
408
                    d5 = d7;
409
                }
410
            }
411
        }
412
413
        private void createBurst(int[] colours, int[] fadeColours, boolean trail, boolean twinkleIn)
414
        {
415
            double d0 = this.rand.nextGaussian() * 0.05D;
416
            double d1 = this.rand.nextGaussian() * 0.05D;
417
418
            for (int i = 0; i < 70; ++i)
419
            {
420
                double d2 = this.motionX * 0.5D + this.rand.nextGaussian() * 0.15D + d0;
421
                double d3 = this.motionZ * 0.5D + this.rand.nextGaussian() * 0.15D + d1;
422
                double d4 = this.motionY * 0.5D + this.rand.nextDouble() * 0.5D;
423
                this.createParticle(this.posX, this.posY, this.posZ, d2, d4, d3, colours, fadeColours, trail, twinkleIn);
424
            }
425
        }
426
427
        public int getFXLayer()
428
        {
429
            return 0;
430
        }
431
    }
432
}
433

Deobfuscated MCP 1.8.9 source of EntityFirework from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/particle/EntityFirework.java), stored verbatim.