use of net.minecraft.entity.IEntityOwnable in project EnderIO by SleepyTrousers.
the class ItemSoulVial method itemInteractionForEntity.
@Override
public boolean itemInteractionForEntity(@Nonnull ItemStack item, @Nonnull EntityPlayer player, @Nonnull EntityLivingBase entity, @Nonnull EnumHand hand) {
if (entity.world.isRemote) {
return false;
}
boolean isCreative = player.capabilities.isCreativeMode;
if (CapturedMob.containsSoul(item) && !isCreative) {
return false;
}
// first check if that entity can be picked up at all
CapturedMob capturedMob = CapturedMob.create(entity);
if (capturedMob == null) {
if (entity instanceof EntityPlayer) {
player.sendMessage(Lang.SOUL_VIAL_DENIED_PLAYER.toChatServer());
} else if (CapturedMob.isBlacklisted(entity)) {
player.sendMessage(Lang.SOUL_VIAL_DENIED_AALISTED.toChatServer());
}
return false;
}
// then check for reasons this specific one cannot
if (entity instanceof IEntityOwnable && ((IEntityOwnable) entity).getOwnerId() != null && !player.equals(((IEntityOwnable) entity).getOwner()) && !PermissionAPI.hasPermission(player.getGameProfile(), permissionPickupOwned, new TargetContext(player, entity))) {
player.sendMessage(Lang.SOUL_VIAL_DENIED_OWNED_PET.toChatServer());
return false;
}
if (!PermissionAPI.hasPermission(player.getGameProfile(), permissionPickup, new TargetContext(player, entity))) {
player.sendMessage(Lang.SOUL_VIAL_DENIED.toChatServer());
return false;
}
ItemStack capturedMobVessel = capturedMob.toStack(this, 1, 1);
player.swingArm(hand);
if (!isCreative) {
entity.setDead();
if (entity.isDead) {
// So we do not shrink the stack when it is 1.
if (item.getCount() > 1) {
item.shrink(1);
// Since this stack still exists, add the new vial to the first location, or drop
if (!player.inventory.addItemStackToInventory(capturedMobVessel)) {
player.dropItem(capturedMobVessel, false);
}
} else {
// Otherwise, just replace the stack
player.setHeldItem(hand, capturedMobVessel);
}
player.inventoryContainer.detectAndSendChanges();
return true;
}
} else {
if (!player.inventory.addItemStackToInventory(capturedMobVessel)) {
player.dropItem(capturedMobVessel, false);
}
player.inventoryContainer.detectAndSendChanges();
return true;
}
return false;
}
Aggregations