Class ContainerLock

java.lang.Object
net.minecraft.inventory.ContainerLock

@Immutable
public class ContainerLock
extends Object
  • Field Details

    • EMPTY

      public static final ContainerLock EMPTY
      An empty container lock that can always be opened.
    • key

      private final String key
  • Constructor Details

    • ContainerLock

      public ContainerLock​(String key)
  • Method Details

    • canOpen

      public boolean canOpen​(ItemStack stack)
      Returns true if this lock can be opened with the key item stack.

      An item stack is a valid key if the stack name matches the key string of this lock, or if the key string is empty.

      Parameters:
      stack - the key item stack
    • toTag

      public void toTag​(CompoundTag tag)
      Inserts the key string of this lock into the Lock key of the compound tag.
    • fromTag

      public static ContainerLock fromTag​(CompoundTag tag)
      Creates a new ContainerLock from the Lock key of the compound tag.

      If the Lock key is not present, returns an empty lock.