Restore explosion particle modes
Some checks failed
Build / build (push) Failing after 6m16s

This commit is contained in:
MrSphay
2026-05-09 12:14:16 +02:00
parent 1859e69b01
commit 85253f55db
8 changed files with 297 additions and 14 deletions

View File

@@ -0,0 +1,23 @@
package com.vinlanx.explosionoverhaul.client;
import com.vinlanx.explosionoverhaul.ExplosionOverhaul;
import com.vinlanx.explosionoverhaul.ModParticles;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent;
@EventBusSubscriber(modid = ExplosionOverhaul.MODID, value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD)
public final class ClientParticleEvents {
private ClientParticleEvents() {
}
@SubscribeEvent
public static void registerParticleProviders(RegisterParticleProvidersEvent event) {
event.registerSpriteSet(ModParticles.CUSTOM_GLOW.get(), CustomGlowParticleProvider::new);
event.registerSpriteSet(ModParticles.PLASMA.get(), PlasmaParticle.Provider::new);
event.registerSpriteSet(ModParticles.CUSTOM_SMOKE.get(), SmokeParticle.Provider::new);
event.registerSpriteSet(ModParticles.LINE_SPARK.get(), LineSparkParticleProvider::new);
ExplosionOverhaul.LOGGER.info("Registered Explosion Overhaul particle providers.");
}
}

View File

