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 ben) {
        return this.key.isEmpty() || (!ben.isEmpty() && ben.hasCustomHoverName() && this.key.equals(ben.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("");
    }
}
