Files
Explosion-Overhaul/src/main/java/com/vinlanx/explosionoverhaul/client/SmokeParticle.java

72 lines
2.8 KiB
Java
Raw Normal View History

2026-05-04 12:09:37 +02:00
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;
2026-05-09 12:14:16 +02:00
import net.minecraft.util.Mth;
2026-05-04 12:09:37 +02:00
public class SmokeParticle extends TextureSheetParticle {
2026-05-09 12:14:16 +02:00
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);
2026-05-09 12:14:16 +02:00
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);
2026-05-09 12:14:16 +02:00
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);
2026-05-04 12:09:37 +02:00
}
@Override
public ParticleRenderType getRenderType() {
return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
2026-05-04 12:09:37 +02:00
}
public boolean shouldCull() {
return false;
}
2026-05-09 12:14:16 +02:00
@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));
2026-05-09 12:14:16 +02:00
this.alpha = this.startAlpha * Mth.clamp(1.0f - progress, 0.0f, 1.0f);
}
public static class Provider implements ParticleProvider<SmokeParticleOptions> {
2026-05-04 12:09:37 +02:00
private final SpriteSet sprites;
public Provider(SpriteSet sprites) {
this.sprites = sprites;
2026-05-04 12:09:37 +02:00
}
@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);
2026-05-04 12:09:37 +02:00
}
}
}