1
0
mirror of https://github.com/cabaletta/baritone synced 2024-12-18 13:15:13 +00:00

avoid creating callbackinfo at all costs

This commit is contained in:
Leijurv 2019-02-12 18:32:03 -08:00
parent 8d481ba394
commit aac7ebf6dd
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 17 additions and 13 deletions

View File

@ -22,27 +22,31 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ChunkRenderContainer; import net.minecraft.client.renderer.ChunkRenderContainer;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.chunk.RenderChunk; import net.minecraft.client.renderer.chunk.RenderChunk;
import net.minecraft.util.math.BlockPos;
import org.lwjgl.opengl.GL14; import org.lwjgl.opengl.GL14;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
@Mixin(ChunkRenderContainer.class) @Mixin(ChunkRenderContainer.class)
public class MixinChunkRenderContainer { public class MixinChunkRenderContainer {
@Inject( @Redirect( // avoid creating CallbackInfo at all costs; this is called 40k times per second
method = "preRenderChunk", 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()) { if (Baritone.settings().renderCachedChunks.get() && Minecraft.getMinecraft().world.getChunk(renderChunkIn.getPosition()).isEmpty()) {
GlStateManager.enableAlpha(); GlStateManager.enableAlpha();
GlStateManager.enableBlend(); GlStateManager.enableBlend();
GL14.glBlendColor(0, 0, 0, Baritone.settings().cachedChunksOpacity.get()); GL14.glBlendColor(0, 0, 0, Baritone.settings().cachedChunksOpacity.get());
GlStateManager.tryBlendFuncSeparate(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_ONE, GL_ZERO); GlStateManager.tryBlendFuncSeparate(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_ONE, GL_ZERO);
} }
return renderChunkIn.getPosition();
} }
} }

View File

@ -22,25 +22,25 @@ import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderList; import net.minecraft.client.renderer.RenderList;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
@Mixin(RenderList.class) @Mixin(RenderList.class)
public class MixinRenderList { public class MixinRenderList {
@Inject( @Redirect( // avoid creating CallbackInfo at all costs; this is called 40k times per second
method = "renderChunkLayer", method = "renderChunkLayer",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "net/minecraft/client/renderer/GlStateManager.popMatrix()V" target = "net/minecraft/client/renderer/GlStateManager.popMatrix()V"
) )
) )
private void renderChunkLayer(CallbackInfo info) { private void popMatrix() {
if (Baritone.settings().renderCachedChunks.get()) { if (Baritone.settings().renderCachedChunks.get()) {
// reset the blend func to normal (not dependent on constant alpha) // 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.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
} }
GlStateManager.popMatrix();
} }
} }

View File

@ -22,25 +22,25 @@ import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.VboRenderList; import net.minecraft.client.renderer.VboRenderList;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
@Mixin(VboRenderList.class) @Mixin(VboRenderList.class)
public class MixinVboRenderList { public class MixinVboRenderList {
@Inject( @Redirect( // avoid creating CallbackInfo at all costs; this is called 40k times per second
method = "renderChunkLayer", method = "renderChunkLayer",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "net/minecraft/client/renderer/GlStateManager.popMatrix()V" target = "net/minecraft/client/renderer/GlStateManager.popMatrix()V"
) )
) )
private void renderChunkLayer(CallbackInfo info) { private void popMatrix() {
if (Baritone.settings().renderCachedChunks.get()) { if (Baritone.settings().renderCachedChunks.get()) {
// reset the blend func to normal (not dependent on constant alpha) // 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.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
} }
GlStateManager.popMatrix();
} }
} }