Class InventoryTranslator<Type extends Inventory>
java.lang.Object
org.geysermc.geyser.translator.inventory.InventoryTranslator<Type>
- Direct Known Subclasses:
BaseInventoryTranslator,PlayerInventoryTranslator
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final InventoryTranslator<PlayerInventory>final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponseacceptRequest(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request, List<org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponseContainer> containerEntries) abstract intbedrockSlotToJava(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData slotInfoData) Converts the Bedrock slot to the corresponding Java slot.booleancanReuseInventory(GeyserSession session, @NonNull Inventory inventory, @NonNull Inventory previous) Whether a new inventory should be prepared - or if we can re-use the previous one.booleancheckNetId(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData slotInfoData) abstract voidcloseInventory(GeyserSession session, Type inventory, boolean force) Closes the inventory, and if necessary, cleans up the prepared inventory.abstract TypecreateInventory(GeyserSession session, String name, int windowId, org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType containerType) Creates a new inventory.protected voiddumpStackRequestDetails(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.intUsed for crafting-related transactions.abstract SlotTypegetSlotType(int javaSlot) Returns the slot type for a Java slot idstatic @Nullable InventoryTranslator<? extends Inventory>inventoryTranslator(@Nullable org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType type) Gets theInventoryTranslatorfor the givenContainerType.protected static booleanisCursor(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData slotInfoData) abstract intjavaSlotToBedrock(int javaSlot) Converts a Java slot to the corresponding Bedrock slot.abstract BedrockContainerSlotjavaSlotToBedrockContainer(int javaSlot, Type inventory) Converts a Java slot to the corresponding Bedrock container and slotprotected final List<org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponseContainer>makeContainerEntries(GeyserSession session, Type inventory, it.unimi.dsi.fastutil.ints.IntSet affectedSlots) abstract voidopenInventory(GeyserSession session, Type inventory) Opens the previously prepared inventory.abstract booleanprepareInventory(GeyserSession session, Type inventory) Prepares the inventory before opening it.protected static org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponserejectRequest(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request) Reject an incorrect ItemStackRequest.protected static org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponserejectRequest(org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request, boolean throwError) Reject an incorrect ItemStackRequest.booleanrequiresOpeningDelay(GeyserSession session, Type inventory) protected booleanshouldHandleRequestFirst(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 booleanshouldRejectItemPlace(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.ItemStackResponsetranslateAutoCraftingRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request) org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponsetranslateCraftingRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request) protected org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponsetranslateCreativeRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request) Handled inPlayerInventoryTranslatororg.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponsetranslateRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request) final voidtranslateRequests(GeyserSession session, Type inventory, List<org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest> requests) protected org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponsetranslateSpecialRequest(GeyserSession session, Type inventory, org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequest request) IfshouldHandleRequestFirst(ItemStackRequestAction, Inventory)returns true, this will be calledabstract voidupdateInventory(GeyserSession session, Type inventory) Updates the inventory by re-sending items for all slots of the inventory.abstract voidupdateProperty(GeyserSession session, Type inventory, int key, int value) Updates a property in the inventory.abstract voidupdateSlot(GeyserSession session, Type inventory, int slot) Updates a specific slot by re-sending the item.
-
Field Details
-
PLAYER_INVENTORY_TRANSLATOR
-
PLAYER_INVENTORY_SIZE
public static final int PLAYER_INVENTORY_SIZE- See Also:
-
PLAYER_INVENTORY_OFFSET
public static final int PLAYER_INVENTORY_OFFSET- See Also:
-
size
public final int size
-
-
Constructor Details
-
InventoryTranslator
public InventoryTranslator(int size)
-
-
Method Details
-
requiresOpeningDelay
-
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
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
Opens the previously prepared inventory. -
closeInventory
Closes the inventory, and if necessary, cleans up the prepared inventory. -
updateProperty
Updates a property in the inventory. -
updateInventory
Updates the inventory by re-sending items for all slots of the inventory. -
updateSlot
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
Converts a Java slot to the corresponding Bedrock container and slot -
getSlotType
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) IfshouldHandleRequestFirst(ItemStackRequestAction, Inventory)returns true, this will be called -
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) Handled inPlayerInventoryTranslator -
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 theInventoryTranslatorfor the givenContainerType. ReturnsPLAYER_INVENTORY_TRANSLATORif type is null.- Parameters:
type- the type- Returns:
- the InventoryType for the given ContainerType.
-