From eb65b8f96e773b3555f9e8e473cc0663b5db13ae Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Mon, 8 Apr 2024 02:38:39 -0700 Subject: [PATCH 1/2] Fully Unregister RFTools Dimensions --- README.md | 2 + build.gradle | 3 + .../universaltweaks/config/UTConfigMods.java | 12 ++++ .../universaltweaks/core/UTMixinLoader.java | 3 + .../mixin/UTDimensionManager.java | 58 +++++++++++++++++++ .../UTRfToolsDimensionManagerAccessor.java | 23 ++++++++ .../mixins.mods.rftoolsdimensions.json | 7 +++ 7 files changed, 108 insertions(+) create mode 100644 src/main/java/mod/acgaming/universaltweaks/mods/rftoolsdimension/mixin/UTDimensionManager.java create mode 100644 src/main/java/mod/acgaming/universaltweaks/mods/rftoolsdimension/mixin/UTRfToolsDimensionManagerAccessor.java create mode 100644 src/main/resources/mixins.mods.rftoolsdimensions.json diff --git a/README.md b/README.md index 849b537b..458be0a1 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,8 @@ All changes are toggleable via config files. * **Duplication Fixes:** Fixes various duplication exploits * **Quark** * **Duplication Fixes:** Fixes various duplication exploits +* **RFTools Dimension** + * **Properly Unregister Dimensions:** Fixes a bug where joining a world or server with any RFTools Dimension registered would disallow entering another world without that dimension until restarting. * **Roost** * **Early Register CT Chickens:** Improves load time by registering ContentTweaker chickens early for Roost to detect them * **Simple Difficulty** diff --git a/build.gradle b/build.gradle index 2640b09c..88d5b4a9 100644 --- a/build.gradle +++ b/build.gradle @@ -164,6 +164,9 @@ dependencies { compileOnly rfg.deobf('net.darkhax.gamestages:GameStages-1.12.2:2.0.120') compileOnly rfg.deobf('net.darkhax.itemstages:ItemStages-1.12.2:2.0.51') compileOnly rfg.deobf('net.darkhax.mobstages:MobStages-1.12.2:2.0.13') + compileOnly rfg.deobf('curse.maven:mcjtylib-233105:2745846') + compileOnly rfg.deobf('curse.maven:rftools-224641:2861573') + compileOnly rfg.deobf('curse.maven:rftools-dimensions-240950:2707390') compileOnly 'curse.maven:actuallyaditions-228404:2844115' compileOnly 'curse.maven:applecore-224472:2969118' compileOnly 'curse.maven:arcanearchives-311357:3057332' diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java index e0dc1f0e..3d390d20 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java @@ -143,6 +143,10 @@ public class UTConfigMods @Config.Name("Quark") public static final QuarkCategory QUARK = new QuarkCategory(); + @Config.LangKey("cfg.universaltweaks.modintegration.rftoolsdimensions") + @Config.Name("RFTools Dimensions") + public static final RFToolsDimensionsCategory RFTOOLS_DIMENSIONS = new RFToolsDimensionsCategory(); + @Config.LangKey("cfg.universaltweaks.modintegration.roost") @Config.Name("Roost") public static final RoostCategory ROOST = new RoostCategory(); @@ -571,6 +575,14 @@ public static class RoostCategory public boolean utRoostEarlyRegisterCTChickens = true; } + public static class RFToolsDimensionsCategory + { + @Config.RequiresMcRestart + @Config.Name("Fully Unregister Dimensions") + @Config.Comment("Fixes a bug where joining a world or server with any RFTools Dimension registered would disallow entering another world without that dimension until restarting") + public boolean utFullyUnregisterDimensions = true; + } + public static class SimpleDifficultyCategory { @Config.RequiresMcRestart diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java index 34904dff..84c4e66d 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java @@ -65,6 +65,7 @@ public List getMixinConfigs() configs.add("mixins.mods.nuclearcraft.json"); configs.add("mixins.mods.quark.dupes.json"); configs.add("mixins.mods.reskillable.json"); + configs.add("mixins.mods.rftoolsdimensions.json"); configs.add("mixins.mods.roost.contenttweaker.json"); configs.add("mixins.mods.simpledifficulty.json"); configs.add("mixins.mods.spiceoflife.dupes.json"); @@ -188,6 +189,8 @@ public boolean shouldMixinConfigQueue(String mixinConfig) return Loader.isModLoaded("quark") && UTConfigMods.QUARK.utDuplicationFixesToggle; case "mixins.mods.reskillable.json": return Loader.isModLoaded("reskillable"); + case "mixins.mods.rftoolsdimensions.json": + return Loader.isModLoaded("rftoolsdim"); case "mixins.mods.roost.contenttweaker.json": return Loader.isModLoaded("contenttweaker"); case "mixins.mods.simpledifficulty.json": diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/rftoolsdimension/mixin/UTDimensionManager.java b/src/main/java/mod/acgaming/universaltweaks/mods/rftoolsdimension/mixin/UTDimensionManager.java new file mode 100644 index 00000000..43f7ebf4 --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/mods/rftoolsdimension/mixin/UTDimensionManager.java @@ -0,0 +1,58 @@ +package mod.acgaming.universaltweaks.mods.rftoolsdimension.mixin; + +import mcjty.rftoolsdim.dimensions.RfToolsDimensionManager; +import mcjty.rftoolsdim.dimensions.description.DimensionDescriptor; +import mod.acgaming.universaltweaks.UniversalTweaks; +import mod.acgaming.universaltweaks.config.UTConfigMods; +import net.minecraftforge.common.DimensionManager; +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.CallbackInfo; + +import java.util.Map; + +// Courtesy of WaitingIdly +@Mixin(value = RfToolsDimensionManager.class, remap = false) +public abstract class UTDimensionManager +{ + @Shadow + private static RfToolsDimensionManager clientInstance; + + @Inject(method = "cleanupDimensionInformation", at = @At("HEAD")) + private static void utClearClientInstance(CallbackInfo ci) + { + if (!UTConfigMods.RFTOOLS_DIMENSIONS.utFullyUnregisterDimensions) return; + if (clientInstance != null) + { + UniversalTweaks.LOGGER.info("UTDimensionManager ::: Cleaning up RFTools dimensions for the clientInstance"); + + for (int id : clientInstance.getDimensions().keySet()) + { + if (DimensionManager.isDimensionRegistered(id)) + { + UniversalTweaks.LOGGER.info("UTDimensionManager ::: Unregister dimension: " + id); + + try + { + DimensionManager.unregisterDimension(id); + } + catch (Exception e) + { + UniversalTweaks.LOGGER.error("UTDimensionManager ::: Error unregistering dimension: " + id, e); + } + } + else + { + UniversalTweaks.LOGGER.info("UTDimensionManager ::: Already unregistered! Dimension: " + id); + } + } + clientInstance.getDimensions().clear(); + ((UTRfToolsDimensionManagerAccessor) clientInstance).getDimensionToID().clear(); + ((UTRfToolsDimensionManagerAccessor) clientInstance).getDimensionInformation().clear(); + ((UTRfToolsDimensionManagerAccessor) clientInstance).getReclaimedIds().clear(); + clientInstance = null; + } + } +} diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/rftoolsdimension/mixin/UTRfToolsDimensionManagerAccessor.java b/src/main/java/mod/acgaming/universaltweaks/mods/rftoolsdimension/mixin/UTRfToolsDimensionManagerAccessor.java new file mode 100644 index 00000000..adc0273b --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/mods/rftoolsdimension/mixin/UTRfToolsDimensionManagerAccessor.java @@ -0,0 +1,23 @@ +package mod.acgaming.universaltweaks.mods.rftoolsdimension.mixin; + +import mcjty.rftoolsdim.dimensions.DimensionInformation; +import mcjty.rftoolsdim.dimensions.RfToolsDimensionManager; +import mcjty.rftoolsdim.dimensions.description.DimensionDescriptor; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Map; +import java.util.Set; + +@Mixin(value = RfToolsDimensionManager.class, remap = false) +public interface UTRfToolsDimensionManagerAccessor +{ + @Accessor("dimensionToID") + Map getDimensionToID(); + + @Accessor("dimensionInformation") + Map getDimensionInformation(); + + @Accessor("reclaimedIds") + Set getReclaimedIds(); +} diff --git a/src/main/resources/mixins.mods.rftoolsdimensions.json b/src/main/resources/mixins.mods.rftoolsdimensions.json new file mode 100644 index 00000000..b2a20778 --- /dev/null +++ b/src/main/resources/mixins.mods.rftoolsdimensions.json @@ -0,0 +1,7 @@ +{ + "package": "mod.acgaming.universaltweaks.mods.rftoolsdimension.mixin", + "refmap": "universaltweaks.refmap.json", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins": ["UTDimensionManager", "UTRfToolsDimensionManagerAccessor"] +} \ No newline at end of file From 0de580698e12b8e2133cd6b48a603c21589d2975 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Mon, 8 Apr 2024 04:28:08 -0700 Subject: [PATCH 2/2] lang key --- src/main/resources/assets/universaltweaks/lang/en_us.lang | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/assets/universaltweaks/lang/en_us.lang b/src/main/resources/assets/universaltweaks/lang/en_us.lang index bdd6c3a9..f8495290 100644 --- a/src/main/resources/assets/universaltweaks/lang/en_us.lang +++ b/src/main/resources/assets/universaltweaks/lang/en_us.lang @@ -74,6 +74,7 @@ cfg.universaltweaks.modintegration.netherrocks=Netherrocks cfg.universaltweaks.modintegration.nuclearcraft=NuclearCraft cfg.universaltweaks.modintegration.projectred=ProjectRed cfg.universaltweaks.modintegration.quark=Quark +cfg.universaltweaks.modintegration.rftoolsdimensions=RFTools Dimensions cfg.universaltweaks.modintegration.roost=Roost cfg.universaltweaks.modintegration.sd=Storage Drawers cfg.universaltweaks.modintegration.simpledifficulty=Simple Difficulty