Skip to content

Inventory Transactions

Niclas Olofsson edited this page Dec 28, 2019 · 6 revisions

Various inventories in bedrock is handled by inventory transactions. Examples of inventories managed via the transactions are creative inventory, normal player inventory (survival), crafting inventory. There are also a couple of "transfer inventories", like the current cursor (when you move an item from one inventory to another, it transfers via this cursor slot).

After executing an inventory change on the client, one or several transactions will happen. At the end of a sequence the transactions will always balance. This works very much like regular bookeeping on business accounts.

There are 5 basic types of transactions

  • Normal transactions (0)
  • Inventory mismatch transactions (1)
  • Item use transactions (2)
  • Item use (on entity) transactions (3)
  • Item release transactions (4)

Normal transactions

Handles moving items within an inventory (like rearranging items in the player inventory), or moving them between inventories (from the player inventory to a chest, crafting grid, etc). For any normal inventory action, this will have 2 transactions; one transaction for the inventory/slot where the item is moved from, and one transaction for the inventory/slot that the item is moving to. Each of these transactions specify the existing inventory (id), the (old) content of the slot, and the new content for the same slot.

Origins

Each transaction above specifies a source for the items. Basically, this is used as an indicator to signal where the items being dealt with in the transaction is coming from. This is necessary in order to create items out of thin air, or from non-typical container based transactions. Creative inventory, crafting and world interaction are typcial sources for items. In this sense the whole "world" is treated as a big inventory that can create/contain items.

The most commonly used sources are

  • Containers
  • Creative inventory
  • Crafting
  • World (interactions)

Inventory actions

Many transactions follow as a cause of some operation performed in context of the type of transaction. These are called actions and further indicate intent of the current transaction(s) and what to expect/verify when balancing the transactions. A typical example is when an item is used, the action will indicate if it is an place, use or destroy action.

Inventory mismatch transactions

A special transaction to deal with out-of-sync issues between client and server.

Item use transactions

When you use an item, it is handled via "use item transactions". Note that this transaction frequently works in combination with an item release transaction.

Item use (on entity) transactions

A specialized version of "use item transaction", dealing with item use applied to other entities.

Item release transactions

Use to communicate various item usage related actions.

Implementation notes

Test cases

Creative, regular move (via cursor) Creative shift-click (no cursor)

Survival, regular move (via cursor) Creative shift-click (no cursor)

Armor, regular move (via cursor) Armor,