From e718edf1dd382dddd5bfa6443c87ecbe1156c599 Mon Sep 17 00:00:00 2001 From: Thom van den Akker Date: Thu, 31 Oct 2024 18:53:47 +0100 Subject: [PATCH 1/3] Undone some of the previous tag work, brought code more in line with the cook rework (datagen was ran but no changes were necessary to json files) --- .../com/minecolonies/api/items/ModItems.java | 16 +++-- .../initializer/ModItemsInitializer.java | 70 ++++++------------- .../defaults/DefaultItemTagsProvider.java | 41 ++++++++--- .../com/minecolonies/core/items/ItemFood.java | 19 +---- 4 files changed, 64 insertions(+), 82 deletions(-) diff --git a/src/main/java/com/minecolonies/api/items/ModItems.java b/src/main/java/com/minecolonies/api/items/ModItems.java index 2281e7c5e13..39a0d11c1de 100755 --- a/src/main/java/com/minecolonies/api/items/ModItems.java +++ b/src/main/java/com/minecolonies/api/items/ModItems.java @@ -3,8 +3,6 @@ import com.minecolonies.core.items.ItemFood; import net.minecraft.world.item.Item; -import java.util.List; - /** * Class handling the registering of the mod items. *

@@ -119,11 +117,16 @@ public final class ModItems /** * Get a list of all possible food items. * - * @return a list of food items. + * @return an array of food items. */ - public static List getFoodItems() + public static Item[] getAllFoods() { - return List.of(cabochis, + return new Item[] { + milkyBread, + sugaryBread, + goldenBread, + chorusBread, + cabochis, cheddar_cheese, congee, cooked_rice, @@ -145,7 +148,8 @@ public static List getFoodItems() stuffed_pepper, stuffed_pita, sushi_roll, - tofu); + tofu + }; } /** diff --git a/src/main/java/com/minecolonies/apiimp/initializer/ModItemsInitializer.java b/src/main/java/com/minecolonies/apiimp/initializer/ModItemsInitializer.java index c2583f7a7fd..55d48aafadf 100755 --- a/src/main/java/com/minecolonies/apiimp/initializer/ModItemsInitializer.java +++ b/src/main/java/com/minecolonies/apiimp/initializer/ModItemsInitializer.java @@ -12,26 +12,20 @@ import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; -import net.minecraft.tags.TagKey; import net.minecraft.world.food.FoodProperties; import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ArmorMaterial; import net.minecraft.world.item.Item; -import net.minecraft.world.item.Item.Properties; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.common.DeferredSpawnEggItem; -import net.neoforged.neoforge.common.Tags; import net.neoforged.neoforge.registries.DeferredRegister; import net.neoforged.neoforge.registries.RegisterEvent; import java.util.EnumMap; import java.util.List; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Stream; import static com.minecolonies.api.blocks.decorative.AbstractBlockGate.IRON_GATE; import static com.minecolonies.api.blocks.decorative.AbstractBlockGate.WOODEN_GATE; @@ -153,53 +147,53 @@ public static void init(final Registry registry) ModItems.scanAnalyzer = new ItemScanAnalyzer("scan_analyzer", new Item.Properties()); // Tier 1 Food Items - ModItems.cheddar_cheese = registerFoodItem(1, ModJobs.CHEF_ID, (builder) -> builder.nutrition(4).saturationModifier(0.6F).build()); - ModItems.feta_cheese = registerFoodItem(1, ModJobs.CHEF_ID, (builder) -> builder.nutrition(4).saturationModifier(0.6F).build()); - ModItems.cooked_rice = registerFoodItem(1, ModJobs.CHEF_ID, builder -> builder.nutrition(4).saturationModifier(0.6F).usingConvertsTo(Items.BOWL).build()); - ModItems.tofu = registerFoodItem(1, ModJobs.CHEF_ID, builder -> builder.nutrition(4).saturationModifier(0.6F).build()); - ModItems.flatbread = registerFoodItem(1, ModJobs.BAKER_ID, Set.of(Tags.Items.FOODS_BREAD), builder -> builder.nutrition(4).saturationModifier(0.6F).build()); + ModItems.cheddar_cheese = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), ModJobs.CHEF_ID.getPath(), 1); + ModItems.feta_cheese = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), ModJobs.CHEF_ID.getPath(), 1); + ModItems.cooked_rice = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).usingConvertsTo(Items.BOWL).build()), ModJobs.CHEF_ID.getPath(), 1); + ModItems.tofu = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), ModJobs.CHEF_ID.getPath(), 1); + ModItems.flatbread = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), ModJobs.BAKER_ID.getPath(), 1); // Tier 2 Food Items - ModItems.manchet_bread = registerFoodItem(2, ModJobs.BAKER_ID, Set.of(Tags.Items.FOODS_BREAD), builder -> builder.nutrition(6).saturationModifier(1.0F).build()); - ModItems.lembas_scone = registerFoodItem(2, ModJobs.BAKER_ID, Set.of(Tags.Items.FOODS_BREAD), builder -> builder.nutrition(6).saturationModifier(1.0F).build()); - ModItems.muffin = registerFoodItem(2, ModJobs.BAKER_ID, Set.of(Tags.Items.FOODS_BREAD, Tags.Items.FOODS_CANDY), builder -> builder.nutrition(6).saturationModifier(1.0F).build()); - ModItems.pottage = registerFoodItem(2, ModJobs.CHEF_ID, Set.of(Tags.Items.FOODS_SOUP, Tags.Items.FOODS_VEGETABLE), builder -> builder.nutrition(6).saturationModifier(1.0F).usingConvertsTo(Items.BOWL).build()); - ModItems.pasta_plain = registerFoodItem(2, ModJobs.CHEF_ID, builder -> builder.nutrition(6).saturationModifier(1.0F).usingConvertsTo(Items.BOWL).build()); + ModItems.manchet_bread = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), ModJobs.BAKER_ID.getPath(), 2); + ModItems.lembas_scone = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), ModJobs.BAKER_ID.getPath(), 2); + ModItems.muffin = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), ModJobs.BAKER_ID.getPath(), 2); + ModItems.pottage = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).usingConvertsTo(Items.BOWL).build()), ModJobs.CHEF_ID.getPath(), 2); + ModItems.pasta_plain = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).usingConvertsTo(Items.BOWL).build()), ModJobs.CHEF_ID.getPath(), 2); // Tier 3 Food items - ModItems.hand_pie = registerFoodItem(3, ModJobs.CHEF_ID, Set.of(Tags.Items.FOODS_BREAD, Tags.Items.FOODS_CANDY), builder -> builder.nutrition(8).saturationModifier(1.2F).build()); + ModItems.hand_pie = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), ModJobs.CHEF_ID.getPath(), 3); // Cold Biomes // Tier 2 - ModItems.cabochis = registerFoodItem(2, ModJobs.CHEF_ID, Set.of(Tags.Items.FOODS_SOUP, Tags.Items.FOODS_VEGETABLE), builder -> builder.nutrition(6).saturationModifier(1.0F).usingConvertsTo(Items.BOWL).build()); + ModItems.cabochis = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).usingConvertsTo(Items.BOWL).build()), ModJobs.CHEF_ID.getPath(), 2); // Tier 3 - ModItems.lamb_stew = registerFoodItem(3, ModJobs.CHEF_ID, Set.of(Tags.Items.FOODS_SOUP, Tags.Items.FOODS_COOKED_MEAT), builder -> builder.nutrition(8).saturationModifier(1.2F).usingConvertsTo(Items.BOWL).build()); + ModItems.lamb_stew = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).usingConvertsTo(Items.BOWL).build()), ModJobs.CHEF_ID.getPath(), 3); // Hot Humid Biomes // Tier 2 - ModItems.rice_ball = registerFoodItem(2, ModJobs.CHEF_ID, builder -> builder.nutrition(6).saturationModifier(1.0F).build()); + ModItems.rice_ball = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), ModJobs.CHEF_ID.getPath(), 2); // Tier 3 - ModItems.sushi_roll = registerFoodItem(3, ModJobs.CHEF_ID, builder -> builder.nutrition(8).saturationModifier(1.2F).build()); + ModItems.sushi_roll = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), ModJobs.CHEF_ID.getPath(), 3); // Temperate Biomes // Tier 2 - ModItems.pasta_tomato = registerFoodItem(2, ModJobs.CHEF_ID, builder -> builder.nutrition(6).saturationModifier(1.0F).usingConvertsTo(Items.BOWL).build()); + ModItems.pasta_tomato = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).usingConvertsTo(Items.BOWL).build()), ModJobs.CHEF_ID.getPath(), 2); // Tier 3 - ModItems.eggplant_dolma = registerFoodItem(3, ModJobs.CHEF_ID, Set.of(Tags.Items.FOODS_VEGETABLE), builder -> builder.nutrition(8).saturationModifier(1.2F).build()); - ModItems.stuffed_pita = registerFoodItem(3, ModJobs.CHEF_ID, Set.of(Tags.Items.FOODS_BREAD, Tags.Items.FOODS_VEGETABLE), builder -> builder.nutrition(8).saturationModifier(1.2F).build()); + ModItems.eggplant_dolma = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), ModJobs.CHEF_ID.getPath(), 3); + ModItems.stuffed_pita = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), ModJobs.CHEF_ID.getPath(), 3); // Hot Dry Biomes // Tier 2 - ModItems.pepper_hummus = registerFoodItem(2, ModJobs.CHEF_ID, builder -> builder.nutrition(6).saturationModifier(1.0F).build()); + ModItems.pepper_hummus = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), ModJobs.CHEF_ID.getPath(), 2); // Tier 3 - ModItems.pita_hummus = registerFoodItem(3, ModJobs.CHEF_ID, builder -> builder.nutrition(8).saturationModifier(1.2F).build()); + ModItems.pita_hummus = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), ModJobs.CHEF_ID.getPath(), 3); // Require trading // Tier 2 - ModItems.congee = registerFoodItem(2, ModJobs.CHEF_ID, builder -> builder.nutrition(6).saturationModifier(1.0F).usingConvertsTo(Items.BOWL).build()); + ModItems.congee = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).usingConvertsTo(Items.BOWL).build()), ModJobs.CHEF_ID.getPath(), 2); // Tier 3 - ModItems.stew_trencher = registerFoodItem(3, ModJobs.CHEF_ID, Set.of(Tags.Items.FOODS_BREAD), builder -> builder.nutrition(8).saturationModifier(1.2F).build()); - ModItems.stuffed_pepper = registerFoodItem(3, ModJobs.CHEF_ID, Set.of(Tags.Items.FOODS_VEGETABLE), builder -> builder.nutrition(8).saturationModifier(1.2F).build()); + ModItems.stew_trencher = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), ModJobs.CHEF_ID.getPath(), 3); + ModItems.stuffed_pepper = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), ModJobs.CHEF_ID.getPath(), 3); // Just dough ModItems.muffin_dough = new Item((new Item.Properties())); @@ -449,22 +443,4 @@ public static void init(final Registry registry) 0 )); - public static ItemFood registerFoodItem(final int tier, final ResourceLocation worker, final Consumer foodPropertiesGenerator) - { - return registerFoodItem(tier, worker, Set.of(), foodPropertiesGenerator); - } - - public static ItemFood registerFoodItem( - final int tier, - final ResourceLocation worker, - final Set> foodTags, - final Consumer foodPropertiesGenerator) - { - final FoodProperties.Builder foodPropertiesBuilder = new FoodProperties.Builder(); - foodPropertiesGenerator.accept(foodPropertiesBuilder); - final Properties itemProperties = new Properties().food(foodPropertiesBuilder.build()); - - final List> tags = Stream.concat(Stream.of(Tags.Items.FOODS), foodTags.stream()).toList(); - return new ItemFood(itemProperties, worker.getPath(), tier, tags); - } } diff --git a/src/main/java/com/minecolonies/core/generation/defaults/DefaultItemTagsProvider.java b/src/main/java/com/minecolonies/core/generation/defaults/DefaultItemTagsProvider.java index 5719a8c87e9..3cd78cfa794 100644 --- a/src/main/java/com/minecolonies/core/generation/defaults/DefaultItemTagsProvider.java +++ b/src/main/java/com/minecolonies/core/generation/defaults/DefaultItemTagsProvider.java @@ -5,7 +5,6 @@ import com.minecolonies.api.items.ModItems; import com.minecolonies.api.items.ModTags; import com.minecolonies.api.util.constant.TagConstants; -import com.minecolonies.core.items.ItemFood; import net.minecraft.core.HolderLookup; import net.minecraft.data.PackOutput; import net.minecraft.data.tags.ItemTagsProvider; @@ -500,22 +499,42 @@ protected void addTags(final @NotNull HolderLookup.Provider provider) tag(ModTags.ignoreNBT) .addTag(ItemTags.BANNERS); - tag(Tags.Items.FOODS) - .add(ModItems.milkyBread, ModItems.sugaryBread, ModItems.goldenBread, ModItems.chorusBread); + tag(Tags.Items.FOODS).add(ModItems.getAllFoods()); tag(Tags.Items.FOODS_BREAD) - .add(ModItems.milkyBread, ModItems.sugaryBread, ModItems.goldenBread, ModItems.chorusBread); + .add(ModItems.milkyBread, + ModItems.sugaryBread, + ModItems.goldenBread, + ModItems.chorusBread, + ModItems.flatbread, + ModItems.hand_pie, + ModItems.lembas_scone, + ModItems.manchet_bread, + ModItems.muffin, + ModItems.stew_trencher, + ModItems.stuffed_pita); + + tag(Tags.Items.FOODS_CANDY) + .add(ModItems.hand_pie) + .add(ModItems.muffin); + + tag(Tags.Items.FOODS_COOKED_MEAT) + .add(ModItems.lamb_stew); tag(Tags.Items.FOODS_GOLDEN) .add(ModItems.goldenBread); - for (final ItemFood foodItem : ModItems.getFoodItems()) - { - for (final TagKey tagKey : foodItem.getTags()) - { - tag(tagKey).add(foodItem); - } - } + tag(Tags.Items.FOODS_SOUP) + .add(ModItems.cabochis) + .add(ModItems.lamb_stew) + .add(ModItems.pottage); + + tag(Tags.Items.FOODS_VEGETABLE) + .add(ModItems.cabochis) + .add(ModItems.eggplant_dolma) + .add(ModItems.pottage) + .add(ModItems.stuffed_pepper) + .add(ModItems.stuffed_pita); } @NotNull diff --git a/src/main/java/com/minecolonies/core/items/ItemFood.java b/src/main/java/com/minecolonies/core/items/ItemFood.java index 0663c3c59bd..c6b2c6d1346 100644 --- a/src/main/java/com/minecolonies/core/items/ItemFood.java +++ b/src/main/java/com/minecolonies/core/items/ItemFood.java @@ -3,7 +3,6 @@ import com.minecolonies.api.items.IMinecoloniesFoodItem; import com.minecolonies.api.util.constant.TranslationConstants; import net.minecraft.network.chat.Component; -import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; @@ -27,11 +26,6 @@ public class ItemFood extends Item implements IMinecoloniesFoodItem */ private final int tier; - /** - * A list of food tags for the item. - */ - private final List> tags; - /** * Creates a new food item. * @@ -39,12 +33,11 @@ public class ItemFood extends Item implements IMinecoloniesFoodItem * @param producer the key for the worker that produces it. * @param tier the nutrition tier. */ - public ItemFood(@NotNull final Properties builder, final String producer, final int tier, final List> tags) + public ItemFood(@NotNull final Properties builder, final String producer, final int tier) { super(builder); this.producer = producer; this.tier = tier; - this.tags = tags; } @Override @@ -59,14 +52,4 @@ public int getTier() { return this.tier; } - - /** - * Get all food tags for the given item. - * - * @return the list of food tags. - */ - public List> getTags() - { - return tags; - } } From 5cc490e6daf6ae2c86cda69bf0ae0ae72baf96a9 Mon Sep 17 00:00:00 2001 From: Thom van den Akker Date: Sun, 17 Nov 2024 13:56:03 +0100 Subject: [PATCH 2/3] Fixes --- src/main/java/com/minecolonies/api/items/ModItems.java | 6 ++++++ src/main/java/com/minecolonies/core/items/ItemFood.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/minecolonies/api/items/ModItems.java b/src/main/java/com/minecolonies/api/items/ModItems.java index c3e9d04d987..010e69e6a06 100755 --- a/src/main/java/com/minecolonies/api/items/ModItems.java +++ b/src/main/java/com/minecolonies/api/items/ModItems.java @@ -183,6 +183,12 @@ public static Item[] getAllIngredients() public static Item[] getAllFoods() { return new Item[] { + // Breads + milkyBread, + sugaryBread, + goldenBread, + chorusBread, + // Tier 1 Food cheddar_cheese, feta_cheese, diff --git a/src/main/java/com/minecolonies/core/items/ItemFood.java b/src/main/java/com/minecolonies/core/items/ItemFood.java index c3b0b02450a..c540bc57692 100644 --- a/src/main/java/com/minecolonies/core/items/ItemFood.java +++ b/src/main/java/com/minecolonies/core/items/ItemFood.java @@ -27,7 +27,7 @@ public class ItemFood extends Item implements IMinecoloniesFoodItem * @param builder the item properties to use. * @param tier the nutrition tier. */ - public ItemFood(@NotNull final Properties builder, final String producer, final int tier) + public ItemFood(@NotNull final Properties builder, final int tier) { super(builder); this.tier = tier; From 7de777bed3d86fd296684c66fc3bba8abd8e3df1 Mon Sep 17 00:00:00 2001 From: Thom van den Akker Date: Sun, 24 Nov 2024 12:01:11 +0100 Subject: [PATCH 3/3] Remove breads --- src/main/java/com/minecolonies/api/items/ModItems.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/minecolonies/api/items/ModItems.java b/src/main/java/com/minecolonies/api/items/ModItems.java index 010e69e6a06..c3e9d04d987 100755 --- a/src/main/java/com/minecolonies/api/items/ModItems.java +++ b/src/main/java/com/minecolonies/api/items/ModItems.java @@ -183,12 +183,6 @@ public static Item[] getAllIngredients() public static Item[] getAllFoods() { return new Item[] { - // Breads - milkyBread, - sugaryBread, - goldenBread, - chorusBread, - // Tier 1 Food cheddar_cheese, feta_cheese,