1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
package ihl.explosion;
import java.util.Random;
import ihl.utils.IHLMathUtils;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.world.World;
public class ExplosionEntityFX extends EntityFX {
private float radius;
private static final Random random = new Random();
private final int[] particlesMaxAge;
private final int[] particlesTextureIndexX;
private final int[] particlesTextureIndexY;
private final double[][] startPos;
private final double[][] pos;
private final double[][] prevPos;
private final float[][] motion;
private final int[] center;
public ExplosionEntityFX(World world, double x, double y, double z)
{
super(world, x, y, z);
this.renderDistanceWeight = 5.0D;
int numParticles = 1;
particlesMaxAge = new int[numParticles];
particlesTextureIndexX = new int[numParticles];
particlesTextureIndexY= new int[numParticles];
startPos = new double[numParticles][3];
pos = new double[numParticles][3];
prevPos = new double[numParticles][3];
motion = new float[numParticles][3];
center = new int[3];
}
public ExplosionEntityFX(World par1World, int centerX1, int centerY1, int centerZ1, float radius1)
{
super(par1World, centerX1, centerY1, centerZ1, 0.0D, 0.0D, 0.0D);
this.particleMaxAge = 100;
this.center = new int[3];
this.lastTickPosX=this.posX=this.prevPosX=this.center[0]=centerX1;
this.lastTickPosY=this.posY=this.prevPosY=this.center[1]=centerY1;
this.lastTickPosZ=this.posZ=this.prevPosZ=this.center[2]=centerZ1;
this.radius=radius1;
float r2 = radius*radius;
int numParticles = (int)(r2*radius/32)+64;
this.startPos = new double[numParticles][3];
this.pos = new double[numParticles][3];
this.prevPos = new double[numParticles][3];
this.particleScale *= 40f;
this.particlesMaxAge = new int[numParticles];
this.particlesTextureIndexX = new int[numParticles];
this.particlesTextureIndexY= new int[numParticles];
this.motion = new float[numParticles][3];
for(int i=0;i<numParticles;i++)
{
float fPosX = random.nextFloat()*2f-1f;
float fPosY = (random.nextFloat()*2f-1f)*IHLMathUtils.sqrt(1f-fPosX*fPosX);
float fPosZ = (random.nextFloat()*2f-1f)*IHLMathUtils.sqrt(1f-fPosX*fPosX-fPosY*fPosY);
fPosX *= radius1;
fPosY *= radius1;
fPosZ *= radius1;
prevPos[i][0] = pos[i][0] = startPos[i][0] = fPosX + centerX1;
prevPos[i][1] = pos[i][1] = startPos[i][1] = fPosY + centerY1;
prevPos[i][2] = pos[i][2] = startPos[i][2] = fPosZ + centerZ1;
particlesMaxAge[i] = random.nextInt(particleMaxAge-20)+16;
particlesTextureIndexY[i]=random.nextInt(8);
}
this.noClip = true;
this.renderDistanceWeight = 6.0D+radius1/2;
}
@Override
public void renderParticle(Tessellator tessellator, float interFrame, float rotationX, float rotationXZ, float rotationZ, float rotationYZ, float rotationXY)
{
for(int i=0;i<particlesMaxAge.length;i++)
{
float u1 = this.particlesTextureIndexX[i] / 16.0F;
float u2 = u1 + 1F / 16.0F;
float v1 = this.particlesTextureIndexY[i] / 8.0F;
float v2 = v1 + 1F / 8.0F;
float scale = 0.1F * this.particleScale;
float fPosX = (float)(this.prevPos[i][0] - this.prevPosX + (this.pos[i][0] - this.prevPos[i][0]) * interFrame);
float fPosY = (float)(this.prevPos[i][1] - this.prevPosY + (this.pos[i][1] - this.prevPos[i][1]) * interFrame);
float fPosZ = (float)(this.prevPos[i][2] - this.prevPosZ + (this.pos[i][2] - this.prevPos[i][2]) * interFrame);
tessellator.addVertexWithUV(
fPosX - rotationX * scale - rotationYZ * scale,
fPosY - rotationXZ * scale,
fPosZ - rotationZ * scale - rotationXY * scale,
u2, v2);
tessellator.addVertexWithUV(
fPosX - rotationX * scale + rotationYZ * scale,
fPosY + rotationXZ * scale,
fPosZ - rotationZ * scale + rotationXY * scale,
u2, v1);
tessellator.addVertexWithUV(
fPosX + rotationX * scale + rotationYZ * scale,
fPosY + rotationXZ * scale,
fPosZ + rotationZ * scale + rotationXY * scale,
u1, v1);
tessellator.addVertexWithUV(
fPosX + rotationX * scale - rotationYZ * scale,
fPosY - rotationXZ * scale,
fPosZ + rotationZ * scale - rotationXY * scale,
u1, v2);
}
}
@Override
public void onUpdate()
{
if (this.particleAge++ >= this.particleMaxAge)
{
this.setDead();
}
for(int i=0;i<particlesMaxAge.length;i++)
{
this.prevPos[i][0] = this.pos[i][0];
this.prevPos[i][1] = this.pos[i][1];
this.prevPos[i][2] = this.pos[i][2];
int maxFrameX = 15;
int frameX = this.particleAge * maxFrameX / this.particlesMaxAge[i];
if(frameX<=maxFrameX)
{
this.particlesTextureIndexX[i] = frameX;
}
if(this.startPos[i][1] < this.center[1])
{
IHLMathUtils.vector_add(this.motion[i],
(float)(this.center[0]-this.pos[i][0])*0.0004f,
0.004f,
(float)(this.center[2]-this.pos[i][2])*0.0004f);
}
else
{
float[] ring = new float[] {
(float)(this.startPos[i][0]-this.center[0]),
0f,
(float)(this.startPos[i][2]-this.center[2])};
IHLMathUtils.scale_vector_to_value(ring, radius*0.6f);
IHLMathUtils.vector_add(ring,
this.center[0],
(float)this.startPos[i][1]+this.particleAge*0.001f,
this.center[2]);
float[] from_point_to_ring = IHLMathUtils.vector_return_difference(ring,this.pos[i]);
float[] from_point_to_center = IHLMathUtils.vector_return_difference(this.center,this.pos[i]);
float[] tangent_to_ring = IHLMathUtils.vector_vector_multiply(from_point_to_ring, from_point_to_center);
float[] tangent_to_torus = IHLMathUtils.vector_vector_multiply(from_point_to_ring, tangent_to_ring);
IHLMathUtils.normalize_vector(tangent_to_torus);
IHLMathUtils.vector_add(this.motion[i],
from_point_to_ring[0]*0.01f + tangent_to_torus[0]*0.02f,
from_point_to_ring[1]*0.01f + tangent_to_torus[1]*0.02f + 0.004f,
from_point_to_ring[2]*0.01f + tangent_to_torus[2]*0.02f);
}
IHLMathUtils.vector_add(this.pos[i],this.motion[i]);
IHLMathUtils.multiply_vector_to_value(this.motion[i], 0.98f);
}
}
@Override
public void setParticleTextureIndex(int par1)
{
this.particleTextureIndexX = par1;
}
@Override
public boolean shouldRenderInPass(int pass)
{
return pass==1;
}
}
|