Search in sources :

Example 1 with IKeyItem

use of pl.asie.charset.api.storage.IKeyItem in project Charset by CharsetMC.

the class LockEventHandler method unlockOrRaiseError.

public static boolean unlockOrRaiseError(EntityPlayer player, TileEntity tile, Lockable lock) {
    if (player.getEntityWorld().isRemote) {
        return true;
    }
    boolean canUnlock = false;
    for (ItemStack stack : getPotentialKeys(player)) {
        if (!stack.isEmpty() && stack.getItem() instanceof IKeyItem) {
            IKeyItem key = (IKeyItem) stack.getItem();
            canUnlock = key.canUnlock(lock.getLock().getLockKey(), stack);
            if (canUnlock) {
                break;
            }
        }
    }
    if (!canUnlock) {
        ITextComponent displayName = tile.getDisplayName();
        if (displayName == null) {
            displayName = new TextComponentTranslation(tile.getBlockType().getUnlocalizedName() + ".name");
        }
        new Notice(tile, new TextComponentTranslation("container.isLocked", displayName)).sendTo(player);
        player.getEntityWorld().playSound(player, tile.getPos(), SoundEvents.BLOCK_CHEST_LOCKED, SoundCategory.BLOCKS, 1.0f, 1.0f);
    }
    return canUnlock;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Notice(pl.asie.charset.lib.notify.Notice) IKeyItem(pl.asie.charset.api.storage.IKeyItem) ITextComponent(net.minecraft.util.text.ITextComponent) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 IKeyItem (pl.asie.charset.api.storage.IKeyItem)1 Notice (pl.asie.charset.lib.notify.Notice)1