Automatically disable and re-enable Optifine's Fast Render setting before rendering a video
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.replaymod.compat;
|
||||
|
||||
import com.replaymod.compat.optifine.DisableFastRender;
|
||||
import com.replaymod.compat.shaders.ShaderBeginRender;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
@@ -18,6 +19,7 @@ public class ReplayModCompat {
|
||||
public void init(FMLInitializationEvent event) {
|
||||
EventBus bus = FMLCommonHandler.instance().bus();
|
||||
bus.register(new ShaderBeginRender());
|
||||
bus.register(new DisableFastRender());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.replaymod.compat.optifine;
|
||||
|
||||
import com.replaymod.render.events.ReplayRenderEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class DisableFastRender {
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private boolean wasFastRender = false;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderBegin(ReplayRenderEvent.Pre event) {
|
||||
if (!FMLClientHandler.instance().hasOptifine()) return;
|
||||
|
||||
try {
|
||||
wasFastRender = (boolean) OptifineReflection.gameSettings_ofFastRender.get(mc.gameSettings);
|
||||
OptifineReflection.gameSettings_ofFastRender.set(mc.gameSettings, false);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderEnd(ReplayRenderEvent.Post event){
|
||||
if (!FMLClientHandler.instance().hasOptifine()) return;
|
||||
|
||||
try {
|
||||
OptifineReflection.gameSettings_ofFastRender.set(mc.gameSettings, wasFastRender);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.replaymod.compat.optifine;
|
||||
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class OptifineReflection {
|
||||
|
||||
// GameSettings.ofFastRender
|
||||
public static Field gameSettings_ofFastRender;
|
||||
|
||||
static {
|
||||
try {
|
||||
// this throws an ignored ClassNotFoundException if Optifine isn't installed
|
||||
Class.forName("Config");
|
||||
|
||||
gameSettings_ofFastRender = GameSettings.class.getDeclaredField("ofFastRender");
|
||||
gameSettings_ofFastRender.setAccessible(true);
|
||||
} catch (ClassNotFoundException ignore) {
|
||||
// no optifine installed
|
||||
} catch (NoSuchFieldException e) {
|
||||
// the field wasn't found. Has it been renamed?
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user