Fix middle click drop handling

This commit is contained in:
GoldenStack 2024-04-20 20:48:54 -05:00 committed by mworzala
parent 33cfb8f764
commit 9f45a9f1b4
No known key found for this signature in database
GPG Key ID: B148F922E64797C7
2 changed files with 9 additions and 6 deletions

View File

@ -107,7 +107,7 @@ public final class Click {
public @Nullable Click.Info processClick(@NotNull ClientClickWindowPacket packet, boolean isCreative, @Nullable Integer containerSize) {
final byte button = packet.button();
final boolean requireCreative = switch (packet.clickType()) {
case CLONE -> true;
case CLONE -> packet.slot() != -999; // Permit middle click dropping
case QUICK_CRAFT -> button == 8 || button == 9 || button == 10;
default -> false;
};
@ -115,10 +115,13 @@ public final class Click {
final int slot = packet.slot() == -999 ? -999 :
containerSize == null ? PlayerInventoryUtils.protocolToMinestom(packet.slot()) : packet.slot();
final int maxSize = containerSize != null ? containerSize + PlayerInventoryUtils.INNER_SIZE : PlayerInventoryUtils.INVENTORY_SIZE;
if (packet.clickType() == ClientClickWindowPacket.ClickType.PICKUP && slot == -999) {
if (button == 0) return new Info.LeftDropCursor();
if (button == 1) return new Info.RightDropCursor();
if (button == 2) return new Info.MiddleDropCursor();
if (slot == -999) {
if (packet.clickType() == ClientClickWindowPacket.ClickType.PICKUP) {
if (button == 0) return new Info.LeftDropCursor();
if (button == 1) return new Info.RightDropCursor();
} else if (packet.clickType() == ClientClickWindowPacket.ClickType.CLONE) { // Why Mojang, why?
if (button == 2) return new Info.MiddleDropCursor();
}
}
final boolean valid = slot >= 0 && slot < maxSize;
if (!valid) return null;

View File

@ -13,7 +13,7 @@ public class ClickPreprocessorTest {
public void testPickupType() {
assertProcessed(new Click.Info.LeftDropCursor(), clickPacket(PICKUP, 1, 0, -999));
assertProcessed(new Click.Info.RightDropCursor(), clickPacket(PICKUP, 1, 1, -999));
assertProcessed(new Click.Info.MiddleDropCursor(), clickPacket(PICKUP, 1, 2, -999));
assertProcessed(new Click.Info.MiddleDropCursor(), clickPacket(CLONE, 1, 2, -999));
assertProcessed(new Click.Info.Left(0), clickPacket(PICKUP, 1, 0, 0));
assertProcessed(new Click.Info.Left(SIZE), clickPacket(PICKUP, 1, 0, 5));