Class InventoryTranslator<Type extends Inventory>

java.lang.Object
org.geysermc.geyser.translator.inventory.InventoryTranslator<Type>
Direct Known Subclasses:
BaseInventoryTranslator, PlayerInventoryTranslator

public abstract class InventoryTranslator<Type extends Inventory> extends Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static enum 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
     
    final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse
    acceptRequest(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request, List<org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponseContainer> containerEntries)
     
    abstract int
    bedrockSlotToJava(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData slotInfoData)
    Converts the Bedrock slot to the corresponding Java slot.
    boolean
    canReuseInventory(GeyserSession session, @NonNull Inventory inventory, @NonNull Inventory previous)
    Whether a new inventory should be prepared - or if we can re-use the previous one.
    boolean
    checkNetId(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData slotInfoData)
     
    abstract void
    closeInventory(GeyserSession session, Type inventory, boolean force)
    Closes the inventory, and if necessary, cleans up the prepared inventory.
    abstract Type
    createInventory(GeyserSession session, String name, int windowId, org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType containerType)
    Creates a new inventory.
    protected void
    dumpStackRequestDetails(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData source, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData destination)
    Print out the contents of an ItemStackRequest, should the net ID check fail.
    int
    Used for crafting-related transactions.
    abstract SlotType
    getSlotType(int javaSlot)
    Returns the slot type for a Java slot id
    static @Nullable InventoryTranslator<? extends Inventory>
    inventoryTranslator(@Nullable org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType type)
    Gets the InventoryTranslator for the given ContainerType.
    protected static boolean
    isCursor(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData slotInfoData)
     
    abstract int
    javaSlotToBedrock(int javaSlot)
    Converts a Java slot to the corresponding Bedrock slot.
    javaSlotToBedrockContainer(int javaSlot, Type inventory)
    Converts a Java slot to the corresponding Bedrock container and slot
    protected final List<org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponseContainer>
    makeContainerEntries(GeyserSession session, Type inventory, it.unimi.dsi.fastutil.ints.IntSet affectedSlots)
     
    abstract void
    openInventory(GeyserSession session, Type inventory)
    Opens the previously prepared inventory.
    abstract boolean
    prepareInventory(GeyserSession session, Type inventory)
    Prepares the inventory before opening it.
    protected static org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse
    rejectRequest(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request)
    Reject an incorrect ItemStackRequest.
    protected static org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse
    rejectRequest(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request, boolean throwError)
    Reject an incorrect ItemStackRequest.
    boolean
     
    protected boolean
    shouldHandleRequestFirst(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.action.ItemStackRequestAction action, Type inventory)
    Should be overrided if this request matches a certain criteria and shouldn't be treated normally.
    protected boolean
    shouldRejectItemPlace(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.ContainerSlotType bedrockSourceContainer, int javaSourceSlot, org.cloudburstmc.protocol.bedrock.data.inventory.ContainerSlotType bedrockDestinationContainer, int javaDestinationSlot)
    Should be overwritten in cases where specific inventories should reject an item being in a specific spot.
    org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse
    translateAutoCraftingRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request)
     
    org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse
    translateCraftingRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request)
     
    protected org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse
    translateCreativeRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request)
    org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse
    translateRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request)
     
    final void
    translateRequests(GeyserSession session, Type inventory, List<org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest> requests)
     
    protected org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse
    translateSpecialRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request)
    abstract void
    updateInventory(GeyserSession session, Type inventory)
    Updates the inventory by re-sending items for all slots of the inventory.
    abstract void
    updateProperty(GeyserSession session, Type inventory, int key, int value)
    Updates a property in the inventory.
    abstract void
    updateSlot(GeyserSession session, Type inventory, int slot)
    Updates a specific slot by re-sending the item.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • InventoryTranslator

      public InventoryTranslator(int size)
  • Method Details

    • requiresOpeningDelay

      public boolean requiresOpeningDelay(GeyserSession session, Type inventory)
    • canReuseInventory

      public boolean canReuseInventory(GeyserSession session, @NonNull Inventory inventory, @NonNull Inventory previous)
      Whether a new inventory should be prepared - or if we can re-use the previous one.
    • prepareInventory

      public abstract boolean prepareInventory(GeyserSession session, Type inventory)
      Prepares the inventory before opening it. Bedrock requires the inventory to "exist" before opening it - that can be either a real block (e.g. chest), or an entity (e.g. horse)
      Returns:
      whether the inventory was successfully prepared
    • openInventory

      public abstract void openInventory(GeyserSession session, Type inventory)
      Opens the previously prepared inventory.
    • closeInventory

      public abstract void closeInventory(GeyserSession session, Type inventory, boolean force)
      Closes the inventory, and if necessary, cleans up the prepared inventory.
    • updateProperty

      public abstract void updateProperty(GeyserSession session, Type inventory, int key, int value)
      Updates a property in the inventory.
    • updateInventory

      public abstract void updateInventory(GeyserSession session, Type inventory)
      Updates the inventory by re-sending items for all slots of the inventory.
    • updateSlot

      public abstract void updateSlot(GeyserSession session, Type inventory, int slot)
      Updates a specific slot by re-sending the item.
    • bedrockSlotToJava

      public abstract int bedrockSlotToJava(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData slotInfoData)
      Converts the Bedrock slot to the corresponding Java slot.
    • javaSlotToBedrock

      public abstract int javaSlotToBedrock(int javaSlot)
      Converts a Java slot to the corresponding Bedrock slot.
    • javaSlotToBedrockContainer

      public abstract BedrockContainerSlot javaSlotToBedrockContainer(int javaSlot, Type inventory)
      Converts a Java slot to the corresponding Bedrock container and slot
    • getSlotType

      public abstract SlotType getSlotType(int javaSlot)
      Returns the slot type for a Java slot id
    • createInventory

      public abstract Type createInventory(GeyserSession session, String name, int windowId, org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType containerType)
      Creates a new inventory.
    • getGridSize

      public int getGridSize()
      Used for crafting-related transactions. Will override in PlayerInventoryTranslator and CraftingInventoryTranslator.
    • shouldRejectItemPlace

      protected boolean shouldRejectItemPlace(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.ContainerSlotType bedrockSourceContainer, int javaSourceSlot, org.cloudburstmc.protocol.bedrock.data.inventory.ContainerSlotType bedrockDestinationContainer, int javaDestinationSlot)
      Should be overwritten in cases where specific inventories should reject an item being in a specific spot. For examples, looms use this to reject items that are dyes in Bedrock but not in Java.

      The source/destination slot will be -1 if the cursor is the slot

      Returns:
      true if this transfer should be rejected
    • shouldHandleRequestFirst

      protected boolean shouldHandleRequestFirst(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.action.ItemStackRequestAction action, Type inventory)
      Should be overrided if this request matches a certain criteria and shouldn't be treated normally. E.G. anvil renaming or enchanting
    • translateSpecialRequest

      protected org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse translateSpecialRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request)
    • translateRequests

      public final void translateRequests(GeyserSession session, Type inventory, List<org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest> requests)
    • translateRequest

      public org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse translateRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request)
    • translateCraftingRequest

      public org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse translateCraftingRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request)
    • translateAutoCraftingRequest

      public org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse translateAutoCraftingRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request)
    • translateCreativeRequest

      protected org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse translateCreativeRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request)
    • acceptRequest

      protected static org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse acceptRequest(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request, List<org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponseContainer> containerEntries)
    • rejectRequest

      protected static org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse rejectRequest(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request)
      Reject an incorrect ItemStackRequest.
    • rejectRequest

      protected static org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse rejectRequest(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request, boolean throwError)
      Reject an incorrect ItemStackRequest.
      Parameters:
      throwError - whether this request was truly erroneous (true), or known as an outcome and should not be treated as bad (false).
    • dumpStackRequestDetails

      protected void dumpStackRequestDetails(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData source, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData destination)
      Print out the contents of an ItemStackRequest, should the net ID check fail.
    • checkNetId

      public boolean checkNetId(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData slotInfoData)
    • makeContainerEntries

      protected final List<org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponseContainer> makeContainerEntries(GeyserSession session, Type inventory, it.unimi.dsi.fastutil.ints.IntSet affectedSlots)
    • isCursor

      protected static boolean isCursor(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData slotInfoData)
    • inventoryTranslator

      public static @Nullable InventoryTranslator<? extends Inventory> inventoryTranslator(@Nullable org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType type)
      Gets the InventoryTranslator for the given ContainerType. Returns PLAYER_INVENTORY_TRANSLATOR if type is null.
      Parameters:
      type - the type
      Returns:
      the InventoryType for the given ContainerType.