use of net.minecraftforge.items.ItemStackHandler in project NetherEx by LogicTechCorp.
the class BlockUrnOfSorrow method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
TileEntityUrnOfSorrow altar = (TileEntityUrnOfSorrow) world.getTileEntity(pos);
if (altar == null) {
return false;
}
ItemStackHandler inventory = altar.getInventory();
ItemStack inventoryStack = inventory.getStackInSlot(0);
ItemStack heldStack = player.getHeldItemMainhand();
if (!player.isSneaking()) {
if (heldStack.getItem() == Items.POTIONITEM && state.getValue(TYPE) == EnumType.EMPTY) {
for (PotionEffect effect : PotionUtils.getEffectsFromStack(heldStack)) {
if (effect.getPotion() == NetherExEffects.LOST) {
player.getHeldItemMainhand().shrink(1);
world.setBlockState(pos, state.withProperty(TYPE, EnumType.FULL));
}
}
} else {
if (inventoryStack.isEmpty() && !player.getHeldItemMainhand().isEmpty()) {
inventory.setStackInSlot(0, player.getHeldItemMainhand().splitStack(1));
}
}
} else {
if (!inventoryStack.isEmpty() && altar.getSummoningTime() == 0) {
if (!world.isRemote) {
altar.spawnItemStack(world, pos.up(), inventory.getStackInSlot(0));
}
inventory.setStackInSlot(0, ItemStack.EMPTY);
}
}
return super.onBlockActivated(world, pos, state, player, hand, facing, hitX, hitY, hitZ);
}
Aggregations