From 9b5bbe294e020842246aa559424986bd61e9d912 Mon Sep 17 00:00:00 2001 From: Rongmario Date: Sun, 22 Dec 2024 21:21:20 +0000 Subject: [PATCH] Implement fix for BWM beacon loading crashes --- README.md | 2 ++ dependencies.gradle | 1 + gradle.properties | 1 + .../universaltweaks/config/UTConfigMods.java | 11 ++++++++ .../universaltweaks/core/UTMixinLoader.java | 1 + .../bwm/mixin/UTTileEntityBeaconMixin.java | 27 +++++++++++++++++++ src/main/resources/mixins.mods.bwm.json | 7 +++++ 7 files changed, 50 insertions(+) create mode 100644 src/main/java/mod/acgaming/universaltweaks/mods/bwm/mixin/UTTileEntityBeaconMixin.java create mode 100644 src/main/resources/mixins.mods.bwm.json diff --git a/README.md b/README.md index 39badfee..cebd2a49 100644 --- a/README.md +++ b/README.md @@ -309,6 +309,8 @@ All changes are toggleable via config files. * **Botania** * **Duplication Fixes:** Fixes various duplication exploits * **Fancy Skybox:** Enables the Botania Garden of Glass skybox for custom dimensions +* **Better with Mods** + * **Beacon NBT Loading Fix:** Fixes BWM beacons reading null tags from vanilla beacons * **CB Multipart** * **Memory Leak Fix:** Fixes a memory leak associated with EntityPlayer * **Chisel** diff --git a/dependencies.gradle b/dependencies.gradle index 95b2dd60..2a9b656c 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -68,6 +68,7 @@ final def mod_dependencies = [ 'curse.maven:biomes-o-plenty-220318:2842510' : [debug_biomes_o_plenty], 'curse.maven:blood-magic-224791:2822288' : [debug_blood_magic], 'curse.maven:botania-225643:3330934' : [debug_botania], + 'curse.maven:bwm-suite-246760:5702821' : [debug_bwm], 'curse.maven:ceramics-250617:3158763' : [debug_ceramics], 'curse.maven:chameleon-230497:2450900' : [debug_storage_drawers], 'curse.maven:chickens-241941:2537643' : [debug_chickens], diff --git a/gradle.properties b/gradle.properties index 73463e1e..b14aa083 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,6 +15,7 @@ debug_binnies_mods = false debug_biomes_o_plenty = false debug_blood_magic = false debug_botania = false +debug_bwm = true debug_ceramics = false debug_chickens = false debug_chisel = false diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java index 139af306..49c4ead2 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java @@ -51,6 +51,10 @@ public class UTConfigMods @Config.Name("Botania") public static final BotaniaCategory BOTANIA = new BotaniaCategory(); + @Config.LangKey("cfg.universaltweaks.modintegration.bwm") + @Config.Name("Better with Mods") + public static final BWMCategory BWM = new BWMCategory(); + @Config.LangKey("cfg.universaltweaks.modintegration.cbmultipart") @Config.Name("CB Multipart/Forge Multipart CBE") public static final CBMultipartCategory CB_MULTIPART = new CBMultipartCategory(); @@ -403,6 +407,13 @@ public static class BotaniaCategory public boolean utDuplicationFixesToggle = true; } + public static class BWMCategory + { + @Config.Name("Beacon NBT Loading Fix") + @Config.Comment("Fixes BWM beacons reading null tags from vanilla beacons") + public boolean utBeaconNBTLoadingFix = true; + } + public static class CBMultipartCategory { @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 2e5f9c78..a0a2dc20 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java @@ -50,6 +50,7 @@ public class UTMixinLoader implements ILateMixinLoader put("mixins.mods.bloodmagic.json", () -> loaded("bloodmagic")); put("mixins.mods.botania.dupes.json", () -> loaded("botania") && UTConfigMods.BOTANIA.utDuplicationFixesToggle); put("mixins.mods.botania.json", () -> loaded("botania")); + put("mixins.mods.bwm.json", () -> loaded("betterwithmods") && UTConfigMods.BWM.utBeaconNBTLoadingFix); put("mixins.mods.cbmultipart.json", () -> loaded("forgemultipartcbe") && UTConfigMods.CB_MULTIPART.utMemoryLeakFixToggle); put("mixins.mods.ceramics.json", () -> loaded("ceramics")); put("mixins.mods.chisel.tcomplement.dupes.json", () -> loaded("chisel") && loaded("tcomplement") && UTConfigMods.CHISEL.utDuplicationFixesToggle); diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/bwm/mixin/UTTileEntityBeaconMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/bwm/mixin/UTTileEntityBeaconMixin.java new file mode 100644 index 00000000..c1aa9195 --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/mods/bwm/mixin/UTTileEntityBeaconMixin.java @@ -0,0 +1,27 @@ +package mod.acgaming.universaltweaks.mods.bwm.mixin; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; + +import betterwithmods.common.blocks.tile.TileEntityBeacon; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +// Courtesy of Rongmario +@Mixin(TileEntityBeacon.class) +public class UTTileEntityBeaconMixin extends TileEntity +{ + @WrapOperation(method = "readFromNBT", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NBTUtil;readBlockState(Lnet/minecraft/nbt/NBTTagCompound;)Lnet/minecraft/block/state/IBlockState;")) + private IBlockState readBlockState(NBTTagCompound tag, Operation original) + { + if (tag == null) + { + return Blocks.AIR.getDefaultState(); // Conforms to normal behavior (BWM doesn't even do anything with the type field!) + } + return original.call(tag); + } +} diff --git a/src/main/resources/mixins.mods.bwm.json b/src/main/resources/mixins.mods.bwm.json new file mode 100644 index 00000000..d2181b3f --- /dev/null +++ b/src/main/resources/mixins.mods.bwm.json @@ -0,0 +1,7 @@ +{ + "package": "mod.acgaming.universaltweaks.mods.bwm.mixin", + "refmap": "universaltweaks.refmap.json", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins": ["UTTileEntityBeaconMixin"] +}