diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-12-29 03:32:04 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-12-29 03:32:04 +0100 |
commit | 226c1783c0214b62c3aeecb7f1372a8baf6e4a83 (patch) | |
tree | 0de7a369d01812c0b54712389a8dde12f8770d17 /src/main/java/at/hannibal2/skyhanni | |
parent | 628791fab1c0878c221301579978097f3928d793 (diff) | |
download | skyhanni-226c1783c0214b62c3aeecb7f1372a8baf6e4a83.tar.gz skyhanni-226c1783c0214b62c3aeecb7f1372a8baf6e4a83.tar.bz2 skyhanni-226c1783c0214b62c3aeecb7f1372a8baf6e4a83.zip |
optimize CheckRenderEntityEvent and RenderItemTipEvent
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-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); } } |