pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,11 +18,10 @@
|
||||
|
||||
package appeng.client.render.effects;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.particle.*;
|
||||
import net.minecraft.client.renderer.ActiveRenderInfo;
|
||||
@@ -38,251 +37,234 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public class LightningFX extends SpriteTexturedParticle
|
||||
{
|
||||
public static final BasicParticleType TYPE = new BasicParticleType(false);
|
||||
import appeng.core.AppEng;
|
||||
|
||||
static {
|
||||
TYPE.setRegistryName(AppEng.MOD_ID, "lightning_fx");
|
||||
}
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class LightningFX extends SpriteTexturedParticle {
|
||||
public static final BasicParticleType TYPE = new BasicParticleType(false);
|
||||
|
||||
private static final Random RANDOM_GENERATOR = new Random();
|
||||
private static final int STEPS = 5;
|
||||
private static final int BRIGHTNESS = 13 << 4;
|
||||
static {
|
||||
TYPE.setRegistryName(AppEng.MOD_ID, "lightning_fx");
|
||||
}
|
||||
|
||||
private final double[][] precomputedSteps;
|
||||
private final double[] vertices = new double[3];
|
||||
private final double[] verticesWithUV = new double[3];
|
||||
private boolean hasData = false;
|
||||
private static final Random RANDOM_GENERATOR = new Random();
|
||||
private static final int STEPS = 5;
|
||||
private static final int BRIGHTNESS = 13 << 4;
|
||||
|
||||
private LightningFX( final World w, final double x, final double y, final double z, final double r, final double g, final double b )
|
||||
{
|
||||
this( w, x, y, z, r, g, b, 6 );
|
||||
this.regen();
|
||||
}
|
||||
private final double[][] precomputedSteps;
|
||||
private final double[] vertices = new double[3];
|
||||
private final double[] verticesWithUV = new double[3];
|
||||
private boolean hasData = false;
|
||||
|
||||
protected LightningFX( final World w, final double x, final double y, final double z, final double r, final double g, final double b, final int maxAge )
|
||||
{
|
||||
super( w, x, y, z, r, g, b );
|
||||
this.precomputedSteps = new double[LightningFX.STEPS][3];
|
||||
this.motionX = 0;
|
||||
this.motionY = 0;
|
||||
this.motionZ = 0;
|
||||
this.maxAge = maxAge;
|
||||
}
|
||||
private LightningFX(final World w, final double x, final double y, final double z, final double r, final double g,
|
||||
final double b) {
|
||||
this(w, x, y, z, r, g, b, 6);
|
||||
this.regen();
|
||||
}
|
||||
|
||||
protected void regen()
|
||||
{
|
||||
double lastDirectionX = ( RANDOM_GENERATOR.nextDouble() - 0.5 ) * 0.9;
|
||||
double lastDirectionY = ( RANDOM_GENERATOR.nextDouble() - 0.5 ) * 0.9;
|
||||
double lastDirectionZ = ( RANDOM_GENERATOR.nextDouble() - 0.5 ) * 0.9;
|
||||
for( int s = 0; s < LightningFX.STEPS; s++ )
|
||||
{
|
||||
this.precomputedSteps[s][0] = lastDirectionX = ( lastDirectionX + ( RANDOM_GENERATOR.nextDouble() - 0.5 ) * 0.9 ) / 2.0;
|
||||
this.precomputedSteps[s][1] = lastDirectionY = ( lastDirectionY + ( RANDOM_GENERATOR.nextDouble() - 0.5 ) * 0.9 ) / 2.0;
|
||||
this.precomputedSteps[s][2] = lastDirectionZ = ( lastDirectionZ + ( RANDOM_GENERATOR.nextDouble() - 0.5 ) * 0.9 ) / 2.0;
|
||||
}
|
||||
}
|
||||
protected LightningFX(final World w, final double x, final double y, final double z, final double r, final double g,
|
||||
final double b, final int maxAge) {
|
||||
super(w, x, y, z, r, g, b);
|
||||
this.precomputedSteps = new double[LightningFX.STEPS][3];
|
||||
this.motionX = 0;
|
||||
this.motionY = 0;
|
||||
this.motionZ = 0;
|
||||
this.maxAge = maxAge;
|
||||
}
|
||||
|
||||
protected int getSteps()
|
||||
{
|
||||
return LightningFX.STEPS;
|
||||
}
|
||||
protected void regen() {
|
||||
double lastDirectionX = (RANDOM_GENERATOR.nextDouble() - 0.5) * 0.9;
|
||||
double lastDirectionY = (RANDOM_GENERATOR.nextDouble() - 0.5) * 0.9;
|
||||
double lastDirectionZ = (RANDOM_GENERATOR.nextDouble() - 0.5) * 0.9;
|
||||
for (int s = 0; s < LightningFX.STEPS; s++) {
|
||||
this.precomputedSteps[s][0] = lastDirectionX = (lastDirectionX
|
||||
+ (RANDOM_GENERATOR.nextDouble() - 0.5) * 0.9) / 2.0;
|
||||
this.precomputedSteps[s][1] = lastDirectionY = (lastDirectionY
|
||||
+ (RANDOM_GENERATOR.nextDouble() - 0.5) * 0.9) / 2.0;
|
||||
this.precomputedSteps[s][2] = lastDirectionZ = (lastDirectionZ
|
||||
+ (RANDOM_GENERATOR.nextDouble() - 0.5) * 0.9) / 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IParticleRenderType getRenderType() {
|
||||
// TODO: FIXME
|
||||
return IParticleRenderType.PARTICLE_SHEET_OPAQUE;
|
||||
}
|
||||
protected int getSteps() {
|
||||
return LightningFX.STEPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
this.prevPosX = this.posX;
|
||||
this.prevPosY = this.posY;
|
||||
this.prevPosZ = this.posZ;
|
||||
@Override
|
||||
public IParticleRenderType getRenderType() {
|
||||
// TODO: FIXME
|
||||
return IParticleRenderType.PARTICLE_SHEET_OPAQUE;
|
||||
}
|
||||
|
||||
if( this.age++ >= this.maxAge )
|
||||
{
|
||||
this.setExpired();
|
||||
}
|
||||
@Override
|
||||
public void tick() {
|
||||
this.prevPosX = this.posX;
|
||||
this.prevPosY = this.posY;
|
||||
this.prevPosZ = this.posZ;
|
||||
|
||||
this.motionY -= 0.04D * this.particleGravity;
|
||||
this.move( this.motionX, this.motionY, this.motionZ );
|
||||
this.motionX *= 0.9800000190734863D;
|
||||
this.motionY *= 0.9800000190734863D;
|
||||
this.motionZ *= 0.9800000190734863D;
|
||||
}
|
||||
if (this.age++ >= this.maxAge) {
|
||||
this.setExpired();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderParticle(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) {
|
||||
Vec3d vec3d = renderInfo.getProjectedView();
|
||||
float centerX = (float)(MathHelper.lerp(partialTicks, this.prevPosX, this.posX) - vec3d.getX());
|
||||
float centerY = (float)(MathHelper.lerp(partialTicks, this.prevPosY, this.posY) - vec3d.getY());
|
||||
float centerZ = (float)(MathHelper.lerp(partialTicks, this.prevPosZ, this.posZ) - vec3d.getZ());
|
||||
this.motionY -= 0.04D * this.particleGravity;
|
||||
this.move(this.motionX, this.motionY, this.motionZ);
|
||||
this.motionX *= 0.9800000190734863D;
|
||||
this.motionY *= 0.9800000190734863D;
|
||||
this.motionZ *= 0.9800000190734863D;
|
||||
}
|
||||
|
||||
final float j = 1.0f;
|
||||
float red = this.particleRed * j * 0.9f;
|
||||
float green = this.particleGreen * j * 0.95f;
|
||||
float blue = this.particleBlue * j;
|
||||
final float alpha = this.particleAlpha;
|
||||
@Override
|
||||
public void renderParticle(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) {
|
||||
Vec3d vec3d = renderInfo.getProjectedView();
|
||||
float centerX = (float) (MathHelper.lerp(partialTicks, this.prevPosX, this.posX) - vec3d.getX());
|
||||
float centerY = (float) (MathHelper.lerp(partialTicks, this.prevPosY, this.posY) - vec3d.getY());
|
||||
float centerZ = (float) (MathHelper.lerp(partialTicks, this.prevPosZ, this.posZ) - vec3d.getZ());
|
||||
|
||||
if( this.age == 3 )
|
||||
{
|
||||
this.regen();
|
||||
}
|
||||
final float j = 1.0f;
|
||||
float red = this.particleRed * j * 0.9f;
|
||||
float green = this.particleGreen * j * 0.95f;
|
||||
float blue = this.particleBlue * j;
|
||||
final float alpha = this.particleAlpha;
|
||||
|
||||
float u = this.getMinU() + (this.getMaxU() - this.getMinU()) / 2;
|
||||
float v = this.getMinV() + (this.getMaxV() - this.getMinV()) / 2;
|
||||
if (this.age == 3) {
|
||||
this.regen();
|
||||
}
|
||||
|
||||
double scale = 0.02;// 0.02F * this.particleScale;
|
||||
float u = this.getMinU() + (this.getMaxU() - this.getMinU()) / 2;
|
||||
float v = this.getMinV() + (this.getMaxV() - this.getMinV()) / 2;
|
||||
|
||||
final double[] a = new double[3];
|
||||
final double[] b = new double[3];
|
||||
double scale = 0.02;// 0.02F * this.particleScale;
|
||||
|
||||
double ox = 0;
|
||||
double oy = 0;
|
||||
double oz = 0;
|
||||
final double[] a = new double[3];
|
||||
final double[] b = new double[3];
|
||||
|
||||
final PlayerEntity p = Minecraft.getInstance().player;
|
||||
double ox = 0;
|
||||
double oy = 0;
|
||||
double oz = 0;
|
||||
|
||||
// FIXME: Billboard rotation is not applied to the particle yet,
|
||||
// FIXME The old version apparently did this by hand using rX,rZ -> replicate using the quaternion
|
||||
final PlayerEntity p = Minecraft.getInstance().player;
|
||||
|
||||
for( int layer = 0; layer < 2; layer++ )
|
||||
{
|
||||
if( layer == 0 )
|
||||
{
|
||||
scale = 0.04;
|
||||
// FIXME: Billboard rotation is not applied to the particle yet,
|
||||
// FIXME The old version apparently did this by hand using rX,rZ -> replicate
|
||||
// using the quaternion
|
||||
|
||||
for (int layer = 0; layer < 2; layer++) {
|
||||
if (layer == 0) {
|
||||
scale = 0.04;
|
||||
// FIXME offX *= 0.001;
|
||||
// FIXME offY *= 0.001;
|
||||
// FIXME offZ *= 0.001;
|
||||
red = this.particleRed * j * 0.4f;
|
||||
green = this.particleGreen * j * 0.25f;
|
||||
blue = this.particleBlue * j * 0.45f;
|
||||
}
|
||||
else
|
||||
{
|
||||
red = this.particleRed * j * 0.4f;
|
||||
green = this.particleGreen * j * 0.25f;
|
||||
blue = this.particleBlue * j * 0.45f;
|
||||
} else {
|
||||
// FIXME offX = 0;
|
||||
// FIXME offY = 0;
|
||||
// FIXME offZ = 0;
|
||||
scale = 0.02;
|
||||
red = this.particleRed * j * 0.9f;
|
||||
green = this.particleGreen * j * 0.65f;
|
||||
blue = this.particleBlue * j * 0.85f;
|
||||
}
|
||||
scale = 0.02;
|
||||
red = this.particleRed * j * 0.9f;
|
||||
green = this.particleGreen * j * 0.65f;
|
||||
blue = this.particleBlue * j * 0.85f;
|
||||
}
|
||||
|
||||
for( int cycle = 0; cycle < 3; cycle++ )
|
||||
{
|
||||
this.clear();
|
||||
for (int cycle = 0; cycle < 3; cycle++) {
|
||||
this.clear();
|
||||
|
||||
// FIXME removed interpPos here, check if this is correct
|
||||
double x = centerX; // FIXME - offX;
|
||||
double y = centerY; // FIXME - offY;
|
||||
double z = centerZ; // FIXME - offZ;
|
||||
// FIXME removed interpPos here, check if this is correct
|
||||
double x = centerX; // FIXME - offX;
|
||||
double y = centerY; // FIXME - offY;
|
||||
double z = centerZ; // FIXME - offZ;
|
||||
|
||||
for( int s = 0; s < LightningFX.STEPS; s++ )
|
||||
{
|
||||
final double xN = x + this.precomputedSteps[s][0];
|
||||
final double yN = y + this.precomputedSteps[s][1];
|
||||
final double zN = z + this.precomputedSteps[s][2];
|
||||
for (int s = 0; s < LightningFX.STEPS; s++) {
|
||||
final double xN = x + this.precomputedSteps[s][0];
|
||||
final double yN = y + this.precomputedSteps[s][1];
|
||||
final double zN = z + this.precomputedSteps[s][2];
|
||||
|
||||
final double xD = xN - x;
|
||||
final double yD = yN - y;
|
||||
final double zD = zN - z;
|
||||
final double xD = xN - x;
|
||||
final double yD = yN - y;
|
||||
final double zD = zN - z;
|
||||
|
||||
if( cycle == 0 )
|
||||
{
|
||||
ox = ( yD * 0 ) - ( 1 * zD );
|
||||
oy = ( zD * 0 ) - ( 0 * xD );
|
||||
oz = ( xD * 1 ) - ( 0 * yD );
|
||||
}
|
||||
if( cycle == 1 )
|
||||
{
|
||||
ox = ( yD * 1 ) - ( 0 * zD );
|
||||
oy = ( zD * 0 ) - ( 1 * xD );
|
||||
oz = ( xD * 0 ) - ( 0 * yD );
|
||||
}
|
||||
if( cycle == 2 )
|
||||
{
|
||||
ox = ( yD * 0 ) - ( 0 * zD );
|
||||
oy = ( zD * 1 ) - ( 0 * xD );
|
||||
oz = ( xD * 0 ) - ( 1 * yD );
|
||||
}
|
||||
if (cycle == 0) {
|
||||
ox = (yD * 0) - (1 * zD);
|
||||
oy = (zD * 0) - (0 * xD);
|
||||
oz = (xD * 1) - (0 * yD);
|
||||
}
|
||||
if (cycle == 1) {
|
||||
ox = (yD * 1) - (0 * zD);
|
||||
oy = (zD * 0) - (1 * xD);
|
||||
oz = (xD * 0) - (0 * yD);
|
||||
}
|
||||
if (cycle == 2) {
|
||||
ox = (yD * 0) - (0 * zD);
|
||||
oy = (zD * 1) - (0 * xD);
|
||||
oz = (xD * 0) - (1 * yD);
|
||||
}
|
||||
|
||||
final double ss = Math
|
||||
.sqrt( ox * ox + oy * oy + oz * oz ) / ( ( ( (double) LightningFX.STEPS - (double) s ) / LightningFX.STEPS ) * scale );
|
||||
ox /= ss;
|
||||
oy /= ss;
|
||||
oz /= ss;
|
||||
final double ss = Math.sqrt(ox * ox + oy * oy + oz * oz)
|
||||
/ ((((double) LightningFX.STEPS - (double) s) / LightningFX.STEPS) * scale);
|
||||
ox /= ss;
|
||||
oy /= ss;
|
||||
oz /= ss;
|
||||
|
||||
a[0] = x + ox;
|
||||
a[1] = y + oy;
|
||||
a[2] = z + oz;
|
||||
a[0] = x + ox;
|
||||
a[1] = y + oy;
|
||||
a[2] = z + oz;
|
||||
|
||||
b[0] = x;
|
||||
b[1] = y;
|
||||
b[2] = z;
|
||||
b[0] = x;
|
||||
b[1] = y;
|
||||
b[2] = z;
|
||||
|
||||
this.draw( red, green, blue, buffer, a, b, u, v );
|
||||
this.draw(red, green, blue, buffer, a, b, u, v);
|
||||
|
||||
x = xN;
|
||||
y = yN;
|
||||
z = zN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
x = xN;
|
||||
y = yN;
|
||||
z = zN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void clear()
|
||||
{
|
||||
this.hasData = false;
|
||||
}
|
||||
private void clear() {
|
||||
this.hasData = false;
|
||||
}
|
||||
|
||||
private void draw( float red, float green, float blue, final IVertexBuilder tess, final double[] a, final double[] b, final float u, final float v )
|
||||
{
|
||||
if( this.hasData )
|
||||
{
|
||||
tess.pos( a[0], a[1], a[2] ).tex( u, v ).color( red, green, blue, this.particleAlpha ).lightmap( BRIGHTNESS, BRIGHTNESS ).endVertex();
|
||||
tess.pos( this.vertices[0], this.vertices[1], this.vertices[2] )
|
||||
.tex( u, v )
|
||||
.color( red, green, blue, this.particleAlpha )
|
||||
.lightmap( BRIGHTNESS, BRIGHTNESS )
|
||||
.endVertex();
|
||||
tess.pos( this.verticesWithUV[0], this.verticesWithUV[1], this.verticesWithUV[2] )
|
||||
.tex( u, v )
|
||||
.color( red, green, blue, this.particleAlpha )
|
||||
.lightmap( BRIGHTNESS, BRIGHTNESS )
|
||||
.endVertex();
|
||||
tess.pos( b[0], b[1], b[2] ).tex( u, v ).color( red, green, blue, this.particleAlpha ).lightmap( BRIGHTNESS, BRIGHTNESS ).endVertex();
|
||||
}
|
||||
this.hasData = true;
|
||||
for( int x = 0; x < 3; x++ )
|
||||
{
|
||||
this.vertices[x] = a[x];
|
||||
this.verticesWithUV[x] = b[x];
|
||||
}
|
||||
}
|
||||
private void draw(float red, float green, float blue, final IVertexBuilder tess, final double[] a, final double[] b,
|
||||
final float u, final float v) {
|
||||
if (this.hasData) {
|
||||
tess.pos(a[0], a[1], a[2]).tex(u, v).color(red, green, blue, this.particleAlpha)
|
||||
.lightmap(BRIGHTNESS, BRIGHTNESS).endVertex();
|
||||
tess.pos(this.vertices[0], this.vertices[1], this.vertices[2]).tex(u, v)
|
||||
.color(red, green, blue, this.particleAlpha).lightmap(BRIGHTNESS, BRIGHTNESS).endVertex();
|
||||
tess.pos(this.verticesWithUV[0], this.verticesWithUV[1], this.verticesWithUV[2]).tex(u, v)
|
||||
.color(red, green, blue, this.particleAlpha).lightmap(BRIGHTNESS, BRIGHTNESS).endVertex();
|
||||
tess.pos(b[0], b[1], b[2]).tex(u, v).color(red, green, blue, this.particleAlpha)
|
||||
.lightmap(BRIGHTNESS, BRIGHTNESS).endVertex();
|
||||
}
|
||||
this.hasData = true;
|
||||
for (int x = 0; x < 3; x++) {
|
||||
this.vertices[x] = a[x];
|
||||
this.verticesWithUV[x] = b[x];
|
||||
}
|
||||
}
|
||||
|
||||
protected double[][] getPrecomputedSteps()
|
||||
{
|
||||
return this.precomputedSteps;
|
||||
}
|
||||
protected double[][] getPrecomputedSteps() {
|
||||
return this.precomputedSteps;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static class Factory implements IParticleFactory<BasicParticleType> {
|
||||
private final IAnimatedSprite spriteSet;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static class Factory implements IParticleFactory<BasicParticleType> {
|
||||
private final IAnimatedSprite spriteSet;
|
||||
|
||||
public Factory(IAnimatedSprite spriteSet) {
|
||||
this.spriteSet = spriteSet;
|
||||
}
|
||||
public Factory(IAnimatedSprite spriteSet) {
|
||||
this.spriteSet = spriteSet;
|
||||
}
|
||||
|
||||
public Particle makeParticle(BasicParticleType typeIn, World worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
|
||||
LightningFX lightningFX = new LightningFX(worldIn, x, y, z, xSpeed, ySpeed, zSpeed);
|
||||
lightningFX.selectSpriteRandomly(this.spriteSet);
|
||||
return lightningFX;
|
||||
}
|
||||
}
|
||||
public Particle makeParticle(BasicParticleType typeIn, World worldIn, double x, double y, double z,
|
||||
double xSpeed, double ySpeed, double zSpeed) {
|
||||
LightningFX lightningFX = new LightningFX(worldIn, x, y, z, xSpeed, ySpeed, zSpeed);
|
||||
lightningFX.selectSpriteRandomly(this.spriteSet);
|
||||
return lightningFX;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user