PaperMC / Paper

The most widely used, high performance Minecraft server that aims to fix gameplay and mechanics inconsistencies
https://papermc.io/
Other
9.39k stars 2.2k forks source link

delegate ItemStack #10852

Closed Machine-Maker closed 3 weeks ago

Machine-Maker commented 1 month ago

This essentially removes API-only itemstacks without changing ItemStack to an interface, that will come later.

Just adds a field in api-ItemStack that should always be a CraftItemStack which the api-ItemStack will wrap around. CraftItemStack has to override any methods on api-ItemStack that use this craftDelegate to avoid recursion loops.


Download the paperclip jar for this pull request: paper-10852.zip

Machine-Maker commented 1 month ago

It's possible that ItemStack#equals and ItemStack#hashCode should also directly delegate to a craftitemstack. I think that's probably most correct.

Machine-Maker commented 1 month ago

This doesn't handle empty itemstack (ItemStack#empty) which are still full api stack without server side equivalent and will throw a NPE for most methods.

I think I should just be able to change empty to return ItemStack.create(Material.AIR). It'd have a stack size of 1 however, should I instead add a bridge method to create a truly empty stack? just by returning a copy of nms-ItemStack.EMPTY?

Lulu13022002 commented 1 month ago

Another issue is that asNMSCopy doesn't accept null itemstack anymore so doing /clear for example throw a NPE too via the PrepareItemCraftEvent.