Skip to content

Commit 2783c7f

Browse files
committed
NotFine compat
#181
1 parent eae8a29 commit 2783c7f

14 files changed

Lines changed: 203 additions & 58 deletions

File tree

build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ repositories {
6363
}
6464
}
6565
exclusive(maven("horizon", "https://mvn.falsepattern.com/horizon"), "com.github.GTNewHorizons")
66-
exclusive(jitpack(), "com.github.basdxz")
66+
exclusive(jitpack(), "com.github.basdxz", "com.github.jss2a98aj")
6767
exclusive(maven("mega_uploads", "https://mvn.falsepattern.com/gtmega_uploads"), "optifine")
6868
exclusive(mega(), "codechicken")
6969
exclusive(ivy("https://files.vexatos.com/", "[module]/[artifact]-[revision].[ext]"), "vexatos")
@@ -91,6 +91,10 @@ dependencies {
9191
excludeDeps()
9292
}
9393

94+
compileOnly("com.github.jss2a98aj:NotFine:0.2.5:dev") {
95+
excludeDeps()
96+
}
97+
9498
compileOnly(deobfCurse("railcraft-51195:2458987"))
9599

96100
// Nuclear Control 2 2.4.5a

src/main/java/com/falsepattern/falsetweaks/asm/CoreLoadingPlugin.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
import lombok.Getter;
3636
import lombok.val;
37+
import org.spongepowered.asm.launch.GlobalProperties;
38+
import org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper;
3739

3840
import net.minecraft.launchwrapper.Launch;
3941
import net.minecraft.launchwrapper.LaunchClassLoader;
@@ -77,6 +79,11 @@ private static void pleaseDontBreakMyThreadedRendering() {
7779

7880
@Override
7981
public String[] getASMTransformerClass() {
82+
83+
val mixinTweakClasses = GlobalProperties.<List<String>>get(MixinServiceLaunchWrapper.BLACKBOARD_KEY_TWEAKCLASSES);
84+
if (mixinTweakClasses != null) {
85+
mixinTweakClasses.add(Tags.ROOT_PKG + ".asm.MixinCompatHackTweaker");
86+
}
8087
return new String[]{Tags.ROOT_PKG + ".asm.FalseTweaksTransformer"};
8188
}
8289

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.falsepattern.falsetweaks.asm;
2+
3+
import com.falsepattern.falsetweaks.asm.modules.threadedupdates.block.Threading_BlockMinMax;
4+
import com.falsepattern.falsetweaks.asm.modules.threadedupdates.block.Threading_BlockMinMaxRedirector;
5+
import com.falsepattern.falsetweaks.asm.modules.threadedupdates.settings.Threading_GameSettings;
6+
import com.falsepattern.falsetweaks.asm.modules.threadedupdates.settings.Threading_GameSettingsRedirector;
7+
import com.falsepattern.falsetweaks.config.ModuleConfig;
8+
import com.falsepattern.lib.turboasm.MergeableTurboTransformer;
9+
import com.falsepattern.lib.turboasm.TurboClassTransformer;
10+
import lombok.val;
11+
12+
import cpw.mods.fml.relauncher.FMLLaunchHandler;
13+
14+
import java.util.ArrayList;
15+
import java.util.List;
16+
17+
public class FalseTweaksFieldHackTransformer extends MergeableTurboTransformer {
18+
private static List<TurboClassTransformer> transformers() {
19+
val transformers = new ArrayList<TurboClassTransformer>();
20+
if (FMLLaunchHandler.side().isClient() && ModuleConfig.THREADED_CHUNK_UPDATES()) {
21+
transformers.add(new Threading_GameSettings());
22+
transformers.add(new Threading_GameSettingsRedirector());
23+
transformers.add(new Threading_BlockMinMax());
24+
transformers.add(new Threading_BlockMinMaxRedirector());
25+
}
26+
return transformers;
27+
}
28+
29+
public FalseTweaksFieldHackTransformer() {
30+
super(transformers());
31+
}
32+
}

src/main/java/com/falsepattern/falsetweaks/asm/FalseTweaksTransformer.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ private static List<TurboClassTransformer> transformers() {
5656
transformers.add(new Threading_RenderBlocksASM());
5757
transformers.add(new Threading_TessellatorUseReplacement());
5858
transformers.add(new Threading_ThreadSafeBlockRendererInjector());
59-
transformers.add(new Threading_BlockMinMax());
60-
transformers.add(new Threading_BlockMinMaxRedirector());
61-
transformers.add(new Threading_GameSettings());
62-
transformers.add(new Threading_GameSettingsRedirector());
6359
}
6460
}
6561
return transformers;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.falsepattern.falsetweaks.asm;
2+
3+
import com.falsepattern.falsetweaks.Tags;
4+
5+
import net.minecraft.launchwrapper.ITweaker;
6+
import net.minecraft.launchwrapper.Launch;
7+
import net.minecraft.launchwrapper.LaunchClassLoader;
8+
9+
import java.io.File;
10+
import java.util.List;
11+
12+
public class MixinCompatHackTweaker implements ITweaker {
13+
@Override
14+
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
15+
16+
}
17+
18+
@Override
19+
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
20+
21+
}
22+
23+
@Override
24+
public String getLaunchTarget() {
25+
return null;
26+
}
27+
28+
@Override
29+
public String[] getLaunchArguments() {
30+
Launch.classLoader.registerTransformer(Tags.ROOT_PKG + ".asm.modules.threadedupdates.block.Threading_BlockMinMaxTransformer");
31+
return new String[0];
32+
}
33+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.falsepattern.falsetweaks.asm.modules.occlusion.optifine;
2+
3+
import net.minecraft.launchwrapper.Launch;
4+
import cpw.mods.fml.client.FMLClientHandler;
5+
import cpw.mods.fml.common.Loader;
6+
import cpw.mods.fml.relauncher.FMLLaunchHandler;
7+
8+
public class LazyOptiFineCheck {
9+
private static Boolean optifineDetected = null;
10+
11+
public static boolean hasOptiFine() {
12+
Boolean detected = optifineDetected;
13+
if (detected == null) {
14+
if (FMLLaunchHandler.side().isClient()) {
15+
try {
16+
//We might be too early but let's try the standard way
17+
detected = FMLClientHandler.instance().hasOptifine();
18+
} catch (Throwable ignored) {
19+
//Ok, we'll do it manually then
20+
try {
21+
ClassLoader cl;
22+
cl = Loader.instance().getModClassLoader();
23+
if (cl == null) {
24+
cl = Launch.classLoader;
25+
}
26+
Class.forName("Config", false, cl);
27+
detected = true;
28+
} catch (Throwable ignored1) {
29+
//99.9% sure that optifine is not present
30+
detected = false;
31+
}
32+
}
33+
} else {
34+
//server shouldn't have OF
35+
detected = false;
36+
}
37+
optifineDetected = detected;
38+
}
39+
return detected;
40+
}
41+
}

