@Immutable public class ContainerLock extends Object
Modifier and Type | Field and Description |
---|---|
static ContainerLock |
EMPTY
An empty container lock that can always be opened.
|
private String |
key |
Constructor and Description |
---|
ContainerLock(String key) |
Modifier and Type | Method and Description |
---|---|
boolean |
canOpen(ItemStack stack)
Returns true if this lock can be opened with the key item stack.
|
static ContainerLock |
fromTag(CompoundTag tag)
Creates a new
ContainerLock from the Lock key of the compound tag. |
void |
toTag(CompoundTag tag)
Inserts the key string of this lock into the
Lock key of the compound tag. |
public static final ContainerLock EMPTY
private final String key
public ContainerLock(String key)
public boolean canOpen(ItemStack 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.
stack
- the key item stackpublic void toTag(CompoundTag tag)
Lock
key of the compound tag.public static ContainerLock fromTag(CompoundTag tag)
ContainerLock
from the Lock
key of the compound tag.
If the Lock
key is not present, returns an empty lock.