-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # src/main/java/juuxel/woodsandmires/item/WamItems.java
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/main/java/juuxel/woodsandmires/item/FoodWithRemainderItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters