Fireflies, small fixes

This commit is contained in:
paulevsGitch 2021-01-19 20:06:51 +03:00
parent 1168ec55b0
commit 31163e7658
7 changed files with 97 additions and 0 deletions

View file

@ -0,0 +1,81 @@
package ru.betterend.particle;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.particle.AnimatedParticle;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleFactory;
import net.minecraft.client.particle.SpriteProvider;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.DefaultParticleType;
import net.minecraft.util.math.MathHelper;
import ru.betterend.util.MHelper;
@Environment(EnvType.CLIENT)
public class FireflyParticle extends AnimatedParticle {
private double preVX;
private double preVY;
private double preVZ;
private double nextVX;
private double nextVY;
private double nextVZ;
protected FireflyParticle(ClientWorld world, double x, double y, double z, SpriteProvider sprites, double r, double g, double b) {
super(world, x, y, z, sprites, 0);
setSprite(sprites.getSprite(random));
this.maxAge = MHelper.randRange(150, 300, random);
this.scale = MHelper.randRange(0.05F, 0.15F, random);
this.setTargetColor(15916745);
this.setSpriteForAge(spriteProvider);
this.setColorAlpha(0);
preVX = random.nextGaussian() * 0.02;
preVY = random.nextGaussian() * 0.02;
preVZ = random.nextGaussian() * 0.02;
nextVX = random.nextGaussian() * 0.02;
nextVY = random.nextGaussian() * 0.02;
nextVZ = random.nextGaussian() * 0.02;
}
@Override
public void tick() {
int ticks = this.age & 31;
if (ticks == 0) {
preVX = nextVX;
preVY = nextVY;
preVZ = nextVZ;
nextVX = random.nextGaussian() * 0.02;
nextVY = random.nextGaussian() * 0.02;
nextVZ = random.nextGaussian() * 0.02;
}
double delta = (double) ticks / 31.0;
this.velocityX = MathHelper.lerp(delta, preVX, nextVX);
this.velocityY = MathHelper.lerp(delta, preVY, nextVY);
this.velocityZ = MathHelper.lerp(delta, preVZ, nextVZ);
if (this.age <= 60) {
this.setColorAlpha(this.age / 60F);
}
else if (this.age > maxAge - 60) {
this.setColorAlpha((maxAge - this.age) / 60F);
}
super.tick();
}
@Environment(EnvType.CLIENT)
public static class FireflyParticleFactory implements ParticleFactory<DefaultParticleType> {
private final SpriteProvider sprites;
public FireflyParticleFactory(SpriteProvider sprites) {
this.sprites = sprites;
}
@Override
public Particle createParticle(DefaultParticleType type, ClientWorld world, double x, double y, double z, double vX, double vY, double vZ) {
return new FireflyParticle(world, x, y, z, sprites, 1, 1, 1);
}
}
}