Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Setting itemstack amount to 0

Open JHarris12345 opened this issue 1 year ago • 3 comments

Expected behavior

In pre 1.21 if you create an item stack with amount 0 then it simply removes the item. But in 1.21 it throws an error. Is this ability to remove an item something that can return or is it gone for good? I use this method of setting the amount to 0 a lot for my "limited use" items that deplete after each use. So it's easy for me to just set the amount to currentUses - 1. Here's a screenshot of the error https://gyazo.com/19a00bb855851bcb4aeb99a951ff93b8

Observed/Actual behavior

It should remove the item (like it used to) and not throw an error

Steps/models to reproduce

Set an item's amount to 0

Plugin and Datapack List

N/A

Paper version

Any 1.21 ver

Other

No response

JHarris12345 avatar Sep 12 '24 18:09 JHarris12345

You can set amount to 0 on existing items, but you can't create new ones with amount 0, use https://jd.papermc.io/paper/1.21.1/org/bukkit/inventory/ItemStack.html#empty() if you need an empty item stack

masmc05 avatar Sep 12 '24 19:09 masmc05

It created an air item stack if you tried to make one with amount 0 in pre 1.21. I am just asking if it's possible to get this back in 1.21 as it was a nice feature and saves needing to change all the code xD

JHarris12345 avatar Sep 12 '24 19:09 JHarris12345

ItemStack type is immutable in vanilla, and the goal here is generally to confirm closer to vanilla archtypes here, especially with ItemMeta already having caused general issues around changing types, which will only get to become more fun as people dive into components for doing stuff

electronicboy avatar Sep 12 '24 19:09 electronicboy