pmmp / PocketMine-MP

A server software for Minecraft: Bedrock Edition in PHP
https://pmmp.io
GNU Lesser General Public License v3.0
3.28k stars 1.56k forks source link

Floating-point errors causing NBT mismatches between client and server #4061

Closed dktapps closed 3 years ago

dktapps commented 3 years ago

Issue description

Since the server doesn't keep track of the serial network NBT of items anymore, it's possible for floating-point errors to slightly alter the decoded result, which leads to a false negative comparison.

This is problematic because it leads to items not being considered equivalent even though they are, for all intents and purposes, the same item. This causes problems with inventory transactions, amongst other things.

Steps to reproduce the issue

  1. Use the following code in a plugin
    public function onPlayerChat(PlayerChatEvent $event) : void{
        $event->getPlayer()->getInventory()->setItem($event->getPlayer()->getInventory()->getHeldItemIndex(), VanillaItems::LAPIS_LAZULI()->setNamedTag(
            CompoundTag::create()->setFloat("myfloat", 0.3)
        ));
    }
  2. Chat (you'll get a lapis-lazuli item)
  3. Try to move the item in your inventory. You'll notice it doesn't want to move.

OS and versions

dktapps commented 3 years ago

Fixed by 712df04bc4710ee5e9585bf5a6e7e6fbc772a2ad.

SOF3 commented 3 years ago

(The actual fix is in https://github.com/pmmp/NBT/commit/7de6bdfdfbcafe2689aafbde47f6506f265afd19)