diff --git a/src/main/java/org/polyfrost/overflowparticles/mixin/EntityFXMixin.java b/src/main/java/org/polyfrost/overflowparticles/mixin/EntityFXMixin.java index e46552e..c0b8bf2 100644 --- a/src/main/java/org/polyfrost/overflowparticles/mixin/EntityFXMixin.java +++ b/src/main/java/org/polyfrost/overflowparticles/mixin/EntityFXMixin.java @@ -9,22 +9,38 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(EntityFX.class) -public class EntityFXMixin { +public abstract class EntityFXMixin { @Shadow protected float particleScale; - @Unique private float scale; + @Shadow protected int particleAge; + + @Shadow public abstract float getAlpha(); + + @Shadow public abstract void setAlphaF(float alpha); + + @Shadow protected int particleMaxAge; + @Unique private float overflowParticles$scale; @Inject(method = "renderParticle", at = @At(value = "HEAD")) private void setScale(WorldRenderer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ, CallbackInfo ci) { - scale = particleScale; + overflowParticles$scale = particleScale; ParticleConfig config = ModConfig.INSTANCE.getConfig((EntityFX) (Object) this); if (config == null) return; - particleScale *= config.getEntry().getSize(); + ParticleEntry entry = config.getEntry(); + particleScale *= entry.getSize(); + int id = entry.getID(); + + float age = (float) particleAge / particleMaxAge; + if ((id != 0 && id != 1 && id != 2 && id != 3 && id != 100) // fireworks + && entry.getFade() && age > entry.getFadeStart()) { + float alpha = 1 - age + entry.getFadeStart(); + if (getAlpha() != alpha) setAlphaF(alpha); + } } - @Inject(method = "renderParticle", at = @At(value = "TAIL")) + @Inject(method = "renderParticle", at = @At(value = "RETURN")) private void reset(WorldRenderer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ, CallbackInfo ci) { - particleScale = scale; + particleScale = overflowParticles$scale; } } diff --git a/src/main/kotlin/org/polyfrost/overflowparticles/config/ParticleConfig.kt b/src/main/kotlin/org/polyfrost/overflowparticles/config/ParticleConfig.kt index 66a5be5..1bcf501 100644 --- a/src/main/kotlin/org/polyfrost/overflowparticles/config/ParticleConfig.kt +++ b/src/main/kotlin/org/polyfrost/overflowparticles/config/ParticleConfig.kt @@ -25,6 +25,10 @@ class ParticleConfig(val name: String, val id: Int) : SubConfig(name, "") { for (i in colors) { hideIf(i) { id == 28 } } + val fades = listOf("fade", "fadeStart") + for (i in fades) { + hideIf(i) { id == 0 || id == 1 || id == 2 || id == 3 } + } } override fun reInitialize() { diff --git a/src/main/kotlin/org/polyfrost/overflowparticles/config/ParticleEntry.kt b/src/main/kotlin/org/polyfrost/overflowparticles/config/ParticleEntry.kt index 570b36d..c9dbfb1 100644 --- a/src/main/kotlin/org/polyfrost/overflowparticles/config/ParticleEntry.kt +++ b/src/main/kotlin/org/polyfrost/overflowparticles/config/ParticleEntry.kt @@ -1,7 +1,8 @@ package org.polyfrost.overflowparticles.config import cc.polyfrost.oneconfig.config.annotations.* -import cc.polyfrost.oneconfig.config.core.* +import cc.polyfrost.oneconfig.config.core.ConfigUtils +import cc.polyfrost.oneconfig.config.core.OneColor import org.polyfrost.overflowparticles.OverflowParticles class ParticleEntry { @@ -17,6 +18,12 @@ class ParticleEntry { @Color(name = "Color") var color = OneColor(255, 255, 255, 255) + @Switch(name = "Fade", description = "Make particles fade rather than just disappearing.") + var fade = true + + @Slider(name = "Fade Out Start", description = "How far into the lifespan of the particle before it starts to fade.", max = 1F, min = 0F) + var fadeStart = 0.5f + @Slider(name = "Size", min = 0.5f, max = 5f) var size = 1.0f get() = field.coerceIn(0f, 5f)