use of net.mcft.copy.betterstorage.api.lock.IKey in project BetterStorage by copygirl.
the class LockAttachment method use.
private boolean use(EntityPlayer player, ItemStack holding) {
if (player.worldObj.isRemote)
return false;
ILockable lockable = (ILockable) tileEntity;
ItemStack lock = lockable.getLock();
if (lock == null) {
if (StackUtils.isLock(holding) && lockable.isLockValid(holding)) {
lockable.setLock(holding);
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
return true;
}
} else if (StackUtils.isKey(holding)) {
IKey keyType = (IKey) holding.getItem();
ILock lockType = (ILock) lock.getItem();
boolean success = keyType.unlock(holding, lock, true);
lockType.onUnlock(lock, holding, lockable, player, success);
if (!success)
return true;
if (player.isSneaking()) {
AxisAlignedBB box = getHighlightBox();
double x = (box.minX + box.maxX) / 2;
double y = (box.minY + box.maxY) / 2;
double z = (box.minZ + box.maxZ) / 2;
EntityItem item = WorldUtils.spawnItem(player.worldObj, x, y, z, lock);
lockable.setLock(null);
} else
lockable.useUnlocked(player);
return true;
}
return false;
}
Aggregations