@@ -1,18 +1,78 @@
package com.vinlanx.explosionoverhaul.client;
import com.vinlanx.explosionoverhaul.Config;
import com.vinlanx.explosionoverhaul.CustomGlowParticleOptions;
import net.minecraft.client.multiplayer.ClientLevel;
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 CustomGlowParticle extends TextureSheetParticle {
public CustomGlowParticle(ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, CustomGlowParticleOptions options) {
private final SpriteSet sprites;
private final float baseSize;
public CustomGlowParticle(ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, CustomGlowParticleOptions options, SpriteSet sprites) {
super(level, x, y, z, xSpeed, ySpeed, zSpeed);
this.lifetime = 1;
this.sprites = sprites;
Config.Client.ParticleRenderMode mode = Config.CLIENT.particleRenderMode.get();
float configScale = ((Double)Config.CLIENT.particleSizeScale.get()).floatValue();
float powerScale = Mth.clamp(options.getPower() / 4.0f, 0.8f, 4.0f);
this.baseSize = options.getScale() * configScale * powerScale * (0.85f + this.random.nextFloat() * 0.35f);
this.lifetime = switch (mode) {
case REALISTIC -> 34 + this.random.nextInt(15);
case REALISTIC_2 -> 44 + this.random.nextInt(22);
case VANILA -> 22 + this.random.nextInt(12);
};
this.quadSize = this.baseSize;
this.friction = 0.88f;
this.gravity = mode == Config.Client.ParticleRenderMode.VANILA ? -0.01f : -0.018f;
this.hasPhysics = false;
this.xd = xSpeed * 0.85;
this.yd = ySpeed * 0.85 + 0.01;
this.zd = zSpeed * 0.85;
this.alpha = 0.92f;
this.pickSprite(sprites);
applyModeColor(mode, options.getZone());
}
@Override
public ParticleRenderType getRenderType() {
return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
}
@Override
public void tick() {
super.tick();
if (this.age >= this.lifetime) {
return;
}
float progress = this.age / (float)this.lifetime;
this.setSpriteFromAge(this.sprites);
this.alpha = Mth.clamp(1.0f - progress, 0.0f, 1.0f) * 0.92f;
this.quadSize = this.baseSize * (0.8f + progress * 1.8f);
}
@Override
public boolean shouldCull() {
return false;
}
private void applyModeColor(Config.Client.ParticleRenderMode mode, int zone) {
if (mode == Config.Client.ParticleRenderMode.VANILA) {
this.rCol = zone == 0 ? 1.0f : 0.95f;
this.gCol = zone == 0 ? 0.55f : 0.72f;
this.bCol = zone == 0 ? 0.15f : 0.3f;
return;
}
if (mode == Config.Client.ParticleRenderMode.REALISTIC_2) {
this.rCol = zone == 0 ? 1.0f : 0.82f;
this.gCol = zone == 0 ? 0.76f : 0.92f;
this.bCol = zone == 0 ? 0.42f : 1.0f;
return;
}
this.rCol = zone == 0 ? 1.0f : 1.0f;
this.gCol = zone == 0 ? 0.48f : 0.72f;
this.bCol = zone == 0 ? 0.08f : 0.2f;
}
}

View File

@@ -12,10 +12,13 @@ import net.minecraft.client.particle.SpriteSet;
public class CustomGlowParticleProvider
implements ParticleProvider<CustomGlowParticleOptions> {
private final SpriteSet sprites;
public CustomGlowParticleProvider(SpriteSet pSprites) {
this.sprites = pSprites;
}
public Particle createParticle(CustomGlowParticleOptions options, ClientLevel pLevel, double pX, double pY, double pZ, double pXSpeed, double pYSpeed, double pZSpeed) {
return new CustomGlowParticle(pLevel, pX, pY, pZ, pXSpeed, pYSpeed, pZSpeed, options);
return new CustomGlowParticle(pLevel, pX, pY, pZ, pXSpeed, pYSpeed, pZSpeed, options, this.sprites);
}
}

View File

@@ -4,15 +4,40 @@ import net.minecraft.client.multiplayer.ClientLevel;
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 LineSparkParticle extends TextureSheetParticle {
private final SpriteSet sprites;
public LineSparkParticle(ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, SpriteSet sprites) {
super(level, x, y, z, xSpeed, ySpeed, zSpeed);
this.setSpriteFromAge(sprites);
this.sprites = sprites;
this.lifetime = 6 + this.random.nextInt(8);
this.quadSize = 0.12f + this.random.nextFloat() * 0.18f;
this.rCol = 1.0f;
this.gCol = 0.8f;
this.bCol = 0.35f;
this.alpha = 1.0f;
this.friction = 0.76f;
this.gravity = 0.08f;
this.xd = xSpeed;
this.yd = ySpeed;
this.zd = zSpeed;
this.setSpriteFromAge(this.sprites);
}
@Override
public ParticleRenderType getRenderType() {
return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
}
@Override
public void tick() {
super.tick();
if (this.age >= this.lifetime) {
return;
}
this.setSpriteFromAge(this.sprites);
this.alpha = Mth.clamp(1.0f - this.age / (float)this.lifetime, 0.0f, 1.0f);
}
}

View File

@@ -7,11 +7,28 @@ 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 PlasmaParticle extends TextureSheetParticle {
private final SpriteSet sprites;
private final float startSize;
protected PlasmaParticle(ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, PlasmaParticleOptions options, SpriteSet sprites) {
super(level, x, y, z, xSpeed, ySpeed, zSpeed);
this.lifetime = 1;
this.sprites = sprites;
this.lifetime = 10 + this.random.nextInt(10);
this.startSize = Mth.clamp(options.getPower() / 8.0f, 0.45f, 2.8f);
this.quadSize = this.startSize;
this.rCol = 1.0f;
this.gCol = 0.74f + this.random.nextFloat() * 0.22f;
this.bCol = 0.18f;
this.alpha = 1.0f;
this.friction = 0.82f;
this.gravity = 0.02f;
this.hasPhysics = true;
this.xd = xSpeed;
this.yd = ySpeed;
this.zd = zSpeed;
this.pickSprite(sprites);
}
@@ -20,6 +37,18 @@ public class PlasmaParticle extends TextureSheetParticle {
return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
}
@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 = this.startSize * (1.0f - progress * 0.65f);
this.alpha = Mth.clamp(1.0f - progress, 0.0f, 1.0f);
}
public static class Provider implements ParticleProvider<PlasmaParticleOptions> {
private final SpriteSet sprites;

View File

@@ -7,11 +7,30 @@ 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.lifetime = 1;
this.sprites = sprites;
this.lifetime = Math.max(6, options.getLifetime());
this.startSize = options.getScale() * (options.isHeavy() ? 1.45f : 1.0f);
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);
}
@@ -24,6 +43,18 @@ public class SmokeParticle extends TextureSheetParticle {
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 = this.startSize * (1.0f + progress * 1.6f);
this.alpha = this.startAlpha * Mth.clamp(1.0f - progress, 0.0f, 1.0f);
}
public static class Provider implements ParticleProvider<SmokeParticleOptions> {
private final SpriteSet sprites;