diff --git a/src/main/java/org/polyfrost/overflowparticles/hook/EntityFXHook.java b/src/main/java/org/polyfrost/overflowparticles/hook/EntityFXHook.java new file mode 100644 index 0000000..632a8fe --- /dev/null +++ b/src/main/java/org/polyfrost/overflowparticles/hook/EntityFXHook.java @@ -0,0 +1,6 @@ +package org.polyfrost.overflowparticles.hook; + +public interface EntityFXHook { + int overflowParticles$getParticleID(); + void overflowParticles$setParticleID(int id); +} diff --git a/src/main/java/org/polyfrost/overflowparticles/mixin/EffectRendererMixin.java b/src/main/java/org/polyfrost/overflowparticles/mixin/EffectRendererMixin.java index 0e36ad0..39f73ea 100644 --- a/src/main/java/org/polyfrost/overflowparticles/mixin/EffectRendererMixin.java +++ b/src/main/java/org/polyfrost/overflowparticles/mixin/EffectRendererMixin.java @@ -11,22 +11,16 @@ import org.polyfrost.overflowparticles.config.MainConfig; import org.polyfrost.overflowparticles.config.ModConfig; import org.polyfrost.overflowparticles.config.ParticleConfig; +import org.polyfrost.overflowparticles.utils.UtilKt; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.util.Collection; -import java.util.List; - @Mixin(EffectRenderer.class) public abstract class EffectRendererMixin { - @Shadow - private List[][] fxLayers; - @Unique private int overflowParticles$ID; @@ -84,49 +78,22 @@ private void spawn(int particleId, double xCoord, double yCoord, double zCoord, @ModifyArg(method = "spawnEffectParticle", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/EffectRenderer;addEffect(Lnet/minecraft/client/particle/EntityFX;)V", ordinal = 0)) private EntityFX spawn(EntityFX effect) { - put(effect, overflowParticles$ID); + UtilKt.setParticleEntityID(effect, overflowParticles$ID); return effect; } - @ModifyArg(method = "updateEffectAlphaLayer", at = @At(value = "INVOKE", target = "Ljava/util/List;removeAll(Ljava/util/Collection;)Z", ordinal = 0)) - private Collection update(Collection c) { - List list = c instanceof List ? (List) c : null; - if (list == null) return c; - for (EntityFX entityFX : list) { - remove(entityFX); - } - return c; - } - @Inject(method = "addEffect", at = @At("HEAD")) private void check(EntityFX effect, CallbackInfo ci) { if (effect instanceof EntityDiggingFX) { - put(effect, 37); + UtilKt.setParticleEntityID(effect, 37); } } - @Inject(method = "addEffect", at = @At(value = "INVOKE", target = "Ljava/util/List;remove(I)Ljava/lang/Object;")) - private void limit(EntityFX effect, CallbackInfo ci) { - int i = effect.getFXLayer(); - int j = effect.getAlpha() != 1.0F ? 0 : 1; - remove(this.fxLayers[i][j].get(0)); - } - @ModifyConstant(method = "addEffect", constant = @Constant(intValue = 4000)) private int changeMaxParticleLimit(int original) { return MainConfig.INSTANCE.getSettings().getMaxParticleLimit(); } - @Unique - private void remove(EntityFX entityFX) { - OverflowParticles.INSTANCE.getEntitiesCache().remove(entityFX.getEntityId()); - } - - @Unique - private void put(EntityFX entityFX, int id) { - OverflowParticles.INSTANCE.getEntitiesCache().put(entityFX.getEntityId(), id); - } - @Inject( method = { "addBlockHitEffects(Lnet/minecraft/util/BlockPos;Lnet/minecraft/util/EnumFacing;)V", diff --git a/src/main/java/org/polyfrost/overflowparticles/mixin/EntityFXMixin.java b/src/main/java/org/polyfrost/overflowparticles/mixin/EntityFXMixin.java index 0d722b2..8b4dbb3 100644 --- a/src/main/java/org/polyfrost/overflowparticles/mixin/EntityFXMixin.java +++ b/src/main/java/org/polyfrost/overflowparticles/mixin/EntityFXMixin.java @@ -4,12 +4,13 @@ import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.entity.Entity; import org.polyfrost.overflowparticles.config.*; +import org.polyfrost.overflowparticles.hook.EntityFXHook; import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = EntityFX.class, priority = 1001) // after particlesehanced -public abstract class EntityFXMixin { +public abstract class EntityFXMixin implements EntityFXHook { @Shadow protected float particleScale; @Shadow protected int particleAge; @@ -20,6 +21,7 @@ public abstract class EntityFXMixin { @Shadow protected int particleMaxAge; @Unique private float overflowParticles$scale; + @Unique private int overflowParticles$ID; @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) { @@ -49,4 +51,13 @@ private void reset(WorldRenderer worldRendererIn, Entity entityIn, float partial particleScale = overflowParticles$scale; } + @Override + public int overflowParticles$getParticleID() { + return overflowParticles$ID; + } + + @Override + public void overflowParticles$setParticleID(int id) { + overflowParticles$ID = id; + } } diff --git a/src/main/kotlin/org/polyfrost/overflowparticles/OverflowParticles.kt b/src/main/kotlin/org/polyfrost/overflowparticles/OverflowParticles.kt index 1f5f42c..fd815ae 100644 --- a/src/main/kotlin/org/polyfrost/overflowparticles/OverflowParticles.kt +++ b/src/main/kotlin/org/polyfrost/overflowparticles/OverflowParticles.kt @@ -6,7 +6,8 @@ import net.minecraft.util.EnumParticleTypes import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.event.FMLInitializationEvent -import org.polyfrost.overflowparticles.config.* +import org.polyfrost.overflowparticles.config.ModConfig +import org.polyfrost.overflowparticles.config.ParticleConfig import org.polyfrost.overflowparticles.utils.IconRenderer @Mod(modid = OverflowParticles.MODID, name = OverflowParticles.NAME, version = OverflowParticles.VERSION, modLanguageAdapter = "cc.polyfrost.oneconfig.utils.KotlinLanguageAdapter") @@ -23,8 +24,6 @@ object OverflowParticles { val names = listOf("Entity Death", "Large Explosion", "Huge Explosion", "Firework Spark", "Water Bubble", "Water Splash", "Water Wake", "Liquid", "Depth Suspended", "Critical", "Sharpness", "Smoke", "Large Smoke", "Splash Potion", "Instant Potion", "Potion", "Beacon Effect", "Witch Spell", "Water Drip", "Lava Drip", "Angry Villager", "Happy Villager", "Mycelium", "Note", "Portal", "Enchantment", "Flame", "Lava", "Footstep", "Cloud", "Redstone", "Snowball", "Shovel Snow", "Slime", "Heart", "Barrier", "Item Eat / Break", "Blocks", "Block Dust", "Rain Drop", "Item Pickup", "Mob Appearance") - var entitiesCache = HashMap() - val ignores = listOf(2, 32, 38, 40, 41) val unfair = listOf(28, 37) diff --git a/src/main/kotlin/org/polyfrost/overflowparticles/config/ModConfig.kt b/src/main/kotlin/org/polyfrost/overflowparticles/config/ModConfig.kt index 9907c1a..ab8aac7 100644 --- a/src/main/kotlin/org/polyfrost/overflowparticles/config/ModConfig.kt +++ b/src/main/kotlin/org/polyfrost/overflowparticles/config/ModConfig.kt @@ -8,6 +8,7 @@ import club.sk1er.patcher.config.OldPatcherConfig import dev.isxander.particlesenhanced.config.ParticlesEnhancedConfig import net.minecraft.client.particle.EntityFX import org.polyfrost.overflowparticles.OverflowParticles +import org.polyfrost.overflowparticles.hook.EntityFXHook import java.util.ArrayList object ModConfig : Config(Mod(OverflowParticles.NAME, ModType.UTIL_QOL, "/overflowparticles.svg"), "${OverflowParticles.MODID}.json") { @@ -19,8 +20,8 @@ object ModConfig : Config(Mod(OverflowParticles.NAME, ModType.UTIL_QOL, "/overfl var blockSetting = BlockParticleEntry() fun getConfig(entity: EntityFX?): ParticleConfig? { - val id = OverflowParticles.entitiesCache[entity?.entityId] ?: return null - return getConfigByID(id) + if (entity !is EntityFXHook) return null + return getConfigByID(entity.`overflowParticles$getParticleID`()) } fun getConfigByID(id: Int): ParticleConfig? { diff --git a/src/main/kotlin/org/polyfrost/overflowparticles/utils/Util.kt b/src/main/kotlin/org/polyfrost/overflowparticles/utils/Util.kt index 914e035..6a2ac96 100644 --- a/src/main/kotlin/org/polyfrost/overflowparticles/utils/Util.kt +++ b/src/main/kotlin/org/polyfrost/overflowparticles/utils/Util.kt @@ -1,8 +1,16 @@ package org.polyfrost.overflowparticles.utils +import net.minecraft.client.particle.EntityFX import net.minecraft.world.IWorldAccess import org.polyfrost.overflowparticles.config.MainConfig import org.polyfrost.overflowparticles.config.ParticleConfig +import org.polyfrost.overflowparticles.hook.EntityFXHook + +fun setParticleEntityID(entity: EntityFX, id: Int) { + if (entity is EntityFXHook) { + entity.`overflowParticles$setParticleID`(id) + } +} fun color(color: Int, targetColor: Float, cfg: ParticleConfig): Float = if (cfg.entry.customColor) color / 255f * if (cfg.entry.colorMode) 1f else targetColor else targetColor