GlowstoneMC / Glowstone

A fast, customizable and compatible open source server for Minecraft: Java Edition
https://glowstone.net
Other
1.88k stars 271 forks source link

Sugar Cane item is not consumed on placement #1012

Closed heisluft closed 5 years ago

heisluft commented 5 years ago

When I plant sugar canes the stack size decreases as it should, but only client-side. After "running-out-of" Sugar canes, rightclicking dirt / sand next to water still plants sugar canes. Clicking on the "empty slot" gives. Attachment contains visual proof

Proof (Might not have finished uploading)

mastercoms commented 5 years ago

I believe the sugar cane item, which is used to place sugar cane blocks, is not implemented. So although the correct process is replicated client side, it is not replicated on the server and thus there is actually no consumption going on. Or, the placement might be implemented, but not the consumption.

heisluft commented 5 years ago

I can look into it and make a pr as soon as I get to do it

jhg023 commented 5 years ago

I looked into it and found out that this issue is present with every block. When getting the item in the Player's hand, GlowPlayerInventory#getItemInMainHand is called, which returns a cloned ItemStack. Because it's cloned, changing its amount does not change the item amount in the player's inventory, so the amount stays the same server-sided.

Removing the call to .cloned() fixes the problem, but I'm not sure if that indirectly breaks anything else.

Edit: Momo suggested a better solution in Discord: set the player's inventory item to the modified, cloned item after the amount is decremented. I'll create a PR for this shortly.