Skip to content

Commit

Permalink
Don't gobble bowls (#10322)
Browse files Browse the repository at this point in the history
Don't eat a whole stack of food bowls at once.
  • Loading branch information
uecasm authored Oct 13, 2024
1 parent d98ba43 commit 6ea498a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/minecolonies/api/util/ItemStackUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.minecolonies.api.items.CheckedNbtKey;
import com.minecolonies.api.items.ModItems;
import com.minecolonies.api.items.ModTags;
import com.minecolonies.core.items.ItemBowlFood;
import com.minecolonies.core.util.AdvancementUtils;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -948,6 +949,10 @@ public static void consumeFood(final ItemStack foodStack, final AbstractEntityCi
{
itemUseReturn = new ItemStack(Items.GLASS_BOTTLE);
}
else if (foodStack.getItem() instanceof ItemBowlFood)
{
itemUseReturn = new ItemStack(Items.BOWL);
}

if (!itemUseReturn.isEmpty() && itemUseReturn.getItem() != foodStack.getItem())
{
Expand Down
34 changes: 32 additions & 2 deletions src/main/java/com/minecolonies/core/items/ItemBowlFood.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.minecolonies.core.items;

import com.minecolonies.api.items.IMinecoloniesFoodItem;
import com.minecolonies.api.util.ItemStackUtils;
import com.minecolonies.api.util.constant.TranslationConstants;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.BowlFoodItem;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
Expand All @@ -15,7 +19,7 @@
/**
* A custom item class for bowl food items.
*/
public class ItemBowlFood extends BowlFoodItem implements IMinecoloniesFoodItem
public class ItemBowlFood extends Item implements IMinecoloniesFoodItem
{
/**
* The food tier.
Expand All @@ -34,6 +38,32 @@ public ItemBowlFood(@NotNull final Properties builder, final int tier)
this.tier = tier;
}

@NotNull
@Override
public ItemStack finishUsingItem(@NotNull final ItemStack stack, @NotNull final Level level, @NotNull final LivingEntity entity)
{
// implementation of this is deliberately similar to HoneyBottleItem; in particular it only
// gives extra drops to Players because citizens eating food are dealt with by the caller.

final ItemStack bowl = new ItemStack(Items.BOWL);

final ItemStack remainder = super.finishUsingItem(stack, level, entity);
if (ItemStackUtils.isEmpty(remainder))
{
return bowl;
}

if (entity instanceof final Player player && !player.getAbilities().instabuild)
{
if (!player.getInventory().add(bowl))
{
player.drop(bowl, false);
}
}

return stack;
}

@Override
public void appendHoverText(@NotNull final ItemStack stack, @Nullable final Level worldIn, @NotNull final List<Component> tooltip, @NotNull final TooltipFlag flagIn)
{
Expand Down

0 comments on commit 6ea498a

Please sign in to comment.