diff --git a/build.gradle b/build.gradle index c24f594f..ddd66c80 100644 --- a/build.gradle +++ b/build.gradle @@ -4,6 +4,7 @@ plugins { id 'idea' id 'maven-publish' id 'net.neoforged.gradle.userdev' version '7.0.151' + id 'net.neoforged.gradle.mixin' version '7.0.151' } tasks.named('wrapper', Wrapper).configure { @@ -103,6 +104,14 @@ repositories { } } +mixin { + // add sourceSets.main, "${mod_id}.refmap.json" + // Sets up the mixin config; this gets added to run configurations and the manifest in the final jar + config "${mod_id}.mixins.json" + + // Enables exporting mixin-changed classes to .mixin.out in the run folder + // debug.export = true +} dependencies { // Specify the version of Minecraft to use. diff --git a/src/main/java/com/legobmw99/allomancy/modules/consumables/item/VialItem.java b/src/main/java/com/legobmw99/allomancy/modules/consumables/item/VialItem.java index ee2d8425..5ec09ca8 100644 --- a/src/main/java/com/legobmw99/allomancy/modules/consumables/item/VialItem.java +++ b/src/main/java/com/legobmw99/allomancy/modules/consumables/item/VialItem.java @@ -99,6 +99,7 @@ public static void fillVial(ItemStack stack, FlakeStorage storage) { /** * TEMPORARY: Used to port pre-1.20.5 worlds to post. * Loads custom NBT data and convets it to the data component. + * TODO: Remove in future version once worlds have updated */ @Override public void verifyComponentsAfterLoad(ItemStack pStack) { diff --git a/src/main/java/com/legobmw99/allomancy/modules/extras/mixin/BannerDFUMixin.java b/src/main/java/com/legobmw99/allomancy/modules/extras/mixin/BannerDFUMixin.java new file mode 100644 index 00000000..7114b0d5 --- /dev/null +++ b/src/main/java/com/legobmw99/allomancy/modules/extras/mixin/BannerDFUMixin.java @@ -0,0 +1,46 @@ +package com.legobmw99.allomancy.modules.extras.mixin; + +import com.legobmw99.allomancy.Allomancy; +import com.legobmw99.allomancy.api.enums.Metal; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.datafix.fixes.BannerPatternFormatFix; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +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.HashMap; +import java.util.Locale; +import java.util.Map; + + +/** + * TEMPORARY: Used to port 1.20 banners to 1.21 + * TODO: Remove in future version once worlds have updated + */ +@Mixin(BannerPatternFormatFix.class) +public class BannerDFUMixin { + @Mutable + @Final + @Shadow + private static Map PATTERN_ID_MAP; + + @Inject(at = @At("RETURN"), method = "") + private static void onConstruct(CallbackInfo info) { + + Allomancy.LOGGER.info("Injecting to banner DFU"); + var patternMap = new HashMap<>(PATTERN_ID_MAP); + + for (Metal mt : Metal.values()) { + String name = mt.getName(); + Allomancy.LOGGER.info("Redirecting banner pattern for {}", name); + patternMap.put("ALLOMANCY" + name.toUpperCase(Locale.ROOT), + ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, name).toString()); + } + + PATTERN_ID_MAP = patternMap; + } +} diff --git a/src/main/java/com/legobmw99/allomancy/modules/powers/CommonEventHandler.java b/src/main/java/com/legobmw99/allomancy/modules/powers/CommonEventHandler.java index 8dab5aec..e9537250 100644 --- a/src/main/java/com/legobmw99/allomancy/modules/powers/CommonEventHandler.java +++ b/src/main/java/com/legobmw99/allomancy/modules/powers/CommonEventHandler.java @@ -51,6 +51,7 @@ private CommonEventHandler() {} /** * TEMPORARY: Used to port Forge worlds to Neoforged. * Loads the player's data file and sees if they have an old forge Capability stored. + * TODO: Remove in future version once worlds have updated */ @SubscribeEvent public static void onPlayerLoad(final PlayerEvent.LoadFromFile event) { diff --git a/src/main/resources/META-INF/neoforge.mods.toml b/src/main/resources/META-INF/neoforge.mods.toml index 37474f7f..ed665d64 100644 --- a/src/main/resources/META-INF/neoforge.mods.toml +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -40,6 +40,11 @@ authors = "${mod_authors}" #optional # The description text for the mod (multi line!) (#mandatory) description = '''${mod_description}''' + +# The [[mixins]] block allows you to declare your mixin config to FML so that it gets loaded. +[[mixins]] +config="${mod_id}.mixins.json" + # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. [[dependencies.${ mod_id }]] #optional # the modid of the dependency diff --git a/src/main/resources/allomancy.mixins.json b/src/main/resources/allomancy.mixins.json new file mode 100644 index 00000000..fabee772 --- /dev/null +++ b/src/main/resources/allomancy.mixins.json @@ -0,0 +1,12 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "com.legobmw99.allomancy.modules.extras.mixin", + "compatibilityLevel": "JAVA_21", + "mixins": ["BannerDFUMixin"], + "client": [], + "server": [], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file