From b70e2645c8aa0695ccd25b39d36f393914b84304 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Sun, 26 Dec 2021 12:07:38 -0500 Subject: [PATCH] Allow dropping items from the creative menu in mobile Fixes #2626 --- .../inventory/PlayerInventoryTranslator.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java index 0fd9f114f..fcd613c23 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java @@ -401,7 +401,6 @@ public class PlayerInventoryTranslator extends InventoryTranslator { break; } case CRAFT_RESULTS_DEPRECATED: { - CraftResultsDeprecatedStackRequestActionData deprecatedCraftAction = (CraftResultsDeprecatedStackRequestActionData) action; if (craftState != CraftState.RECIPE_ID) { return rejectRequest(request); } @@ -453,6 +452,28 @@ public class PlayerInventoryTranslator extends InventoryTranslator { } break; } + case DROP: { + // Can be replicated as of 1.18.2 Bedrock on mobile by clicking from the creative menu to outside it + if (craftState != CraftState.DEPRECATED) { + return rejectRequest(request); + } + + DropStackRequestActionData dropAction = (DropStackRequestActionData) action; + if (dropAction.getSource().getContainer() != ContainerSlotType.CREATIVE_OUTPUT || dropAction.getSource().getSlot() != 50) { + return rejectRequest(request); + } + + ItemStack dropStack; + if (dropAction.getCount() == javaCreativeItem.getAmount()) { + dropStack = javaCreativeItem; + } else { + // Specify custom count + dropStack = new ItemStack(javaCreativeItem.getId(), dropAction.getCount(), javaCreativeItem.getNbt()); + } + ServerboundSetCreativeModeSlotPacket creativeDropPacket = new ServerboundSetCreativeModeSlotPacket(-1, dropStack); + session.sendDownstreamPacket(creativeDropPacket); + break; + } default: return rejectRequest(request); }