Added EntityCustomFX class, used for spawning custom particles on entities.

This commit is contained in:
luisc committed 2021-09-05 21:53:58 -05:00
1 parent 459976c54d
commit 2a378190ae
1 file changed
+126
@@ -0,0 +1,126 @@
package noppes.npcs.client.fx;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.ModelPartData;
import noppes.npcs.client.ClientProxy;
import org.lwjgl.opengl.GL11;
public class EntityCustomFX extends EntityFX {
private Entity entity;
private final ResourceLocation location;
private boolean move = true;
private float startX = 0, startY = 0, startZ = 0;
public float scale1 = 1.0F;
public float scale2 = 1.0F;
public float scaleRate = 1.0F;
public int scaleRateStart = 0;
public float alpha1 = 1.0F;
public float alpha2 = 0;
public float alphaRate = 0.0F;
public int alphaRateStart = 0;
public EntityCustomFX(Entity entity, double x, double y, double z,
double motionX, double motionY, double motionZ, float gravity,
float scale1, float scale2, float scaleRate, int scaleRateStart,
float alpha1, float alpha2, float alphaRate, int alphaRateStart,
int age,
ModelPartData data) {
super(entity.worldObj, x, y, z, motionX, motionY, motionZ);
this.scale1 = scale1;
this.scale2 = scale2;
this.scaleRate = Math.abs(scaleRate);
this.scaleRateStart = scaleRateStart;
particleScale = scale1;
if(scale1 > scale2)
this.scaleRate *= -1;
this.alpha1 = alpha1;
this.alpha2 = alpha2;
this.alphaRate = Math.abs(alphaRate);
this.alphaRateStart = alphaRateStart;
particleAlpha = alpha1;
if(alpha1 > alpha2)
this.alphaRate *= -1;
particleGravity = gravity/0.04F;
particleMaxAge = age;
this.motionX = motionX;
this.motionY = motionY;
this.motionZ = motionZ;
this.entity = entity;
noClip = true;
particleRed = (data.color >> 16 & 255) / 255f;
particleGreen = (data.color >> 8 & 255) / 255f;
particleBlue = (data.color & 255) / 255f;
if(Math.floor(Math.random()*3) == 1){
move = false;
this.startX = (float) entity.posX;
this.startY = (float) entity.posY;
this.startZ = (float) entity.posZ;
}
location = new ResourceLocation(data.texture);
}
@Override
public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7)
{
if(move){
startX = (float)(entity.prevPosX + (entity.posX - entity.prevPosX) * (double)par2);
startY = (float)(entity.prevPosY + (entity.posY - entity.prevPosY) * (double)par2);
startZ = (float)(entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double)par2);
}
Tessellator tessellator = Tessellator.instance;
tessellator.draw();
float scale = this.scaleRate / (float)particleMaxAge;
if((this.scaleRate < 0 && particleScale+scale < this.scale2) || (this.scaleRate > 0 && particleScale+scale > this.scale2))
particleScale = this.scale2;
else if(particleAge >= this.scaleRateStart)
particleScale += scale;
float alpha = this.alphaRate / (float)particleMaxAge;
if((this.alphaRate < 0 && particleAlpha+alpha < this.alpha2) || (this.alphaRate > 0 && particleAlpha+alpha > this.alpha2))
particleAlpha = this.alpha2;
else if(particleAge >= this.alphaRateStart)
particleAlpha += alpha;
ClientProxy.bindTexture(location);
float f = 0.0f;
float f1 = 1.0f;
float f2 = 0.0f;
float f3 = 1.0f;
float f4 = 0.1F * particleScale;
float f5 = (float)(((prevPosX + (posX - prevPosX) * (double)par2) - interpPosX) + startX);
float f6 = (float)(((prevPosY + (posY - prevPosY) * (double)par2) - interpPosY) + startY);
float f7 = (float)(((prevPosZ + (posZ - prevPosZ) * (double)par2) - interpPosZ) + startZ);
GL11.glColor4f(1, 1, 1, 1.0F);
tessellator.startDrawingQuads();
tessellator.setBrightness(240);
par1Tessellator.setColorOpaque_F(1, 1, 1);
par1Tessellator.setColorRGBA_F(particleRed, particleGreen, particleBlue, particleAlpha);
par1Tessellator.addVertexWithUV(f5 - par3 * f4 - par6 * f4, f6 - par4 * f4, f7 - par5 * f4 - par7 * f4, f1, f3);
par1Tessellator.addVertexWithUV((f5 - par3 * f4) + par6 * f4, f6 + par4 * f4, (f7 - par5 * f4) + par7 * f4, f1, f2);
par1Tessellator.addVertexWithUV(f5 + par3 * f4 + par6 * f4, f6 + par4 * f4, f7 + par5 * f4 + par7 * f4, f, f2);
par1Tessellator.addVertexWithUV((f5 + par3 * f4) - par6 * f4, f6 - par4 * f4, (f7 + par5 * f4) - par7 * f4, f, f3);
tessellator.draw();
tessellator.startDrawingQuads();
}
public int getFXLayer(){
return 0;
}
}