From 2d546382a40b8ada67e5ab57ea4e06543176cb74 Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Fri, 21 Jul 2023 18:29:26 +0300 Subject: [PATCH 1/2] Fix pine cone jam not giving back the bottle after eating --- .../item/FoodWithRemainderItem.java | 32 +++++++++++++++++++ .../juuxel/woodsandmires/item/WamItems.java | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/main/java/juuxel/woodsandmires/item/FoodWithRemainderItem.java 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..54e7007 --- /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 = getRecipeRemainder(stack); + 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 5fc2037..9890d00 100644 --- a/src/main/java/juuxel/woodsandmires/item/WamItems.java +++ b/src/main/java/juuxel/woodsandmires/item/WamItems.java @@ -12,7 +12,7 @@ public final class WamItems { public static final Item PINE_BOAT = register("pine_boat", new WamBoatItem(WamBoat.PINE, new Item.Settings().group(ItemGroup.TRANSPORTATION))); public static final Item PINE_CONE = register("pine_cone", new Item(new Item.Settings().group(ItemGroup.MATERIALS))); - 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() .group(ItemGroup.FOOD) .recipeRemainder(Items.GLASS_BOTTLE) From 576041fa73f1da74d4cb012ca265426ec42568a5 Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Fri, 21 Jul 2023 18:54:30 +0300 Subject: [PATCH 2/2] Use getRecipeRemainder on stack instead of item --- .../java/juuxel/woodsandmires/item/FoodWithRemainderItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/juuxel/woodsandmires/item/FoodWithRemainderItem.java b/src/main/java/juuxel/woodsandmires/item/FoodWithRemainderItem.java index 54e7007..cd09d0c 100644 --- a/src/main/java/juuxel/woodsandmires/item/FoodWithRemainderItem.java +++ b/src/main/java/juuxel/woodsandmires/item/FoodWithRemainderItem.java @@ -13,7 +13,7 @@ public FoodWithRemainderItem(Settings settings) { @Override public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { - var remainder = getRecipeRemainder(stack); + var remainder = stack.getRecipeRemainder(); super.finishUsing(stack, world, user); // If the slot is empty, we can safely insert the empty bottle there.