Skip to content

Commit

Permalink
add fade feature to particles
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Jun 21, 2024
1 parent 18750b9 commit 935d01b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 935d01b

Please sign in to comment.