From 5a6fbb2cd51a935b5b55c7842d42f657f33c2f00 Mon Sep 17 00:00:00 2001 From: Sleepy Evelyn <46009144+sleepy-evelyn@users.noreply.github.com> Date: Wed, 27 Nov 2024 17:42:04 +0000 Subject: [PATCH] Suppress Tinkers Modifier exception --- gradle.properties | 2 +- .../compat/tconstruct/LazyModifierMixin.java | 29 +++++++++++++++++++ src/main/resources/railwaystweaks.mixins.json | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/main/java/dev/ithundxr/railwaystweaks/mixin/compat/tconstruct/LazyModifierMixin.java diff --git a/gradle.properties b/gradle.properties index 998cdaf..1737f1b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2G # Mod Properties -mod_version = 0.0.46 +mod_version = 0.0.47 maven_group = dev.ithundxr archives_base_name = RailwaysTweaks diff --git a/src/main/java/dev/ithundxr/railwaystweaks/mixin/compat/tconstruct/LazyModifierMixin.java b/src/main/java/dev/ithundxr/railwaystweaks/mixin/compat/tconstruct/LazyModifierMixin.java new file mode 100644 index 0000000..7d4a480 --- /dev/null +++ b/src/main/java/dev/ithundxr/railwaystweaks/mixin/compat/tconstruct/LazyModifierMixin.java @@ -0,0 +1,29 @@ +package dev.ithundxr.railwaystweaks.mixin.compat.tconstruct; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import slimeknights.tconstruct.library.modifiers.Modifier; +import slimeknights.tconstruct.library.modifiers.ModifierId; +import slimeknights.tconstruct.library.modifiers.ModifierManager; +import slimeknights.tconstruct.library.modifiers.util.LazyModifier; + +@Mixin(LazyModifier.class) +public class LazyModifierMixin { + + @Shadow @Final protected ModifierId id; + + @Inject( + method = "get()Lslimeknights/tconstruct/library/modifiers/Modifier;", + at = @At("HEAD"), + cancellable = true, + remap = false + ) + private void railwayTweaks$suppressException(CallbackInfoReturnable cir) { + if (!ModifierManager.INSTANCE.isDynamicModifiersLoaded()) + cir.setReturnValue(ModifierManager.INSTANCE.getDefaultValue()); + } +} diff --git a/src/main/resources/railwaystweaks.mixins.json b/src/main/resources/railwaystweaks.mixins.json index c12022c..195c56a 100644 --- a/src/main/resources/railwaystweaks.mixins.json +++ b/src/main/resources/railwaystweaks.mixins.json @@ -17,6 +17,7 @@ "compat.create.SchematicannonBlockEntityMixin", "compat.dcintegration.DiscordEventListenerMixin", "compat.enchancement.SlideComponentMixin", + "compat.tconstruct.LazyModifierMixin", "compat.tconstruct.SimpleChannelAccessor" ], "client": [