From 821e3126ea3deb1cea616741a7eed04eb6e2dac7 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Fri, 12 Mar 2021 11:51:37 -0500 Subject: [PATCH] Handful of review fixes --- .../inventory/Generic3X3Container.java | 5 ++- .../BedrockLecternUpdateTranslator.java | 4 +-- .../inventory/InventoryTranslator.java | 33 ++++++++++++------- .../LecternInventoryTranslator.java | 10 +----- .../AbstractHorseInventoryTranslator.java | 3 -- .../inventory/updater/InventoryUpdater.java | 2 +- .../java/window/JavaSetSlotTranslator.java | 1 - .../world/block/BlockTranslator.java | 6 ++-- 8 files changed, 33 insertions(+), 31 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/inventory/Generic3X3Container.java b/connector/src/main/java/org/geysermc/connector/inventory/Generic3X3Container.java index 8c89cdeb6..080e11982 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/Generic3X3Container.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/Generic3X3Container.java @@ -27,10 +27,13 @@ package org.geysermc.connector.inventory; import com.github.steveice10.mc.protocol.data.game.window.WindowType; import lombok.Getter; +import org.geysermc.connector.network.session.GeyserSession; public class Generic3X3Container extends Container { /** - * Whether we need to set the container type as {@link com.nukkitx.protocol.bedrock.data.inventory.ContainerType#DROPPER} + * Whether we need to set the container type as {@link com.nukkitx.protocol.bedrock.data.inventory.ContainerType#DROPPER}. + * + * Used at {@link org.geysermc.connector.network.translators.inventory.translators.Generic3X3InventoryTranslator#openInventory(GeyserSession, Inventory)} */ @Getter private boolean isDropper = false; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockLecternUpdateTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockLecternUpdateTranslator.java index 99dcebed9..10af0b610 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockLecternUpdateTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockLecternUpdateTranslator.java @@ -56,7 +56,7 @@ public class BedrockLecternUpdateTranslator extends PacketTranslator currentJavaPage) { for (int i = currentJavaPage; i < newJavaPage; i++) { ClientClickWindowButtonPacket clickButtonPacket = new ClientClickWindowButtonPacket(session.getOpenInventory().getId(), 2); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java index 6ef214067..6ec90d24d 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java @@ -108,8 +108,8 @@ public abstract class InventoryTranslator { public abstract void updateInventory(GeyserSession session, Inventory inventory); public abstract void updateSlot(GeyserSession session, Inventory inventory, int slot); public abstract int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData); - public abstract int javaSlotToBedrock(int javaSlot); //TODO - public abstract BedrockContainerSlot javaSlotToBedrockContainer(int javaSlot); //TODO + public abstract int javaSlotToBedrock(int javaSlot); + public abstract BedrockContainerSlot javaSlotToBedrockContainer(int javaSlot); public abstract SlotType getSlotType(int javaSlot); public abstract Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory); @@ -138,7 +138,7 @@ public abstract class InventoryTranslator { * If {@link #shouldHandleRequestFirst(StackRequestActionData, Inventory)} returns true, this will be called */ public ItemStackResponsePacket.Response translateSpecialRequest(GeyserSession session, Inventory inventory, ItemStackRequest request) { - return null; + return rejectRequest(request); } public void translateRequests(GeyserSession session, Inventory inventory, List requests) { @@ -151,15 +151,22 @@ public abstract class InventoryTranslator { if (shouldHandleRequestFirst(firstAction, inventory)) { // Some special request that shouldn't be processed normally response = translateSpecialRequest(session, inventory, request); - } else if (firstAction.getType() == StackRequestActionType.CRAFT_RECIPE) { - response = translateCraftingRequest(session, inventory, request); - } else if (firstAction.getType() == StackRequestActionType.CRAFT_RECIPE_AUTO) { - response = translateAutoCraftingRequest(session, inventory, request); - } else if (firstAction.getType() == StackRequestActionType.CRAFT_CREATIVE) { - // This is also used for pulling items out of creative - response = translateCreativeRequest(session, inventory, request); } else { - response = translateRequest(session, inventory, request); + switch (firstAction.getType()) { + case CRAFT_RECIPE: + response = translateCraftingRequest(session, inventory, request); + break; + case CRAFT_RECIPE_AUTO: + response = translateAutoCraftingRequest(session, inventory, request); + break; + case CRAFT_CREATIVE: + // This is also used for pulling items out of creative + response = translateCreativeRequest(session, inventory, request); + break; + default: + response = translateRequest(session, inventory, request); + break; + } } } else { response = rejectRequest(request); @@ -693,8 +700,10 @@ public abstract class InventoryTranslator { return acceptRequest(request, makeContainerEntries(session, inventory, plan.getAffectedSlots())); } + /** + * Handled in {@link PlayerInventoryTranslator} + */ public ItemStackResponsePacket.Response translateCreativeRequest(GeyserSession session, Inventory inventory, ItemStackRequest request) { - // Handled in PlayerInventoryTranslator return rejectRequest(request); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LecternInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LecternInventoryTranslator.java index dbbc418ba..c08dfd995 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LecternInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LecternInventoryTranslator.java @@ -51,22 +51,19 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator { public LecternInventoryTranslator() { super(1); - this.updater = new LecternInventoryUpdater(); + this.updater = new InventoryUpdater(); } @Override public void prepareInventory(GeyserSession session, Inventory inventory) { - } @Override public void openInventory(GeyserSession session, Inventory inventory) { - } @Override public void closeInventory(GeyserSession session, Inventory inventory) { - } @Override @@ -81,7 +78,6 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator { @Override public void updateInventory(GeyserSession session, Inventory inventory) { - } @Override @@ -171,8 +167,4 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator { } return builder; } - - private static class LecternInventoryUpdater extends InventoryUpdater { - - } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/horse/AbstractHorseInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/horse/AbstractHorseInventoryTranslator.java index 6c6c9a0c2..0e365aca1 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/horse/AbstractHorseInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/horse/AbstractHorseInventoryTranslator.java @@ -41,17 +41,14 @@ public abstract class AbstractHorseInventoryTranslator extends BaseInventoryTran @Override public void prepareInventory(GeyserSession session, Inventory inventory) { - } @Override public void openInventory(GeyserSession session, Inventory inventory) { - } @Override public void closeInventory(GeyserSession session, Inventory inventory) { - } @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/updater/InventoryUpdater.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/updater/InventoryUpdater.java index d7c137177..e94c0944b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/updater/InventoryUpdater.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/updater/InventoryUpdater.java @@ -35,7 +35,7 @@ import org.geysermc.connector.network.translators.inventory.InventoryTranslator; import java.util.Arrays; -public abstract class InventoryUpdater { +public class InventoryUpdater { public void updateInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) { ItemData[] bedrockItems = new ItemData[36]; for (int i = 0; i < 36; i++) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java index b5978ba76..a0e9901f3 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java @@ -134,7 +134,6 @@ public class JavaSetSlotTranslator extends PacketTranslator height += -firstRow + 1; width += -firstCol + 1; - //TODO recipes: for (Recipe recipe : session.getCraftingRecipes().values()) { if (recipe.getType() == RecipeType.CRAFTING_SHAPED) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/world/block/BlockTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/world/block/BlockTranslator.java index ec1c79950..057c74d2b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/world/block/BlockTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/world/block/BlockTranslator.java @@ -112,8 +112,6 @@ public abstract class BlockTranslator { */ private final Map javaIdentifierToBedrockTag; - private static final int BLOCK_STATE_VERSION = 17825808; - /** * Stores the raw blocks JSON until it is no longer needed. */ @@ -413,6 +411,10 @@ public abstract class BlockTranslator { return bedrockWaterId; } + /** + * @return the "block state version" generated in the Bedrock block palette that completes an NBT indication of a + * block state. + */ public abstract int getBlockStateVersion(); public byte[] getEmptyChunkData() {