From 53dd3bcfedf358adcf4c1ca2157caecf870d6409 Mon Sep 17 00:00:00 2001 From: flatkat Date: Sun, 22 Sep 2024 00:57:30 +0200 Subject: [PATCH 1/2] (broken for now) Testing to remake StewStack and adding toggability to the feature --- .../harmony/mixin/food/StewStack.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/symphony/harmony/mixin/food/StewStack.java b/src/main/java/dev/symphony/harmony/mixin/food/StewStack.java index 70be601..8e69a4a 100644 --- a/src/main/java/dev/symphony/harmony/mixin/food/StewStack.java +++ b/src/main/java/dev/symphony/harmony/mixin/food/StewStack.java @@ -1,7 +1,10 @@ package dev.symphony.harmony.mixin.food; + import dev.symphony.harmony.config.HarmonyConfig; +import net.fabricmc.fabric.api.item.v1.DefaultItemComponentEvents; +import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.FoodComponents; import net.minecraft.item.Item; import net.minecraft.item.Items; @@ -17,12 +20,22 @@ public class StewStack { // Would be nice if this was applied to all items with a specific custom item tag to facilitate mod compat. - @Redirect(method = "", slice = @Slice(from = @At(value = "CONSTANT", args = { - "stringValue=mushroom_stew"}, ordinal = 0)), at = @At( - value = "NEW", target = "(Lnet/minecraft/item/Item$Settings;)Lnet/minecraft/item/Item;", ordinal = 0)) - private static Item stacked_mushroom_stew(Item.Settings settings) { - return new Item((new Item.Settings()).maxCount(HarmonyConfig.StewStackSize).food(FoodComponents.MUSHROOM_STEW)); + //@Redirect(method = "", slice = @Slice(from = @At(value = "CONSTANT", args = { + // "stringValue=mushroom_stew"}, ordinal = 0)), at = @At( + // value = "NEW", target = "(Lnet/minecraft/item/Item$Settings;)Lnet/minecraft/item/Item;", ordinal = 0)) + //private static Item stacked_mushroom_stew(Item.Settings settings) { + // return new Item((new Item.Settings()).maxCount(HarmonyConfig.StewStackSize).food(FoodComponents.MUSHROOM_STEW)); + //} + private static void StewStackMethod(){ + if(HarmonyConfig.StewStackBool){ + DefaultItemComponentEvents.MODIFY.register(context -> { + context.modify(Items.MUSHROOM_STEW, builder -> { + builder.add(DataComponentTypes.MAX_STACK_SIZE, HarmonyConfig.StewStackSize); + }); + }); } +} + @Redirect(method = "", slice = @Slice(from = @At(value = "CONSTANT", args = { "stringValue=beetroot_soup"}, ordinal = 0)), at = @At( From 8358546ae5b482d7b6856b2b54c07018d54e9fe0 Mon Sep 17 00:00:00 2001 From: flatkat Date: Sun, 22 Sep 2024 01:27:07 +0200 Subject: [PATCH 2/2] Refactored and rewrote StewStack, now it's toggable -It is no longer a mixin (though uses mixins under the hood i think but still) (also now it has better mod compat out of the box bc of the use of DefaultItemComponentEvents instead of the previous method w Mixins) -Now StewStackBool finally works as intented --- .../java/dev/symphony/harmony/Harmony.java | 3 + .../dev/symphony/harmony/food/StewStack.java | 39 ++++++++++++ .../harmony/mixin/food/StewStack.java | 62 ------------------- src/main/resources/harmony.mixins.json | 1 - 4 files changed, 42 insertions(+), 63 deletions(-) create mode 100644 src/main/java/dev/symphony/harmony/food/StewStack.java delete mode 100644 src/main/java/dev/symphony/harmony/mixin/food/StewStack.java diff --git a/src/main/java/dev/symphony/harmony/Harmony.java b/src/main/java/dev/symphony/harmony/Harmony.java index b5a30ca..a97bbc0 100644 --- a/src/main/java/dev/symphony/harmony/Harmony.java +++ b/src/main/java/dev/symphony/harmony/Harmony.java @@ -6,6 +6,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static dev.symphony.harmony.food.StewStack.StewStackMethod; + public class Harmony implements ModInitializer { public static final String MOD_ID = "harmony"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); @@ -17,5 +19,6 @@ public static Identifier id (String path) { @Override public void onInitialize() { // be gay, do crime + StewStackMethod(); } } \ No newline at end of file diff --git a/src/main/java/dev/symphony/harmony/food/StewStack.java b/src/main/java/dev/symphony/harmony/food/StewStack.java new file mode 100644 index 0000000..29efa12 --- /dev/null +++ b/src/main/java/dev/symphony/harmony/food/StewStack.java @@ -0,0 +1,39 @@ +package dev.symphony.harmony.food; + +import dev.symphony.harmony.config.HarmonyConfig; +import net.fabricmc.fabric.api.item.v1.DefaultItemComponentEvents; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.item.Items; + +public class StewStack { + + // Would be nice if this was applied to all items with a specific custom item tag to facilitate mod compat. + public static void StewStackMethod(){ + if(HarmonyConfig.StewStackBool){ + + DefaultItemComponentEvents.MODIFY.register(context -> { + context.modify(Items.MUSHROOM_STEW, builder -> { + builder.add(DataComponentTypes.MAX_STACK_SIZE, HarmonyConfig.StewStackSize); + }); + }); + + DefaultItemComponentEvents.MODIFY.register(context -> { + context.modify(Items.BEETROOT_SOUP, builder -> { + builder.add(DataComponentTypes.MAX_STACK_SIZE, HarmonyConfig.StewStackSize); + }); + }); + + DefaultItemComponentEvents.MODIFY.register(context -> { + context.modify(Items.RABBIT_STEW, builder -> { + builder.add(DataComponentTypes.MAX_STACK_SIZE, HarmonyConfig.StewStackSize); + }); + }); + + DefaultItemComponentEvents.MODIFY.register(context -> { + context.modify(Items.SUSPICIOUS_STEW, builder -> { + builder.add(DataComponentTypes.MAX_STACK_SIZE, HarmonyConfig.StewStackSize); + }); + }); + } + } +} \ No newline at end of file diff --git a/src/main/java/dev/symphony/harmony/mixin/food/StewStack.java b/src/main/java/dev/symphony/harmony/mixin/food/StewStack.java deleted file mode 100644 index 8e69a4a..0000000 --- a/src/main/java/dev/symphony/harmony/mixin/food/StewStack.java +++ /dev/null @@ -1,62 +0,0 @@ -package dev.symphony.harmony.mixin.food; - - - -import dev.symphony.harmony.config.HarmonyConfig; -import net.fabricmc.fabric.api.item.v1.DefaultItemComponentEvents; -import net.minecraft.component.DataComponentTypes; -import net.minecraft.component.type.FoodComponents; -import net.minecraft.item.Item; -import net.minecraft.item.Items; -import net.minecraft.item.SuspiciousStewItem; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.Slice; - - - -@Mixin(Items.class) -public class StewStack { - - // Would be nice if this was applied to all items with a specific custom item tag to facilitate mod compat. - //@Redirect(method = "", slice = @Slice(from = @At(value = "CONSTANT", args = { - // "stringValue=mushroom_stew"}, ordinal = 0)), at = @At( - // value = "NEW", target = "(Lnet/minecraft/item/Item$Settings;)Lnet/minecraft/item/Item;", ordinal = 0)) - //private static Item stacked_mushroom_stew(Item.Settings settings) { - // return new Item((new Item.Settings()).maxCount(HarmonyConfig.StewStackSize).food(FoodComponents.MUSHROOM_STEW)); - //} - private static void StewStackMethod(){ - if(HarmonyConfig.StewStackBool){ - DefaultItemComponentEvents.MODIFY.register(context -> { - context.modify(Items.MUSHROOM_STEW, builder -> { - builder.add(DataComponentTypes.MAX_STACK_SIZE, HarmonyConfig.StewStackSize); - }); - }); - } -} - - - @Redirect(method = "", slice = @Slice(from = @At(value = "CONSTANT", args = { - "stringValue=beetroot_soup"}, ordinal = 0)), at = @At( - value = "NEW", target = "(Lnet/minecraft/item/Item$Settings;)Lnet/minecraft/item/Item;", ordinal = 0)) - private static Item stacked_beetroot_soup(Item.Settings settings) { - return new Item((new Item.Settings()).maxCount(HarmonyConfig.StewStackSize).food(FoodComponents.BEETROOT_SOUP)); - } - - @Redirect(method = "", slice = @Slice(from = @At(value = "CONSTANT", args = { - "stringValue=rabbit_stew"}, ordinal = 0)), at = @At( - value = "NEW", target = "(Lnet/minecraft/item/Item$Settings;)Lnet/minecraft/item/Item;", ordinal = 0)) - private static Item stacked_rabbit_stew(Item.Settings settings) { - return new Item((new Item.Settings()).maxCount(HarmonyConfig.StewStackSize).food(FoodComponents.RABBIT_STEW)); - } - - // Note: the rest of the stews come from the Item class, but the Suspicious Stews extend from the SuspiciousStewItem class - @Redirect(method = "", slice = @Slice(from = @At(value = "CONSTANT", args = { - "stringValue=suspicious_stew"}, ordinal = 0)), at = @At( - value = "NEW", target = "(Lnet/minecraft/item/Item$Settings;)Lnet/minecraft/item/SuspiciousStewItem;", ordinal = 0)) - private static SuspiciousStewItem stacked_suspicious_stew(Item.Settings settings) { - return new SuspiciousStewItem((new Item.Settings()).maxCount(HarmonyConfig.StewStackSize).food(FoodComponents.SUSPICIOUS_STEW)); - } - -} \ No newline at end of file diff --git a/src/main/resources/harmony.mixins.json b/src/main/resources/harmony.mixins.json index ce1ee0b..df8e9ff 100644 --- a/src/main/resources/harmony.mixins.json +++ b/src/main/resources/harmony.mixins.json @@ -4,7 +4,6 @@ "compatibilityLevel": "JAVA_21", "mixins": [ - "food.StewStack", "transportation.VehiclesMoveThroughLeaves" ],