diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinRendererLivingEntity.java | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinRendererLivingEntity.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinRendererLivingEntity.java index 657636e87..5161d55da 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinRendererLivingEntity.java +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinRendererLivingEntity.java @@ -13,23 +13,75 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.HashMap; +import java.util.UUID; + +//TODO make guava caches working @Mixin(RendererLivingEntity.class) public abstract class MixinRendererLivingEntity<T extends EntityLivingBase> extends Render<T> { + + private final HashMap<UUID, Long> lastColorCacheTime = new HashMap<>(); + private final HashMap<UUID, Integer> cachedColor = new HashMap<>(); + + private final HashMap<UUID, Long> lastHurtCacheTime = new HashMap<>(); + private final HashMap<UUID, Boolean> cachedHurt = new HashMap<>(); + + // private final LoadingCache<EntityLivingBase, Integer> colorMultiplier; protected MixinRendererLivingEntity(RenderManager renderManager) { super(renderManager); + +// colorMultiplier = CacheBuilder.newBuilder() +//// .maximumSize(1000) +// .expireAfterWrite(2, TimeUnit.SECONDS) +// .build( +// new CacheLoader<EntityLivingBase, Integer>() { +// @Override +// public Integer load(@NotNull EntityLivingBase key) { +// RenderMobColoredEvent event = new RenderMobColoredEvent(key, 0); +// event.postAndCatch(); +// return event.getColor(); +// } +// } +// ); } @Inject(method = "getColorMultiplier", at = @At("HEAD"), cancellable = true) private void setColorMultiplier(T entity, float lightBrightness, float partialTickTime, CallbackInfoReturnable<Integer> cir) { + UUID uuid = entity.getUniqueID(); + if (lastColorCacheTime.getOrDefault(uuid, 0L) + 1_000 > System.currentTimeMillis()) { + cir.setReturnValue(cachedColor.get(uuid)); + return; + } + RenderMobColoredEvent event = new RenderMobColoredEvent(entity, 0); event.postAndCatch(); - cir.setReturnValue(event.getColor()); + int color = event.getColor(); + cachedColor.put(uuid, color); + lastColorCacheTime.put(uuid, System.currentTimeMillis()); + cir.setReturnValue(color); + +// try { +// cir.setReturnValue(colorMultiplier.get(entity)); +// } catch (ExecutionException e) { +// throw new RuntimeException(e); +// } } @Redirect(method = "setBrightness", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/EntityLivingBase;hurtTime:I", opcode = Opcodes.GETFIELD)) private int changeHurtTime(EntityLivingBase entity) { - ResetEntityHurtEvent event = new ResetEntityHurtEvent(entity, false); - event.postAndCatch(); - return event.getShouldReset() ? 0 : entity.hurtTime; + UUID uuid = entity.getUniqueID(); + + boolean shouldReset; + if (lastHurtCacheTime.getOrDefault(uuid, 0L) + 1_000 > System.currentTimeMillis()) { + shouldReset = cachedHurt.get(uuid); + } else { + ResetEntityHurtEvent event = new ResetEntityHurtEvent(entity, false); + event.postAndCatch(); + shouldReset = event.getShouldReset(); + cachedHurt.put(uuid, shouldReset); + lastHurtCacheTime.put(uuid, System.currentTimeMillis()); + } + + return shouldReset ? 0 : entity.hurtTime; } }
\ No newline at end of file |