mojira.dev
MC-41165

SetSlot packet can no longer set item under cursor

In 1.6.4, sending a SetSlot packet (0x2F in 1.7.2, 0x67 in 1.6.4) with window id ( the first byte ) set to -1 would allow the server to set the item displayed under the mouse cursor while the client was in an inventory window.

This no longer works in 1.7.2. Without the ability to change the item under the cursor, Bukkit can't cancel Inventory events. This has the effect of breaking all plugins that use the "Inventory as a menu" system. After looking at a decompilation of the client source, it appears to be a pretty easy fix.

In the client code, when the Packet class for SetSlot reads from the network, it now reads the first byte as unsigned and saves the results as an integer.

public void read(ep in)
  {
    this.a = in.readUnsignedByte();
    this.b = in.readShort();
    this.c = in.c();
  }

When the packet is processed, the code that checks if the window is -1 is still there, but because the data is now read as unsigned, we should check for the value 255 instead of -1;

public void a(gh pgh) {
  bje lbje = this.f.h;
  if (pgh.getA() == -1) {
      lbje.bn.b(pgh.e());  //This sets the item under the cursor.
  } else {
      <snip>       
  }
}

Comments 3

Before anyone gets tempted to close this because it's not known to directly effect vanilla servers, consider this: it is a bug. The block following "if (pgh.getA() == -1)" is dead code: due to this bug, it's become inaccessible, and that is clearly not intended.

Don't panic. This code doesn't "break" inventory event cancelling.
It does however cause derpiness client side.

Rob Blanckaert

Nathan Adams

Unconfirmed

Minecraft 1.7.2, Minecraft 13w48b

Minecraft 13w49a

Retrieved