37 lines
962 B
Java
37 lines
962 B
Java
package net.minecraft.world;
|
|
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import javax.annotation.concurrent.Immutable;
|
|
|
|
@Immutable
|
|
public class LockCode {
|
|
public static final LockCode NO_LOCK;
|
|
private final String key;
|
|
|
|
public LockCode(final String string) {
|
|
this.key = string;
|
|
}
|
|
|
|
public boolean unlocksWith(final ItemStack bek) {
|
|
return this.key.isEmpty() || (!bek.isEmpty() && bek.hasCustomHoverName() && this.key.equals(bek.getHoverName().getString()));
|
|
}
|
|
|
|
public void addToTag(final CompoundTag jt) {
|
|
if (!this.key.isEmpty()) {
|
|
jt.putString("Lock", this.key);
|
|
}
|
|
}
|
|
|
|
public static LockCode fromTag(final CompoundTag jt) {
|
|
if (jt.contains("Lock", 8)) {
|
|
return new LockCode(jt.getString("Lock"));
|
|
}
|
|
return LockCode.NO_LOCK;
|
|
}
|
|
|
|
static {
|
|
NO_LOCK = new LockCode("");
|
|
}
|
|
}
|