Skip to content

Commit

Permalink
Don't eat the bowls! (#10448)
Browse files Browse the repository at this point in the history
Port Don't gobble bowls #10322
Fix several food items that use bowls in their recipes not returning them when eaten.
  • Loading branch information
uecasm authored Nov 17, 2024
1 parent d38eb7d commit 271ddc2
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
},
{
"id": "minecraft:beetroot"
},
{
"id": "minecraft:bowl"
}
],
"intermediate": "minecraft:air",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
},
{
"id": "minecraft:mutton"
},
{
"id": "minecraft:bowl"
}
],
"intermediate": "minecraft:air",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
},
{
"id": "minecolonies:soysauce"
},
{
"id": "minecraft:bowl"
}
],
"intermediate": "minecraft:air",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
},
{
"item": "minecraft:carrot"
},
{
"item": "minecraft:bowl"
}
],
"result": {
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/minecolonies/api/util/FoodUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
import com.minecolonies.core.tileentities.TileEntityRack;
import net.minecraft.core.BlockPos;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.HoneyBottleItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;

import javax.annotation.Nullable;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;

Expand Down Expand Up @@ -263,4 +266,36 @@ public static int getMinFoodDiversityRequirement(final int buildingLevel)
{
return buildingLevel;
}

/**
* Update stacks for consuming a food (does not apply the actual nutrition).
* @param foodStack the food stack being eaten (will be modified!).
* @param citizen the citizen doing the eating.
* @return the leftover item (e.g. bottle, bowl), or an empty stack.
*/
public static ItemStack consumeFoodStack(final ItemStack foodStack,
final AbstractEntityCitizen citizen)
{
final FoodProperties food = foodStack.getFoodProperties(citizen);
if (food != null)
{
final ItemStack consumedStack = foodStack.finishUsingItem(citizen.level(), citizen);
final Optional<ItemStack> returned = food.usingConvertsTo();
if (returned.isPresent())
{
return returned.get().copy();
}
else if (foodStack.getItem() instanceof HoneyBottleItem)
{
// Special handling because vanilla doesn't use usingConvertsTo since it's stackable
return new ItemStack(Items.GLASS_BOTTLE);
}
else if (consumedStack.getItem() != foodStack.getItem())
{
return consumedStack;
}
}

return ItemStack.EMPTY;
}
}
20 changes: 9 additions & 11 deletions src/main/java/com/minecolonies/api/util/ItemStackUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.decoration.ArmorStand;
import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.*;
Expand Down Expand Up @@ -883,25 +882,24 @@ public static Set<ItemStack> allItemsPlusInventory(@NotNull final Player player)
*
* @param foodStack the itemstack of food.
* @param citizen the citizen entity.
* @param inventory optional inventory to insert stack into if not citizen.
* @param player optional player providing the food.
*/
public static void consumeFood(final ItemStack foodStack, final AbstractEntityCitizen citizen, final Inventory inventory)
public static void consumeFood(final ItemStack foodStack, final AbstractEntityCitizen citizen, @Nullable final Player player)
{
final ICitizenData citizenData = citizen.getCitizenData();
ItemStack itemUseReturn = foodStack.finishUsingItem(citizen.level(), citizen);
final double satIncrease = FoodUtils.getFoodValue(foodStack, citizen);
ItemStack itemUseReturn = FoodUtils.consumeFoodStack(foodStack, citizen);

citizenData.increaseSaturation(satIncrease);

// Special handling for these as those are stackable + have a return per item.
if (foodStack.getItem() instanceof HoneyBottleItem)
if (player != null && player.hasInfiniteMaterials())
{
itemUseReturn = new ItemStack(Items.GLASS_BOTTLE);
itemUseReturn = ItemStack.EMPTY;
}

if (!itemUseReturn.isEmpty() && itemUseReturn.getItem() != foodStack.getItem())
citizenData.increaseSaturation(satIncrease);

if (!itemUseReturn.isEmpty())
{
if (citizenData.getInventory().isFull() || (inventory != null && !inventory.add(itemUseReturn)))
if (citizenData.getInventory().isFull() || (player != null && !player.getInventory().add(itemUseReturn)))
{
InventoryUtils.spawnItemStack(
citizen.level(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ public static void init(final Registry<Item> registry)
ModItems.tofu = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.flatbread = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.cheese_ravioli = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.chicken_broth = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.chicken_broth = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.meat_ravioli = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.mint_jelly = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.mint_tea = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.polenta = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.potato_soup = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.polenta = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.potato_soup = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.veggie_ravioli = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.yogurt = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);

Expand All @@ -177,22 +177,22 @@ public static void init(final Registry<Item> registry)
ModItems.apple_pie = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), 2);
ModItems.plain_cheesecake = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), 2);
ModItems.baked_salmon = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), 2);
ModItems.eggdrop_soup = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), 2);
ModItems.eggdrop_soup = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).usingConvertsTo(Items.BOWL).saturationModifier(1.0F).build()), 2);
ModItems.fish_n_chips = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), 2);
ModItems.pierogi = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), 2);
ModItems.veggie_soup = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), 2);
ModItems.yogurt_with_berries = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), 2);
ModItems.veggie_soup = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(6).saturationModifier(1.0F).build()), 2);
ModItems.yogurt_with_berries = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(6).saturationModifier(1.0F).build()), 2);

