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 bki) {
        return this.key.isEmpty() || (!bki.isEmpty() && bki.hasCustomHoverName() && this.key.equals(bki.getHoverName().getString()));
    }
    
    public void addToTag(final CompoundTag le) {
        if (!this.key.isEmpty()) {
            le.putString("Lock", this.key);
        }
    }
    
    public static LockCode fromTag(final CompoundTag le) {
        if (le.contains("Lock", 8)) {
            return new LockCode(le.getString("Lock"));
        }
        return LockCode.NO_LOCK;
    }
    
    static {
        NO_LOCK = new LockCode("");
    }
}
