Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPLE and OptiFine compatibility #43

Merged
merged 11 commits into from
Jan 8, 2024
3 changes: 3 additions & 0 deletions project.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ repositories {

dependencies {
compileOnly("com.falsepattern:triangulator-mc1.7.10:1.7.0:api")

compileOnly("com.falsepattern:rple-mc1.7.10:1.0.0-rc8:api")
compileOnly("com.falsepattern:falsetweaks-mc1.7.10:2.7.4:api")
}

runClient {
Expand Down
67 changes: 43 additions & 24 deletions src/main/java/makamys/neodymium/Compat.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package makamys.neodymium;

import static makamys.neodymium.Constants.LOGGER;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;

import org.lwjgl.opengl.GLContext;

import com.falsepattern.triangulator.api.ToggleableTessellator;
import cpw.mods.fml.common.Loader;
import makamys.neodymium.config.Config;
import makamys.neodymium.util.OFUtil;
import makamys.neodymium.util.virtualjar.IVirtualJar;
import makamys.neodymium.util.virtualjar.VirtualJar;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.settings.GameSettings;
import org.lwjgl.opengl.GLContext;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;

import static makamys.neodymium.Constants.LOGGER;

public class Compat {

Expand All @@ -26,7 +24,11 @@ public class Compat {

private static int notEnoughVRAMAmountMB = -1;

private static boolean RPLE;
private static boolean IS_RPLE_PRESENT;

private static boolean IS_FALSE_TWEAKS_PRESENT;

private static boolean isShadersEnabled;

public static void init() {
isGL33Supported = GLContext.getCapabilities().OpenGL33;
Expand All @@ -36,36 +38,53 @@ public static void init() {
}

if (Loader.isModLoaded("rple")) {
RPLE = true;
IS_RPLE_PRESENT = true;
}

if (Loader.isModLoaded("falsetweaks")) {
IS_FALSE_TWEAKS_PRESENT = true;
}
}

public static boolean RPLE() {
return RPLE;
public static boolean isRPLEModPresent() {
return IS_RPLE_PRESENT;
}

private static void disableTriangulator() {
((ToggleableTessellator)Tessellator.instance).disableTriangulator();
public static boolean isFalseTweaksModPresent() {
return IS_FALSE_TWEAKS_PRESENT;
}

public static void getCompatibilityWarnings(List<Warning> warns, List<Warning> criticalWarns, boolean statusCommand){
if(Minecraft.getMinecraft().gameSettings.advancedOpengl) {
warns.add(new Warning("Advanced OpenGL is enabled, performance may be poor." + (statusCommand ? " Click here to disable it." : "")).chatAction("neodymium disable_advanced_opengl"));
}



public static boolean isOptiFineShadersEnabled() {
return isShadersEnabled;
}

public static void updateOptiFineShadersState() {
try {
Class<?> shaders = Class.forName("shadersmod.client.Shaders");
try {
String shaderPack = (String)shaders.getMethod("getShaderPackName").invoke(null);
if(shaderPack != null) {
criticalWarns.add(new Warning("A shader pack is enabled, this is not supported."));
isShadersEnabled = true;
return;
}
} catch(Exception e) {
LOGGER.warn("Failed to get shader pack name");
e.printStackTrace();
}
} catch (ClassNotFoundException e) {


}
isShadersEnabled = false;
}

private static void disableTriangulator() {
((ToggleableTessellator)Tessellator.instance).disableTriangulator();
}

public static void getCompatibilityWarnings(List<Warning> warns, List<Warning> criticalWarns, boolean statusCommand){
if(Minecraft.getMinecraft().gameSettings.advancedOpengl) {
warns.add(new Warning("Advanced OpenGL is enabled, performance may be poor." + (statusCommand ? " Click here to disable it." : "")).chatAction("neodymium disable_advanced_opengl"));
}

if(!isGL33Supported) {
Expand Down Expand Up @@ -118,7 +137,7 @@ public static boolean disableAdvancedOpenGL() {
}
return false;
}

private static class OptiFineStubVirtualJar implements IVirtualJar {

@Override
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/makamys/neodymium/Neodymium.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import java.util.ArrayList;
import java.util.List;

import makamys.neodymium.renderer.compat.RenderUtil;
import makamys.neodymium.renderer.compat.RenderUtilRPLE;
import makamys.neodymium.renderer.compat.RenderUtilShaderRPLE;
import makamys.neodymium.renderer.compat.RenderUtilShaders;
import makamys.neodymium.renderer.compat.RenderUtilVanilla;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
Expand All @@ -18,7 +21,6 @@
import cpw.mods.fml.common.event.FMLConstructionEvent;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent;
Expand Down Expand Up @@ -49,6 +51,8 @@ public class Neodymium
private boolean renderDebugText = false;

public static NeoRenderer renderer;

public static RenderUtil util;

private static World rendererWorld;

Expand Down Expand Up @@ -97,6 +101,17 @@ private void onPlayerWorldChanged(World newWorld) {
List<Warning> criticalWarns = warnsAndCriticalWarns.getRight();

if(criticalWarns.isEmpty()) {
boolean rple = Compat.isRPLEModPresent();
boolean optiFineShaders = Compat.isOptiFineShadersEnabled();
if (rple && optiFineShaders) {
util = RenderUtilShaderRPLE.INSTANCE;
} else if (optiFineShaders) {
util = RenderUtilShaders.INSTANCE;
} else if (rple) {
util = RenderUtilRPLE.INSTANCE;
} else {
util = RenderUtilVanilla.INSTANCE;
}
renderer = new NeoRenderer(newWorld);
renderer.hasIncompatibilities = !warns.isEmpty() || !criticalWarns.isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package makamys.neodymium.mixin;

import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Shadow;

import makamys.neodymium.ducks.IMixinGameSettings_OptiFine;
import net.minecraft.client.settings.GameSettings;

@Mixin(value = GameSettings.class, remap = false)
@Mixin(value = GameSettings.class,
remap = false)
@Pseudo
public class MixinGameSettings_OptiFine implements IMixinGameSettings_OptiFine {


@Dynamic
@Shadow
private int ofFogType;

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/makamys/neodymium/mixin/MixinGuiMainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ abstract class MixinGuiMainMenu {
@Shadow
private String splashText;

@Inject(method = "<init>*", at = @At("RETURN"))
@Inject(method = "<init>",
at = @At("RETURN"),
require = 1)
private void postConstructor(CallbackInfo ci) {
splashText = Neodymium.modifySplash(splashText);
}
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/makamys/neodymium/mixin/MixinRenderGlobal.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,36 @@ abstract class MixinRenderGlobal {

private boolean nd$isInsideUpdateRenderers;

@Inject(method = "renderAllRenderLists", at = @At(value = "HEAD"), cancellable = true)
@Inject(method = "renderAllRenderLists",
at = @At(value = "HEAD"),
cancellable = true,
require = 1)
private void blockVanillaChunkRendering(int p1, double p2, CallbackInfo ci) {
if(!Neodymium.shouldRenderVanillaWorld()) {
ci.cancel();
}
}

@Inject(method = "renderSortedRenderers", at = @At(value = "HEAD"))
public void preRenderSortedRenderers(int startRenderer, int numRenderers, int renderPass, double partialTickTime, CallbackInfoReturnable cir) {
@Inject(method = "renderSortedRenderers",
at = @At(value = "HEAD"),
cancellable = true,
require = 1)
public void preRenderSortedRenderers(int startRenderer, int numRenderers, int renderPass, double partialTickTime, CallbackInfoReturnable<Integer> cir) {
if(Neodymium.isActive()) {
Neodymium.renderer.preRenderSortedRenderers(renderPass, partialTickTime, sortedWorldRenderers);
cir.setReturnValue(Neodymium.renderer.preRenderSortedRenderers(renderPass, partialTickTime, sortedWorldRenderers));
}
}

@Inject(method = "loadRenderers", at = @At(value = "HEAD"))
@Inject(method = "loadRenderers",
at = @At(value = "HEAD"),
require = 1)
public void preLoadRenderers(CallbackInfo ci) {
Neodymium.destroyRenderer();
}

@Inject(method = "updateRenderers", at = @At(value = "RETURN"))
@Inject(method = "updateRenderers",
at = @At(value = "RETURN"),
require = 1)
public void speedUpChunkUpdatesForDebug(EntityLivingBase entity, boolean flag, CallbackInfoReturnable<Boolean> cir) {
if(Neodymium.isActive() && !nd$isInsideUpdateRenderers) {
nd$isInsideUpdateRenderers = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.nio.IntBuffer;

import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
Expand All @@ -15,7 +16,12 @@
abstract class MixinRenderGlobal_OptiFine {

// for OptiFine's Fast Render option
@Redirect(method = "renderSortedRenderersFast", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glCallLists(Ljava/nio/IntBuffer;)V"), remap=false)
@Dynamic
@Redirect(method = "renderSortedRenderersFast",
at = @At(value = "INVOKE",
target = "Lorg/lwjgl/opengl/GL11;glCallLists(Ljava/nio/IntBuffer;)V"),
remap=false,
require = 1)
private void redirectRenderAllRenderLists(IntBuffer buffer) {
if(Neodymium.shouldRenderVanillaWorld()) {
GL11.glCallLists(buffer);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/makamys/neodymium/mixin/MixinTessellator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ abstract class MixinTessellator implements ITessellator {

@Shadow private boolean isDrawing;

@Inject(method = "draw", at = @At(value = "HEAD"), cancellable = true)
@Inject(method = "draw",
at = @At(value = "HEAD"),
cancellable = true,
require = 1)
private void preDraw(CallbackInfoReturnable<Integer> cir) {
if(nd$captureMeshes) {
ChunkMesh.preTessellatorDraw((Tessellator)(Object)this);
Expand Down
Loading