// Tier 3 Food items
ModItems.hand_pie = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), 3);
ModItems.mintchoco_cheesecake = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), 3);
ModItems.borscht = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), 3);
ModItems.borscht = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(8).saturationModifier(1.2F).build()), 3);
ModItems.schnitzel = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), 3);
ModItems.steak_dinner = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), 3);

// Cold Biomes
// Tier 1
ModItems.squash_soup = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.squash_soup = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(4).saturationModifier(0.6F).build()), 1);
// Tier 2
ModItems.cabochis = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(6).saturationModifier(1.0F).build()), 2);
ModItems.veggie_quiche = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), 2);
Expand All @@ -202,17 +202,17 @@ public static void init(final Registry<Item> registry)

// Hot Humid Biomes
// Tier 1
ModItems.pea_soup = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.pea_soup = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(4).saturationModifier(0.6F).build()), 1);
// Tier 2
ModItems.rice_ball = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), 2);
ModItems.mutton_dinner = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), 3);
// Tier 3
ModItems.sushi_roll = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), 3);
ModItems.ramen = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), 3);
ModItems.ramen = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(8).saturationModifier(1.2F).build()), 3);

// Temperate Biomes
// Tier 1
ModItems.corn_chowder = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.corn_chowder = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(4).saturationModifier(0.6F).build()), 1);
ModItems.tortillas = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(4).saturationModifier(0.6F).build()), 1);
// Tier 2
ModItems.pasta_tomato = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(6).saturationModifier(1.0F).build()), 2);
Expand All @@ -230,12 +230,12 @@ public static void init(final Registry<Item> registry)
ModItems.kebab = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), 1);
// Tier 3
ModItems.pita_hummus = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), 3);
ModItems.spicy_eggplant = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), 3);
ModItems.spicy_eggplant = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(8).saturationModifier(1.2F).build()), 3);

// Require trading
// Tier 2
ModItems.congee = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(6).saturationModifier(1.0F).build()), 2);
ModItems.kimchi = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(6).saturationModifier(1.0F).build()), 2);
ModItems.kimchi = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().usingConvertsTo(Items.BOWL).nutrition(6).saturationModifier(1.0F).build()), 2);
// Tier 3
ModItems.stew_trencher = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), 3);
ModItems.stuffed_pepper = new ItemFood((new Item.Properties()).food(new FoodProperties.Builder().nutrition(8).saturationModifier(1.2F).build()), 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@
import com.minecolonies.core.network.messages.server.colony.OpenInventoryMessage;
import com.minecolonies.core.util.TeleportHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.syncher.EntityDataAccessor;
Expand All @@ -86,9 +84,6 @@
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.ai.goal.GoalSelector;
import net.minecraft.world.entity.ai.goal.InteractGoal;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
Expand All @@ -99,15 +94,10 @@
import net.minecraft.world.item.ShieldItem;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.scores.PlayerTeam;
import net.minecraft.world.scores.Team;
import net.neoforged.neoforge.common.CommonHooks;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.entity.living.LivingShieldBlockEvent;
import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.network.PacketDistributor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -583,7 +573,7 @@ private void childFoodInteraction(final ItemStack usedStack, final Player player

playSound(SoundEvents.GENERIC_EAT, 1.5f, (float) SoundUtils.getRandomPitch(getRandom()));
new ItemParticleEffectMessage(usedStack.copy(), getX(), getY(), getZ(), getXRot(), getYRot(), getEyeHeight()).sendToTrackingEntity(this);
ItemStackUtils.consumeFood(usedStack, this, player.getInventory());
ItemStackUtils.consumeFood(usedStack, this, player);
}
}
else
Expand Down Expand Up @@ -618,7 +608,7 @@ private void eatFoodInteraction(final ItemStack usedStack, final Player player,
{
citizenData.getCitizenFoodHandler().addLastEaten(usedStack.getItem());
}
ItemStackUtils.consumeFood(usedStack, this, player.getInventory());
ItemStackUtils.consumeFood(usedStack, this, player);
}

