Return the empty container when eating stacked food with containers

This commit is contained in:
Sollace 2024-04-05 23:41:32 +01:00
parent 34bdd7f135
commit 7140ce6d0e
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB

View file

@ -4,8 +4,10 @@ import java.util.Optional;
import net.minecraft.advancement.criterion.Criteria;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsage;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.stat.Stats;
import net.minecraft.util.UseAction;
@ -29,7 +31,16 @@ public class ConsumableItem extends Item {
serverPlayerEntity.incrementStat(Stats.USED.getOrCreateStat(this));
}
return stack.isEmpty() ? Optional.ofNullable(getRecipeRemainder()).map(Item::getDefaultStack).orElse(ItemStack.EMPTY) : stack;
if (stack.isEmpty()) {
return stack.isEmpty() ? Optional.ofNullable(getRecipeRemainder()).map(Item::getDefaultStack).orElse(ItemStack.EMPTY) : stack;
}
if (user instanceof PlayerEntity player) {
return Optional.ofNullable(getRecipeRemainder()).map(Item::getDefaultStack).map(remainder -> {
return ItemUsage.exchangeStack(stack, player, remainder);
}).orElse(stack);
}
return stack;
}
@Override