diff --git a/src/main/java/juuxel/woodsandmires/item/FoodWithRemainderItem.java b/src/main/java/juuxel/woodsandmires/item/FoodWithRemainderItem.java new file mode 100644 index 0000000..cd09d0c --- /dev/null +++ b/src/main/java/juuxel/woodsandmires/item/FoodWithRemainderItem.java @@ -0,0 +1,32 @@ +package juuxel.woodsandmires.item; + +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class FoodWithRemainderItem extends Item { + public FoodWithRemainderItem(Settings settings) { + super(settings); + } + + @Override + public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { + var remainder = stack.getRecipeRemainder(); + super.finishUsing(stack, world, user); + + // If the slot is empty, we can safely insert the empty bottle there. + if (stack.isEmpty()) { + return remainder; + } + + // Otherwise, we have to insert it to the inventory if not in creative mode. + if (user instanceof PlayerEntity player && !player.getAbilities().creativeMode) { + player.getInventory().offerOrDrop(remainder); + } + + // Return the leftover food. + return stack; + } +} diff --git a/src/main/java/juuxel/woodsandmires/item/WamItems.java b/src/main/java/juuxel/woodsandmires/item/WamItems.java index f14e838..08c2dfa 100644 --- a/src/main/java/juuxel/woodsandmires/item/WamItems.java +++ b/src/main/java/juuxel/woodsandmires/item/WamItems.java @@ -13,7 +13,7 @@ public final class WamItems { public static final Item PINE_BOAT = register("pine_boat", new WamBoatItem(false, WamBoat.PINE, new Item.Settings())); public static final Item PINE_CHEST_BOAT = register("pine_chest_boat", new WamBoatItem(true, WamBoat.PINE, new Item.Settings())); public static final Item PINE_CONE = register("pine_cone", new Item(new Item.Settings())); - public static final Item PINE_CONE_JAM = register("pine_cone_jam", new Item( + public static final Item PINE_CONE_JAM = register("pine_cone_jam", new FoodWithRemainderItem( new Item.Settings() .recipeRemainder(Items.GLASS_BOTTLE) .food(new FoodComponent.Builder().hunger(3).saturationModifier(0.25f).build())