diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/mixins/hooks/RenderManagerHook.kt | 25 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderManager.java | 23 |
2 files changed, 20 insertions, 28 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/RenderManagerHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/RenderManagerHook.kt deleted file mode 100644 index 3e3283662..000000000 --- a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/RenderManagerHook.kt +++ /dev/null @@ -1,25 +0,0 @@ -package at.hannibal2.skyhanni.mixins.hooks - -import at.hannibal2.skyhanni.events.CheckRenderEntityEvent -import net.minecraft.client.renderer.culling.ICamera -import net.minecraft.entity.Entity -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable - -fun shouldRender( - entityIn: Entity, - camera: ICamera, - camX: Double, - camY: Double, - camZ: Double, - cir: CallbackInfoReturnable<Boolean> -) { - if ( - CheckRenderEntityEvent( - entityIn, - camera, - camX, - camY, - camZ - ).postAndCatch() - ) cir.returnValue = false -}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderManager.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderManager.java index e36b87195..1085f6c7f 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderManager.java +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderManager.java @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.mixins.transformers; -import at.hannibal2.skyhanni.mixins.hooks.RenderManagerHookKt; +import at.hannibal2.skyhanni.events.CheckRenderEntityEvent; import net.minecraft.client.renderer.culling.ICamera; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.entity.Entity; @@ -9,11 +9,28 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.HashMap; +import java.util.UUID; + @Mixin(RenderManager.class) public class MixinRenderManager { + private final HashMap<UUID, Long> lastColorCacheTime = new HashMap<>(); + private final HashMap<UUID, Boolean> cache = new HashMap<>(); + @Inject(method = "shouldRender", at = @At("HEAD"), cancellable = true) - private void shouldRender(Entity entityIn, ICamera camera, double camX, double camY, double camZ, CallbackInfoReturnable<Boolean> cir) { - RenderManagerHookKt.shouldRender(entityIn, camera, camX, camY, camZ, cir); + private void shouldRender(Entity entity, ICamera camera, double camX, double camY, double camZ, CallbackInfoReturnable<Boolean> cir) { + UUID uuid = entity.getUniqueID(); + boolean shouldRender; + if (lastColorCacheTime.getOrDefault(uuid, 0L) + 1_000 > System.currentTimeMillis()) { + shouldRender = cache.get(uuid); + } else { + shouldRender = !new CheckRenderEntityEvent<>(entity, camera, camX, camY, camZ).postAndCatch(); + + cache.put(uuid, shouldRender); + lastColorCacheTime.put(uuid, System.currentTimeMillis()); + } + + cir.setReturnValue(shouldRender); } } |