interactionCooldown = 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ private InteractionResult directPlayerInteraction(final Player player, final Int
{
playSound(SoundEvents.GENERIC_EAT, 1.5f, (float) SoundUtils.getRandomPitch(getRandom()));
new ItemParticleEffectMessage(usedStack.copy(), getX(), getY(), getZ(), getXRot(), getYRot(), getEyeHeight()).sendToTrackingEntity(this);
ItemStackUtils.consumeFood(usedStack, this, player.getInventory());
ItemStackUtils.consumeFood(usedStack, this, player);
MessageUtils.forCitizen(this, MESSAGE_INTERACTION_VISITOR_FOOD).sendTo(player);
}
return InteractionResult.CONSUME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ private void buildOtherItems(@NotNull final RecipeOutput consumer)
.requires(ModBlocks.blockNetherPepper)
.requires(ModBlocks.blockOnion)
.requires(Items.CARROT)
.requires(Items.BOWL)
.unlockedBy("has_nether_pepper", has(ModBlocks.blockNetherPepper))
.save(consumer, new ResourceLocation(MOD_ID, "kimchi"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ protected void registerRecipes(@NotNull final Consumer<CustomRecipeBuilder> cons
new ItemStorage(new ItemStack(Items.POTATO)),
new ItemStorage(new ItemStack(Items.BROWN_MUSHROOM)),
new ItemStorage(new ItemStack(ModBlocks.blockCabbage)),
new ItemStorage(new ItemStack(Items.MUTTON))))
new ItemStorage(new ItemStack(Items.MUTTON)),
new ItemStorage(new ItemStack(Items.BOWL))))
.result(new ItemStack(ModItems.lamb_stew))
.showTooltip(true)
.minBuildingLevel(4)
Expand All @@ -148,7 +149,8 @@ protected void registerRecipes(@NotNull final Consumer<CustomRecipeBuilder> cons
new ItemStorage(new ItemStack(ModItems.chicken_broth)),
new ItemStorage(new ItemStack(Items.POTATO)),
new ItemStorage(new ItemStack(Items.BEETROOT)),
new ItemStorage(new ItemStack(Items.BEETROOT))
new ItemStorage(new ItemStack(Items.BEETROOT)),
new ItemStorage(new ItemStack(Items.BOWL))
))
.result(new ItemStack(ModItems.borscht, 2))
.showTooltip(true)
Expand All @@ -174,7 +176,8 @@ protected void registerRecipes(@NotNull final Consumer<CustomRecipeBuilder> cons
new ItemStorage(new ItemStack(ModBlocks.blockGarlic)),
new ItemStorage(new ItemStack(ModBlocks.blockOnion)),
new ItemStorage(new ItemStack(ModItems.raw_noodle)),
new ItemStorage(new ItemStack(ModItems.soysauce))
new ItemStorage(new ItemStack(ModItems.soysauce)),
new ItemStorage(new ItemStack(Items.BOWL))
))
.result(new ItemStack(ModItems.ramen, 1))
.showTooltip(true)
Expand Down

0 comments on commit 271ddc2

Please sign in to comment.