From d4774a2166420b59518e88d7beb2a838b7c0aadf Mon Sep 17 00:00:00 2001 From: ah-OOG-ah <75745146+ah-OOG-ah@users.noreply.github.com> Date: Mon, 11 Nov 2024 02:24:27 -0500 Subject: [PATCH 1/7] Disable thread safety checks with FalseTweaks If False's threaded rendering is running, it's handling the safety checks itself. --- dependencies.gradle | 3 +++ repositories.gradle | 4 +++- .../java/com/gtnewhorizon/gtnhlib/ClientProxy.java | 11 ++++++++++- .../gtnewhorizon/gtnhlib/compat/FalseTweaks.java | 14 ++++++++++++++ .../java/com/gtnewhorizon/gtnhlib/compat/Mods.java | 7 +++++++ .../gtnhlib/mixins/early/MixinTessellator.java | 6 +++--- 6 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/gtnewhorizon/gtnhlib/compat/FalseTweaks.java create mode 100644 src/main/java/com/gtnewhorizon/gtnhlib/compat/Mods.java diff --git a/dependencies.gradle b/dependencies.gradle index 155f2eb..87fbe36 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -22,4 +22,7 @@ dependencies { compileOnly('org.jetbrains:annotations:24.0.1') compileOnly("org.projectlombok:lombok:1.18.22") {transitive = false } annotationProcessor("org.projectlombok:lombok:1.18.22") + + // For CapturingTesselator compat + compileOnly("com.falsepattern:falsetweaks-mc1.7.10:3.3.2:api") } diff --git a/repositories.gradle b/repositories.gradle index c884390..5e33d9c 100644 --- a/repositories.gradle +++ b/repositories.gradle @@ -1,5 +1,7 @@ // Add any additional repositories for your dependencies here repositories { - + maven { + url = uri("https://mvn.falsepattern.com/releases") + } } diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/ClientProxy.java b/src/main/java/com/gtnewhorizon/gtnhlib/ClientProxy.java index edc3e3e..f3cfc2b 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/ClientProxy.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/ClientProxy.java @@ -2,6 +2,8 @@ import static com.gtnewhorizon.gtnhlib.client.model.ModelLoader.shouldLoadModels; +import com.gtnewhorizon.gtnhlib.compat.FalseTweaks; +import com.gtnewhorizon.gtnhlib.compat.Mods; import net.minecraft.client.Minecraft; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; @@ -23,7 +25,7 @@ public class ClientProxy extends CommonProxy { private static boolean modelsBaked = false; - + public static boolean doThreadSafetyChecks = true; private final Minecraft mc = Minecraft.getMinecraft(); @Override @@ -41,6 +43,13 @@ public void init(FMLInitializationEvent event) { public void postInit(FMLPostInitializationEvent event) { super.postInit(event); + if (Mods.FALSETWEAKS) { + doThreadSafetyChecks = FalseTweaks.doTessSafetyChecks(); + if (!doThreadSafetyChecks) { + GTNHLib.info("FalseTweaks threaded rendering is enabled - disabling GTNHLib's thread safety checks"); + } + } + if (shouldLoadModels()) { Minecraft.getMinecraft().refreshResources(); ModelLoader.loadModels(); diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/compat/FalseTweaks.java b/src/main/java/com/gtnewhorizon/gtnhlib/compat/FalseTweaks.java new file mode 100644 index 0000000..595fdaa --- /dev/null +++ b/src/main/java/com/gtnewhorizon/gtnhlib/compat/FalseTweaks.java @@ -0,0 +1,14 @@ +package com.gtnewhorizon.gtnhlib.compat; + +import com.falsepattern.falsetweaks.api.ThreadedChunkUpdates; + +public class FalseTweaks { + + /** + * When FalseTweaks is loaded, it may inject into the Tesselator to do its own threaded chunk building. If it's + * doing that, disable our checks and let FT handle it. + */ + public static boolean doTessSafetyChecks() { + return !ThreadedChunkUpdates.isEnabled(); + } +} diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/compat/Mods.java b/src/main/java/com/gtnewhorizon/gtnhlib/compat/Mods.java new file mode 100644 index 0000000..668f3e0 --- /dev/null +++ b/src/main/java/com/gtnewhorizon/gtnhlib/compat/Mods.java @@ -0,0 +1,7 @@ +package com.gtnewhorizon.gtnhlib.compat; + +import cpw.mods.fml.common.Loader; + +public class Mods { + public static final boolean FALSETWEAKS = Loader.isModLoaded("falsetweaks"); +} diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/mixins/early/MixinTessellator.java b/src/main/java/com/gtnewhorizon/gtnhlib/mixins/early/MixinTessellator.java index f1cc4ca..99a395f 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/mixins/early/MixinTessellator.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/mixins/early/MixinTessellator.java @@ -1,5 +1,7 @@ package com.gtnewhorizon.gtnhlib.mixins.early; +import static com.gtnewhorizon.gtnhlib.ClientProxy.doThreadSafetyChecks; + import java.nio.Buffer; import java.nio.ByteBuffer; @@ -18,8 +20,6 @@ @Mixin(Tessellator.class) public abstract class MixinTessellator implements ITessellatorInstance { - @Shadow - public int vertexCount; @Shadow public boolean isDrawing; @@ -40,7 +40,7 @@ private Buffer removeStaticBufferResetOutsideSingleton(ByteBuffer buffer) { @Inject(method = "draw", at = @At("HEAD")) private void preventOffMainThreadDrawing(CallbackInfoReturnable cir) { - if (!TessellatorManager.isMainInstance(this)) { + if (doThreadSafetyChecks && !TessellatorManager.isMainInstance(this)) { throw new RuntimeException("Tried to draw on a tessellator that isn't on the main thread!"); } } From d1f45e0674adb65006aedd5ccacfb1269844a585 Mon Sep 17 00:00:00 2001 From: ah-OOG-ah <75745146+ah-OOG-ah@users.noreply.github.com> Date: Mon, 11 Nov 2024 02:30:19 -0500 Subject: [PATCH 2/7] spotless --- src/main/java/com/gtnewhorizon/gtnhlib/ClientProxy.java | 4 ++-- src/main/java/com/gtnewhorizon/gtnhlib/compat/Mods.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/ClientProxy.java b/src/main/java/com/gtnewhorizon/gtnhlib/ClientProxy.java index f3cfc2b..5eaefcc 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/ClientProxy.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/ClientProxy.java @@ -2,8 +2,6 @@ import static com.gtnewhorizon.gtnhlib.client.model.ModelLoader.shouldLoadModels; -import com.gtnewhorizon.gtnhlib.compat.FalseTweaks; -import com.gtnewhorizon.gtnhlib.compat.Mods; import net.minecraft.client.Minecraft; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; @@ -12,6 +10,8 @@ import com.gtnewhorizon.gtnhlib.client.model.ModelLoader; import com.gtnewhorizon.gtnhlib.commands.ItemInHandCommand; +import com.gtnewhorizon.gtnhlib.compat.FalseTweaks; +import com.gtnewhorizon.gtnhlib.compat.Mods; import com.gtnewhorizon.gtnhlib.eventbus.EventBusSubscriber; import com.gtnewhorizon.gtnhlib.util.AboveHotbarHUD; diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/compat/Mods.java b/src/main/java/com/gtnewhorizon/gtnhlib/compat/Mods.java index 668f3e0..7a4ade5 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/compat/Mods.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/compat/Mods.java @@ -3,5 +3,6 @@ import cpw.mods.fml.common.Loader; public class Mods { + public static final boolean FALSETWEAKS = Loader.isModLoaded("falsetweaks"); } From b94953902229c45d6022ddf9fac4e741f7eceb2d Mon Sep 17 00:00:00 2001 From: ah-OOG-ah <75745146+ah-OOG-ah@users.noreply.github.com> Date: Mon, 11 Nov 2024 02:50:01 -0500 Subject: [PATCH 3/7] Add API for finding current capturing state --- gradle.properties | 2 +- .../gtnewhorizon/gtnhlib/api/CapturingTesselator.java | 10 ++++++++++ .../gtnhlib/client/renderer/TessellatorManager.java | 4 ++++ .../java/com/gtnewhorizon/gtnhlib/mixins/Mixins.java | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/gtnewhorizon/gtnhlib/api/CapturingTesselator.java diff --git a/gradle.properties b/gradle.properties index 869cc51..276cfa3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -75,7 +75,7 @@ replaceGradleTokenInFile = # In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can # leave this property empty. # Example value: (apiPackage = api) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.api -apiPackage = +apiPackage = api # Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/ # There can be multiple files in a space-separated list. diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/api/CapturingTesselator.java b/src/main/java/com/gtnewhorizon/gtnhlib/api/CapturingTesselator.java new file mode 100644 index 0000000..f79dc68 --- /dev/null +++ b/src/main/java/com/gtnewhorizon/gtnhlib/api/CapturingTesselator.java @@ -0,0 +1,10 @@ +package com.gtnewhorizon.gtnhlib.api; + +import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager; + +public class CapturingTesselator { + + public static boolean isCapturing() { + return TessellatorManager.isCurrentlyCapturing(); + } +} diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/client/renderer/TessellatorManager.java b/src/main/java/com/gtnewhorizon/gtnhlib/client/renderer/TessellatorManager.java index c08631f..a8b11c4 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/client/renderer/TessellatorManager.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/client/renderer/TessellatorManager.java @@ -32,6 +32,10 @@ public static Tessellator get() { } } + public static boolean isCurrentlyCapturing() { + return currentlyCapturing.get(); + } + public static boolean isOnMainThread() { return Thread.currentThread() == mainThread; } diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/mixins/Mixins.java b/src/main/java/com/gtnewhorizon/gtnhlib/mixins/Mixins.java index e6e094c..0090542 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/mixins/Mixins.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/mixins/Mixins.java @@ -14,7 +14,7 @@ public enum Mixins { - TESSELLATOR(new Builder("Sodium").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT).setPhase(Phase.EARLY) + TESSELLATOR(new Builder("Thread safety checks for the Tesselator").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT).setPhase(Phase.EARLY) .setApplyIf(() -> true).addMixinClasses("MixinTessellator")), WAVEFRONT_VBO(new Builder("WavefrontObject").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT) .setPhase(Phase.EARLY).setApplyIf(() -> true).addMixinClasses("MixinWavefrontObject")), From 7c0b341c40f928b1c707415ef9061770103baefe Mon Sep 17 00:00:00 2001 From: ah-OOG-ah <75745146+ah-OOG-ah@users.noreply.github.com> Date: Mon, 11 Nov 2024 02:52:44 -0500 Subject: [PATCH 4/7] spotless --- src/main/java/com/gtnewhorizon/gtnhlib/mixins/Mixins.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/mixins/Mixins.java b/src/main/java/com/gtnewhorizon/gtnhlib/mixins/Mixins.java index 0090542..e1cd63a 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/mixins/Mixins.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/mixins/Mixins.java @@ -14,8 +14,8 @@ public enum Mixins { - TESSELLATOR(new Builder("Thread safety checks for the Tesselator").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT).setPhase(Phase.EARLY) - .setApplyIf(() -> true).addMixinClasses("MixinTessellator")), + TESSELLATOR(new Builder("Thread safety checks for the Tesselator").addTargetedMod(TargetedMod.VANILLA) + .setSide(Side.CLIENT).setPhase(Phase.EARLY).setApplyIf(() -> true).addMixinClasses("MixinTessellator")), WAVEFRONT_VBO(new Builder("WavefrontObject").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT) .setPhase(Phase.EARLY).setApplyIf(() -> true).addMixinClasses("MixinWavefrontObject")), GUI_MOD_LIST(new Builder("Auto config ui").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT) From 8597e0250f6bef4edc2d1ebc38eeb354b34c87a9 Mon Sep 17 00:00:00 2001 From: ah-OOG-ah <75745146+ah-OOG-ah@users.noreply.github.com> Date: Mon, 11 Nov 2024 12:06:19 -0500 Subject: [PATCH 5/7] Add `getThreadTesselator` to the API --- .../gtnhlib/api/CapturingTesselator.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/api/CapturingTesselator.java b/src/main/java/com/gtnewhorizon/gtnhlib/api/CapturingTesselator.java index f79dc68..465f999 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/api/CapturingTesselator.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/api/CapturingTesselator.java @@ -1,10 +1,23 @@ package com.gtnewhorizon.gtnhlib.api; import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager; +import net.minecraft.client.renderer.Tessellator; -public class CapturingTesselator { - - public static boolean isCapturing() { +@SuppressWarnings("unused") +public interface CapturingTesselator { + /** + * @return True if this thread is capturing quads, false otherwise + */ + static boolean isCapturing() { return TessellatorManager.isCurrentlyCapturing(); } + + /** + * @throws IllegalStateException If the thread is not capturing and is not the main one. + * @return The CapturingTesselator for this thread if capturing, or else {@link Tessellator#instance} if on the main + * one. + */ + static Tessellator getThreadTesselator() { + return TessellatorManager.get(); + } } From cdcef0b0164e32a160d2edbe3292b5ef0fee5054 Mon Sep 17 00:00:00 2001 From: ah-OOG-ah <75745146+ah-OOG-ah@users.noreply.github.com> Date: Mon, 11 Nov 2024 12:09:47 -0500 Subject: [PATCH 6/7] spotless --- .../com/gtnewhorizon/gtnhlib/api/CapturingTesselator.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/api/CapturingTesselator.java b/src/main/java/com/gtnewhorizon/gtnhlib/api/CapturingTesselator.java index 465f999..37e0f06 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/api/CapturingTesselator.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/api/CapturingTesselator.java @@ -1,10 +1,12 @@ package com.gtnewhorizon.gtnhlib.api; -import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager; import net.minecraft.client.renderer.Tessellator; +import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager; + @SuppressWarnings("unused") public interface CapturingTesselator { + /** * @return True if this thread is capturing quads, false otherwise */ @@ -15,7 +17,7 @@ static boolean isCapturing() { /** * @throws IllegalStateException If the thread is not capturing and is not the main one. * @return The CapturingTesselator for this thread if capturing, or else {@link Tessellator#instance} if on the main - * one. + * one. */ static Tessellator getThreadTesselator() { return TessellatorManager.get(); From 418cb0140a29e86f74f64433eb83571eb0ef40ae Mon Sep 17 00:00:00 2001 From: ah-OOG-ah <75745146+ah-OOG-ah@users.noreply.github.com> Date: Mon, 11 Nov 2024 12:27:49 -0500 Subject: [PATCH 7/7] Define maven content --- repositories.gradle | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/repositories.gradle b/repositories.gradle index 5e33d9c..ccb1da2 100644 --- a/repositories.gradle +++ b/repositories.gradle @@ -2,6 +2,10 @@ repositories { maven { - url = uri("https://mvn.falsepattern.com/releases") + name = 'mavenpattern' + url = 'https://mvn.falsepattern.com/releases' + content { + includeGroup 'com.falsepattern' + } } }