src/main/java/com/falsepattern/falsetweaks/asm/modules/occlusion/optifine/RenderGlobalDeOptimizer.java

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@
3232
import org.objectweb.asm.tree.MethodInsnNode;
3333
import org.objectweb.asm.tree.TypeInsnNode;
3434

35-
import net.minecraft.launchwrapper.Launch;
36-
import cpw.mods.fml.client.FMLClientHandler;
37-
import cpw.mods.fml.common.FMLCommonHandler;
38-
import cpw.mods.fml.common.Loader;
39-
import cpw.mods.fml.relauncher.FMLLaunchHandler;
40-
import cpw.mods.fml.relauncher.Side;
41-
4235
/**
4336
* OptiFine does some weird optimizations that conflict with the occlusion code.
4437
* So I just remove them :3
@@ -71,40 +64,6 @@ public boolean shouldTransformClass(@NotNull String className, @NotNull ClassNod
7164
return LazyOptiFineCheck.hasOptiFine();
7265
}
7366

74-
private static class LazyOptiFineCheck {
75-
private static Boolean optifineDetected = null;
76-
private static boolean hasOptiFine() {
77-
Boolean detected = optifineDetected;
78-
if (detected == null) {
79-
if (FMLLaunchHandler.side().isClient()) {
80-
try {
81-
//We might be too early but let's try the standard way
82-
detected = FMLClientHandler.instance().hasOptifine();
83-
} catch (Throwable ignored) {
84-
//Ok, we'll do it manually then
85-
try {
86-
ClassLoader cl;
87-
cl = Loader.instance().getModClassLoader();
88-
if (cl == null) {
89-
cl = Launch.classLoader;
90-
}
91-
Class.forName("Config", false, cl);
92-
detected = true;
93-
} catch (Throwable ignored1) {
94-
//99.9% sure that optifine is not present
95-
detected = false;
96-
}
97-
}
98-
} else {
99-
//server shouldn't have OF
100-
detected = false;
101-
}
102-
optifineDetected = detected;
103-
}
104-
return detected;
105-
}
106-
}
107-
10867
@Override
10968
public boolean transformClass(@NotNull String className, @NotNull ClassNodeHandle classNode) {
11069
val cn = classNode.getNode();

src/main/java/com/falsepattern/falsetweaks/config/OcclusionConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class OcclusionConfig {
3535

3636
@Config.Comment("Similar to OptiFine's \"Dynamic Updates\" feature, where chunks load faster when you don't move the player at all.")
3737
@Config.LangKey("config.falsetweaks.occlusion.dynamic")
38-
@Config.DefaultBoolean(true)
38+
@Config.DefaultBoolean(false)
3939
public static boolean DYNAMIC_CHUNK_UPDATES;
4040

4141
@Config.Comment("The amount of chunks renderers to update PER SECOND. This is a MAXIMUM limit, not a minimum.\n" +

src/main/java/com/falsepattern/falsetweaks/mixin/mixins/client/particles/EffectRendererMixin.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
package com.falsepattern.falsetweaks.mixin.mixins.client.particles;
2525

26-
import org.lwjgl.opengl.GL11;
2726
import org.spongepowered.asm.mixin.Mixin;
2827
import org.spongepowered.asm.mixin.injection.At;
2928
import org.spongepowered.asm.mixin.injection.Redirect;
@@ -35,9 +34,9 @@ public abstract class EffectRendererMixin {
3534
@Redirect(method = "renderParticles",
3635
at = @At(value = "INVOKE",
3736
target = "Lorg/lwjgl/opengl/GL11;glDepthMask(Z)V",
38-
remap = false),
39-
require = 2)
37+
ordinal = 0,
38+
remap = false))
4039
private void alwaysDepthMaskParticles(boolean flag) {
41-
GL11.glDepthMask(true);
40+
4241
}
4342
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.falsepattern.falsetweaks.mixin.mixins.client.threadedupdates.notfine;
2+
3+
import com.prupe.mcpatcher.ctm.CTMUtils;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.Unique;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Inject;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
9+
10+
import net.minecraft.block.Block;
11+
import net.minecraft.util.IIcon;
12+
import net.minecraft.world.IBlockAccess;
13+
14+
import java.util.concurrent.atomic.AtomicInteger;
15+
import java.util.concurrent.locks.ReentrantLock;
16+
17+
@Mixin(value = CTMUtils.class,
18+
remap = false)
19+
public abstract class CTMUtilsMixin {@Unique
20+
private static final ReentrantLock ft$lock = new ReentrantLock();
21+
@Unique
22+
private static final AtomicInteger ft$lockCounter = new AtomicInteger(0);
23+
24+
@Inject(method = "getBlockIcon(Lnet/minecraft/util/IIcon;Lnet/minecraft/block/Block;Lnet/minecraft/world/IBlockAccess;IIII)Lnet/minecraft/util/IIcon;",
25+
at = @At("HEAD"),
26+
require = 1)
27+
private static void lock1(IIcon icon, Block block, IBlockAccess blockAccess, int x, int y, int z, int face, CallbackInfoReturnable<IIcon> cir) {
28+
ft$lock();
29+
}
30+
31+
@Inject(method = "getBlockIcon(Lnet/minecraft/util/IIcon;Lnet/minecraft/block/Block;II)Lnet/minecraft/util/IIcon;",
32+
at = @At("HEAD"),
33+
require = 1)
34+
private static void lock2(IIcon icon, Block block, int face, int metadata, CallbackInfoReturnable<IIcon> cir) {
35+
ft$lock();
36+
}
37+
38+
39+
@Inject(method = "getBlockIcon(Lnet/minecraft/util/IIcon;Lnet/minecraft/block/Block;Lnet/minecraft/world/IBlockAccess;IIII)Lnet/minecraft/util/IIcon;",
40+
at = @At("RETURN"),
41+
require = 1)
42+
private static void unlock1(IIcon icon, Block block, IBlockAccess blockAccess, int x, int y, int z, int face, CallbackInfoReturnable<IIcon> cir) {
43+
ft$unlock();
44+
}
45+
46+
@Inject(method = "getBlockIcon(Lnet/minecraft/util/IIcon;Lnet/minecraft/block/Block;II)Lnet/minecraft/util/IIcon;",
47+
at = @At("RETURN"),
48+
require = 1)
49+
private static void unlock2(IIcon icon, Block block, int face, int metadata, CallbackInfoReturnable<IIcon> cir) {
50+
ft$unlock();
51+
}
52+
53+
@Unique
54+
private static void ft$lock() {
55+
if (!ft$lock.isHeldByCurrentThread()) {
56+
while (!ft$lock.tryLock()) {
57+
Thread.yield();
58+
}
59+
}
60+
ft$lockCounter.incrementAndGet();
61+
}
62+
63+
@Unique
64+
private static void ft$unlock() {
65+
if (ft$lockCounter.decrementAndGet() == 0) {
66+
ft$lock.unlock();
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)