Search in sources :

Example 1 with ItemStackHandler

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);
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) TileEntityUrnOfSorrow(nex.tileentity.TileEntityUrnOfSorrow) PotionEffect(net.minecraft.potion.PotionEffect) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)1 PotionEffect (net.minecraft.potion.PotionEffect)1 ItemStackHandler (net.minecraftforge.items.ItemStackHandler)1 TileEntityUrnOfSorrow (nex.tileentity.TileEntityUrnOfSorrow)1