Files
Explosion-Overhaul/src/main/java/com/vinlanx/explosionoverhaul/client/SmokeParticle.java
MrSphay 77a55286b8
All checks were successful
Build / build (push) Successful in 9m32s
Restore instant crater debris and glow sprites
2026-05-09 16:46:14 +02:00

72 lines
2.8 KiB
Java

package com.vinlanx.explosionoverhaul.client;
import com.vinlanx.explosionoverhaul.SmokeParticleOptions;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleProvider;
import net.minecraft.client.particle.ParticleRenderType;
import net.minecraft.client.particle.SpriteSet;
import net.minecraft.client.particle.TextureSheetParticle;
import net.minecraft.util.Mth;
public class SmokeParticle extends TextureSheetParticle {
private final SpriteSet sprites;
private final float startSize;
private final float startAlpha;
protected SmokeParticle(ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, SmokeParticleOptions options, SpriteSet sprites) {
super(level, x, y, z, xSpeed, ySpeed, zSpeed);
this.sprites = sprites;
this.lifetime = Math.max(6, options.getLifetime());
float requestedSize = options.getScale() * (options.isHeavy() ? 1.25f : 1.0f);
this.startSize = Mth.clamp(requestedSize, 0.12f, options.isHeavy() ? 8.0f : 5.5f);
this.startAlpha = options.getAlpha();
this.quadSize = this.startSize;
this.rCol = options.getRed();
this.gCol = options.getGreen();
this.bCol = options.getBlue();
this.alpha = this.startAlpha;
this.friction = options.isHeavy() ? 0.94f : 0.9f;
this.gravity = options.isHeavy() ? -0.004f : -0.012f;
this.hasPhysics = false;
this.xd = xSpeed + options.getWindSpeed() * 0.02;
this.yd = ySpeed + 0.008 + options.getHeightPercent() * 0.01;
this.zd = zSpeed;
this.pickSprite(sprites);
}
@Override
public ParticleRenderType getRenderType() {
return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
}
public boolean shouldCull() {
return false;
}
@Override
public void tick() {
super.tick();
if (this.age >= this.lifetime) {
return;
}
float progress = this.age / (float)this.lifetime;
this.setSpriteFromAge(this.sprites);
this.quadSize = Math.min(this.startSize + 5.5f, this.startSize * (1.0f + progress * 1.25f));
this.alpha = this.startAlpha * Mth.clamp(1.0f - progress, 0.0f, 1.0f);
}
public static class Provider implements ParticleProvider<SmokeParticleOptions> {
private final SpriteSet sprites;
public Provider(SpriteSet sprites) {
this.sprites = sprites;
}
@Override
public Particle createParticle(SmokeParticleOptions options, ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
return new SmokeParticle(level, x, y, z, xSpeed, ySpeed, zSpeed, options, this.sprites);
}
}
}