package common.tileentity;

import common.nbt.NBTTagCompound;

public abstract class TileEntityLockable extends TileEntity implements IInteractionObject, ILockableContainer
{
    private LockCode code = LockCode.EMPTY_CODE;

    public void readFromNBT(NBTTagCompound compound)
    {
        super.readFromNBT(compound);
        this.code = LockCode.fromNBT(compound);
    }

    public void writeToNBT(NBTTagCompound compound)
    {
        super.writeToNBT(compound);

        if (this.code != null)
        {
            this.code.toNBT(compound);
        }
    }

    public boolean isLocked()
    {
        return this.code != null && !this.code.isEmpty();
    }

    public LockCode getLockCode()
    {
        return this.code;
    }

    public void setLockCode(LockCode code)
    {
        this.code = code;
    }
    
    public abstract String getName();
    public abstract boolean hasCustomName();

    /**
     * Get the formatted ChatComponent that will be used for the sender's username in chat
     */
    public String getCommandName()
    {
        return this.getName(); // (TextComponent)(this.hasCustomName() ? new TextComponent(this.getName()) : new TextComponent(this.getName()));
    }
}
