From b177ae7ee6494705257ebc6bbeebef89b635aad4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 30 Jan 2019 11:57:54 -0800 Subject: [PATCH] proguard can just ignore GL14 reference actually --- scripts/proguard.pro | 3 + .../mixins/MixinChunkRenderContainer.java | 4 +- .../java/baritone/utils/LeijurvUtils.java | 85 ------------------- 3 files changed, 5 insertions(+), 87 deletions(-) delete mode 100644 src/main/java/baritone/utils/LeijurvUtils.java diff --git a/scripts/proguard.pro b/scripts/proguard.pro index 07e1ec41..df6ad43a 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -12,6 +12,9 @@ -flattenpackagehierarchy -repackageclasses 'baritone' +# lwjgl is weird +-dontwarn org.lwjgl.opengl.GL14 + -keep class baritone.api.** { *; } # this is the keep api # service provider needs these class names diff --git a/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java b/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java index 4a7830f5..e2c1e025 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(); - LeijurvUtils.updateAndGet().run(); + GL14.glBlendColor(0, 0, 0, Baritone.settings().cachedChunksOpacity.get()); 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 deleted file mode 100644 index 05aa65db..00000000 --- a/src/main/java/baritone/utils/LeijurvUtils.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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); - } - } -}