EngineHub / WorldGuard

🛡️ Protect your Minecraft server and lets players claim areas
https://enginehub.org/worldguard/
Other
812 stars 528 forks source link

Fix ItemStack conversion on block place on MC 1.21 #2093

Closed lenis0012 closed 2 weeks ago

lenis0012 commented 2 weeks ago

This issue is present in 1.21 because some materials do not convert 1:1 to item types.
This throws an exception in the ItemStack constructor.
Example: WALL_TORCH is a valid block but not a valid item, only TORCH is a valid item.

So, use the item in hand instead, creating a copy with quantity set to 1, for issuing the use item event.


To reproduce: place a torch on the wall.

If a different solution is preferred that is fine too and this MR may be closed but I don't see an issue with using the item in hand as I believe it is only changed after the event has completed, so it will contain the item placed even if the quantity was 1.

lenis0012 commented 2 weeks ago

Related to #2089

wizjany commented 2 weeks ago

the quantity part shouldn't even be necessary, we only care about the item type to check the interaction mappings. and according to the javadocs, that should return the itemstack at the time of placement, so it shouldn't be consumed until after the event either.