Skip to content

Commit

Permalink
Merge branch '1.19b' into 1.20a
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Jul 21, 2023
2 parents ff1f848 + a92e762 commit 8b86e21
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/main/java/juuxel/woodsandmires/item/FoodWithRemainderItem.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion src/main/java/juuxel/woodsandmires/item/WamItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 8b86e21

Please sign in to comment.