From aac7ebf6dd11af83061405542579de67b68fccd4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 12 Feb 2019 18:32:03 -0800 Subject: [PATCH] avoid creating callbackinfo at all costs --- .../launch/mixins/MixinChunkRenderContainer.java | 14 +++++++++----- .../baritone/launch/mixins/MixinRenderList.java | 8 ++++---- .../baritone/launch/mixins/MixinVboRenderList.java | 8 ++++---- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java b/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java index fef16d6b4..511e1c143 100644 --- a/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java +++ b/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java @@ -22,27 +22,31 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ChunkRenderContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.chunk.RenderChunk; +import net.minecraft.util.math.BlockPos; import org.lwjgl.opengl.GL14; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.Redirect; import static org.lwjgl.opengl.GL11.*; @Mixin(ChunkRenderContainer.class) public class MixinChunkRenderContainer { - @Inject( + @Redirect( // avoid creating CallbackInfo at all costs; this is called 40k times per second method = "preRenderChunk", - at = @At("HEAD") + at = @At( + value = "INVOKE", + target = "net/minecraft/client/renderer/chunk/RenderChunk.getPosition()Lnet/minecraft/util/math/BlockPos;" + ) ) - private void preRenderChunk(RenderChunk renderChunkIn, CallbackInfo ci) { + private BlockPos getPosition(RenderChunk renderChunkIn) { if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().world.getChunk(renderChunkIn.getPosition()).isEmpty()) { GlStateManager.enableAlpha(); GlStateManager.enableBlend(); GL14.glBlendColor(0, 0, 0, Baritone.settings().cachedChunksOpacity.get()); GlStateManager.tryBlendFuncSeparate(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_ONE, GL_ZERO); } + return renderChunkIn.getPosition(); } } diff --git a/src/launch/java/baritone/launch/mixins/MixinRenderList.java b/src/launch/java/baritone/launch/mixins/MixinRenderList.java index 55d1da70a..3d4d8a910 100644 --- a/src/launch/java/baritone/launch/mixins/MixinRenderList.java +++ b/src/launch/java/baritone/launch/mixins/MixinRenderList.java @@ -22,25 +22,25 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderList; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.Redirect; import static org.lwjgl.opengl.GL11.*; @Mixin(RenderList.class) public class MixinRenderList { - @Inject( + @Redirect( // avoid creating CallbackInfo at all costs; this is called 40k times per second method = "renderChunkLayer", at = @At( value = "INVOKE", target = "net/minecraft/client/renderer/GlStateManager.popMatrix()V" ) ) - private void renderChunkLayer(CallbackInfo info) { + private void popMatrix() { if (Baritone.settings().renderCachedChunks.get()) { // reset the blend func to normal (not dependent on constant alpha) GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); } + GlStateManager.popMatrix(); } } diff --git a/src/launch/java/baritone/launch/mixins/MixinVboRenderList.java b/src/launch/java/baritone/launch/mixins/MixinVboRenderList.java index c2c9fd8c7..70048c8ca 100644 --- a/src/launch/java/baritone/launch/mixins/MixinVboRenderList.java +++ b/src/launch/java/baritone/launch/mixins/MixinVboRenderList.java @@ -22,25 +22,25 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.VboRenderList; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.Redirect; import static org.lwjgl.opengl.GL11.*; @Mixin(VboRenderList.class) public class MixinVboRenderList { - @Inject( + @Redirect( // avoid creating CallbackInfo at all costs; this is called 40k times per second method = "renderChunkLayer", at = @At( value = "INVOKE", target = "net/minecraft/client/renderer/GlStateManager.popMatrix()V" ) ) - private void renderChunkLayer(CallbackInfo info) { + private void popMatrix() { if (Baritone.settings().renderCachedChunks.get()) { // reset the blend func to normal (not dependent on constant alpha) GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); } + GlStateManager.popMatrix(); } }