Class ItemSyncedGuiDescription

All Implemented Interfaces:
GuiDescription

public class ItemSyncedGuiDescription extends SyncedGuiDescription
A SyncedGuiDescription for an item stack in an inventory.

The owning item is represented with a StackReference, which can be an item in an entity's inventory or a block's container, or any other reference to an item stack.

If the owning item stack changes in any way, the screen closes by default (see canUse(PlayerEntity)).

Since:
7.0.0
  • Field Details

    • owner

      protected final StackReference owner
      A reference to the owning item stack of this GUI.
    • ownerStack

      protected final ItemStack ownerStack
      The initial item stack of this GUI. This stack must not be mutated!
  • Constructor Details

    • ItemSyncedGuiDescription

      public ItemSyncedGuiDescription(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory, StackReference owner)
      Constructs an ItemSyncedGuiDescription.
      Parameters:
      type - the screen handler type
      syncId - the sync ID
      playerInventory - the inventory of the player viewing this GUI description
      owner - a reference to the owning item stack of this GUI description
  • Method Details

    • canUse

      public boolean canUse(PlayerEntity entity)

      The default implementation for ItemSyncedGuiDescription returns true if and only if the current owning item stack is fully equal to the original owner.

      If the item NBT is intended to change, subclasses should override this method to only check the item and the count. Those subclasses should also take care to respond properly to any NBT changes in the owning item stack.

      Overrides:
      canUse in class SyncedGuiDescription