From 12d5982c57159cc21de6988adcc536eea95d7c31 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Sun, 28 Jun 2020 16:14:57 -0800 Subject: [PATCH] Anvil fixes --- .../inventory/AnvilInventoryTranslator.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/AnvilInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/AnvilInventoryTranslator.java index 74710d45..c5d1de25 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/AnvilInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/AnvilInventoryTranslator.java @@ -30,15 +30,13 @@ import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.mc.protocol.data.message.TextMessage; import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientRenameItemPacket; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.nukkitx.protocol.bedrock.data.inventory.ContainerId; -import com.nukkitx.protocol.bedrock.data.inventory.ContainerType; -import com.nukkitx.protocol.bedrock.data.inventory.InventoryActionData; -import com.nukkitx.protocol.bedrock.data.inventory.ItemData; +import com.nukkitx.protocol.bedrock.data.inventory.*; import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.inventory.updater.CursorInventoryUpdater; import java.util.List; +import java.util.stream.Collectors; public class AnvilInventoryTranslator extends BlockInventoryTranslator { public AnvilInventoryTranslator() { @@ -57,6 +55,9 @@ public class AnvilInventoryTranslator extends BlockInventoryTranslator { return 2; } } + if (action.getSource().getContainerId() == ContainerId.ANVIL_RESULT) { + return 2; + } return super.bedrockSlotToJava(action); } @@ -112,7 +113,13 @@ public class AnvilInventoryTranslator extends BlockInventoryTranslator { session.sendDownstreamPacket(renameItemPacket); } if (anvilResult != null) { - //client will send another packet to grab anvil output + //Strip unnecessary actions + List strippedActions = actions.stream() + .filter(action -> action.getSource().getContainerId() == ContainerId.ANVIL_RESULT + || (action.getSource().getType() == InventorySource.Type.CONTAINER + && !(action.getSource().getContainerId() == ContainerId.UI && action.getSlot() != 0))) + .collect(Collectors.toList()); + super.translateActions(session, inventory, strippedActions); return; } @@ -121,7 +128,7 @@ public class AnvilInventoryTranslator extends BlockInventoryTranslator { @Override public void updateSlot(GeyserSession session, Inventory inventory, int slot) { - if (slot >= 0 && slot <= 2) { + if (slot == 0) { ItemStack item = inventory.getItem(slot); if (item != null) { String rename;