proguard can just ignore GL14 reference actually

This commit is contained in:
Leijurv 2019-01-30 11:57:54 -08:00
parent 8947eff3b1
commit b177ae7ee6
No account linked to committer's email address
3 changed files with 5 additions and 87 deletions

View File

@ -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

View File

@ -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);

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}
}