Skip to content

Commit

Permalink
Undone some of the previous tag work, brought code more in line with …
Browse files Browse the repository at this point in the history
…the cook rework (datagen was ran but no changes were necessary to json files)
  • Loading branch information
Thodor12 committed Oct 31, 2024
1 parent d222925 commit e718edf
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 82 deletions.
16 changes: 10 additions & 6 deletions src/main/java/com/minecolonies/api/items/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
Expand Down Expand Up @@ -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<ItemFood> getFoodItems()
public static Item[] getAllFoods()
{
return List.of(cabochis,
return new Item[] {
milkyBread,
sugaryBread,
goldenBread,
chorusBread,
cabochis,
cheddar_cheese,
congee,
cooked_rice,
Expand All @@ -145,7 +148,8 @@ public static List<ItemFood> getFoodItems()
stuffed_pepper,
stuffed_pita,
sushi_roll,
tofu);
tofu
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -153,53 +147,53 @@ public static void init(final Registry<Item> 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()));
Expand Down Expand Up @@ -449,22 +443,4 @@ public static void init(final Registry<Item> registry)
0
));

public static ItemFood registerFoodItem(final int tier, final ResourceLocation worker, final Consumer<FoodProperties.Builder> foodPropertiesGenerator)
{
return registerFoodItem(tier, worker, Set.of(), foodPropertiesGenerator);
}

public static ItemFood registerFoodItem(
final int tier,
final ResourceLocation worker,
final Set<TagKey<Item>> foodTags,
final Consumer<FoodProperties.Builder> foodPropertiesGenerator)
{
final FoodProperties.Builder foodPropertiesBuilder = new FoodProperties.Builder();
foodPropertiesGenerator.accept(foodPropertiesBuilder);
final Properties itemProperties = new Properties().food(foodPropertiesBuilder.build());

final List<TagKey<Item>> tags = Stream.concat(Stream.of(Tags.Items.FOODS), foodTags.stream()).toList();
return new ItemFood(itemProperties, worker.getPath(), tier, tags);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Item> 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
Expand Down
19 changes: 1 addition & 18 deletions src/main/java/com/minecolonies/core/items/ItemFood.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,24 +26,18 @@ public class ItemFood extends Item implements IMinecoloniesFoodItem
*/
private final int tier;

/**
* A list of food tags for the item.
*/
private final List<TagKey<Item>> tags;

/**
* Creates a new food item.
*
* @param builder the item properties to use.
* @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<TagKey<Item>> 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
Expand All @@ -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<TagKey<Item>> getTags()
{
return tags;
}
}

0 comments on commit e718edf

Please sign in to comment.