From 287453860303c1e26e6d0fa2a189400da0e62704 Mon Sep 17 00:00:00 2001 From: PTOM76 <58260965+PTOM76@users.noreply.github.com> Date: Sat, 31 Aug 2024 13:16:29 +0900 Subject: [PATCH] add DataFixer --- build.gradle | 4 ++++ gradle.properties | 4 ++-- .../ItemStackComponentizationFixMixin.java | 21 +++++++++++++++++++ src/main/resources/fabric.mod.json | 1 + src/main/resources/storagebox.accesswidener | 2 ++ src/main/resources/storagebox.mixins.json | 3 ++- 6 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/main/java/net/pitan76/storagebox/mixin/ItemStackComponentizationFixMixin.java create mode 100644 src/main/resources/storagebox.accesswidener diff --git a/build.gradle b/build.gradle index d30c6ac..531e163 100644 --- a/build.gradle +++ b/build.gradle @@ -22,6 +22,10 @@ repositories { maven { url "https://maven.shedaniel.me/" } } +loom { + accessWidenerPath = file("src/main/resources/storagebox.accesswidener") +} + dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" diff --git a/gradle.properties b/gradle.properties index 369a892..4895242 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,8 +9,8 @@ loader_version=0.15.11 fabric_version=0.100.4+1.21 # Mod Properties -mod_version = 1.4.0-1.21 +mod_version = 1.4.2-1.21 maven_group = net.pitan76 archives_base_name = storagebox -changelog = Port to 1.21 \ No newline at end of file +changelog = DataFixer???????? \ No newline at end of file diff --git a/src/main/java/net/pitan76/storagebox/mixin/ItemStackComponentizationFixMixin.java b/src/main/java/net/pitan76/storagebox/mixin/ItemStackComponentizationFixMixin.java new file mode 100644 index 0000000..9c63d3f --- /dev/null +++ b/src/main/java/net/pitan76/storagebox/mixin/ItemStackComponentizationFixMixin.java @@ -0,0 +1,21 @@ +package net.pitan76.storagebox.mixin; + +import com.mojang.serialization.Dynamic; +import net.minecraft.datafixer.fix.ItemStackComponentizationFix; +import net.pitan76.storagebox.StorageBoxMod; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ItemStackComponentizationFix.class) +public class ItemStackComponentizationFixMixin { + @Inject(method = "fixStack", at = @At("TAIL")) + private static void storagebox$fixStack(ItemStackComponentizationFix.StackData data, Dynamic dynamic, CallbackInfo ci) { + if (data.itemEquals("storagebox:storagebox")) { + data.moveToComponent("StorageSize", StorageBoxMod.id("size").toString()); + data.moveToComponent("StorageAuto", StorageBoxMod.id("auto").toString()); + data.moveToComponent("StorageItemData", StorageBoxMod.id("item_data").toString()); + } + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ee16799..01d8190 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -34,6 +34,7 @@ "environment": "*" } ], + "accessWidener": "storagebox.accesswidener", "depends": { "fabricloader": "*", "fabric": "*", diff --git a/src/main/resources/storagebox.accesswidener b/src/main/resources/storagebox.accesswidener new file mode 100644 index 0000000..f729d37 --- /dev/null +++ b/src/main/resources/storagebox.accesswidener @@ -0,0 +1,2 @@ +accessWidener v1 named +accessible class net/minecraft/datafixer/fix/ItemStackComponentizationFix$StackData \ No newline at end of file diff --git a/src/main/resources/storagebox.mixins.json b/src/main/resources/storagebox.mixins.json index 5c48b77..0a34347 100644 --- a/src/main/resources/storagebox.mixins.json +++ b/src/main/resources/storagebox.mixins.json @@ -4,8 +4,9 @@ "package": "net.pitan76.storagebox.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ + "ItemEntityAccessor", "ItemPickupMixin", - "ItemEntityAccessor" + "ItemStackComponentizationFixMixin" ], "injectors": { "defaultRequire": 1