Skip to content

Commit

Permalink
Replace caching system with storing id in EntityFX class
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Jun 22, 2024
1 parent 56ee085 commit 2d6e184
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.polyfrost.overflowparticles.hook;

public interface EntityFXHook {
int overflowParticles$getParticleID();
void overflowParticles$setParticleID(int id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntityFX>[][] fxLayers;

@Unique
private int overflowParticles$ID;

Expand Down Expand Up @@ -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<EntityFX> list = c instanceof List ? (List<EntityFX>) 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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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<Int, Int>()

val ignores = listOf(2, 32, 38, 40, 41)

val unfair = listOf(28, 37)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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? {
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/org/polyfrost/overflowparticles/utils/Util.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2d6e184

Please sign in to comment.