From 683ac1c763f9082f9847ac2a71262941cc729b24 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Sat, 19 Jun 2021 20:33:07 -0400 Subject: [PATCH] Fix spawn egg triggering twice in water --- ...BedrockInventoryTransactionTranslator.java | 60 ++++++++++++------- .../translators/item/ItemRegistry.java | 15 +++-- 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java index 6378c0ba9..bb2325785 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java @@ -183,6 +183,17 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator { + if (packet.getItemInHand() != null) { + // Otherwise boats will not be able to be placed in survival and buckets won't work on mobile + if (ItemRegistry.BOATS.contains(packet.getItemInHand().getId())) { ClientPlayerUseItemPacket itemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND); session.sendDownstreamPacket(itemPacket); - }, 5, TimeUnit.MILLISECONDS)); + } + // Check actions, otherwise buckets may be activated when block inventories are accessed + else if (ItemRegistry.BUCKETS.contains(packet.getItemInHand().getId())) { + // Let the server decide if the bucket item should change, not the client, and revert the changes the client made + InventorySlotPacket slotPacket = new InventorySlotPacket(); + slotPacket.setContainerId(ContainerId.INVENTORY); + slotPacket.setSlot(packet.getHotbarSlot()); + slotPacket.setItem(packet.getItemInHand()); + session.sendUpstreamPacket(slotPacket); + // Delay the interaction in case the client doesn't intend to actually use the bucket + // See BedrockActionTranslator.java + session.setBucketScheduledFuture(session.getConnector().getGeneralThreadPool().schedule(() -> { + ClientPlayerUseItemPacket itemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND); + session.sendDownstreamPacket(itemPacket); + }, 5, TimeUnit.MILLISECONDS)); + } } if (packet.getActions().isEmpty()) { @@ -253,10 +266,15 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator