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;
}
Aggregations