diff --git a/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java b/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java index 286ca5d4..4a7830f5 100644 --- a/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java +++ b/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java @@ -18,11 +18,11 @@ package baritone.launch.mixins; import baritone.Baritone; +import baritone.utils.LeijurvUtils; 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 org.lwjgl.opengl.GL14; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -42,7 +42,7 @@ public class MixinChunkRenderContainer { if (Minecraft.getMinecraft().world.getChunk(renderChunkIn.getPosition()).isEmpty()) { GlStateManager.enableAlpha(); GlStateManager.enableBlend(); - GL14.glBlendColor(1, 1, 1, Baritone.settings().cachedChunksOpacity.get()); + LeijurvUtils.updateAndGet().run(); GlStateManager.tryBlendFuncSeparate(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_ONE, GL_ZERO); } else { GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); diff --git a/src/main/java/baritone/utils/LeijurvUtils.java b/src/main/java/baritone/utils/LeijurvUtils.java new file mode 100644 index 00000000..05aa65db --- /dev/null +++ b/src/main/java/baritone/utils/LeijurvUtils.java @@ -0,0 +1,85 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils; + +import baritone.Baritone; +import org.lwjgl.opengl.GL14; + +import java.lang.invoke.LambdaMetafactory; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +/** + * Is your name Leijurv and you have a severe handicap for X? Well, no worries! This class has YOU covered! + * + * @author Brady + * @since 1/30/2019 + */ +public class LeijurvUtils { + + private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); + + private static Runnable glBlendColorChunkOwnage = null; + private static float existingAlpha; + + public static Runnable updateAndGet() { + float currentAlpha = Baritone.settings().cachedChunksOpacity.get(); + if (glBlendColorChunkOwnage == null || existingAlpha != currentAlpha) { + glBlendColorChunkOwnage = createBlendColorRunnable(1, 1, 1, existingAlpha = currentAlpha); + } + return glBlendColorChunkOwnage; + } + + /** + * Hahhahaha + * WHY???? you may ask. well: + * + * basically proguard sucks (actually the gradle automated setup for it does) and I'm too + * lazy to actually make it work. (It is unable to recognize the GL14 class). This is an + * AWESOME workaround by creating a runnable for the {@code glBlendColor} method without having + * to directly reference the method itself with the added bonus of pre-filling the invocation arguments. + * + * @param r red + * @param g green + * @param b blue + * @param a alpha + * @return Epic runnable that calls {@link GL14#glBlendColor(float, float, float, float)} + */ + public static Runnable createBlendColorRunnable(float r, float g, float b, float a) { + try { + MethodHandle glBlendColor = LOOKUP.findStatic( + Class.forName("org.lwjgl.opengl.GL14"), + "glBlendColor", + MethodType.methodType(Void.TYPE, Float.TYPE, Float.TYPE, Float.TYPE, Float.TYPE) + ); + + // noinspection unchecked + return (Runnable) LambdaMetafactory.metafactory( + LOOKUP, + "run", + glBlendColor.type().changeReturnType(Runnable.class), + MethodType.methodType(Void.TYPE), + glBlendColor, + MethodType.methodType(Void.TYPE) + ).dynamicInvoker().invoke(r, g, b, a); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } +}