Search in sources :

Example 1 with TileDollPedestal

use of mdc.voodoocraft.tile.TileDollPedestal in project VoodooCraft by Mod-DevCafeTeam.

the class BlockDollPedestal method onBlockActivated.

/**
	 * Puts dolls in and out of the pedestal.
	 * @return
	 */
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (hand == EnumHand.OFF_HAND || worldIn.getTileEntity(pos) == null)
        return false;
    TileDollPedestal tile = (TileDollPedestal) worldIn.getTileEntity(pos);
    IItemHandler tileinv = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    if (heldItem == null) {
        if (tileinv.getStackInSlot(0) != null) {
            playerIn.setHeldItem(hand, tileinv.getStackInSlot(0));
            tileinv.extractItem(0, tileinv.getStackInSlot(0).stackSize, false);
            return true;
        }
    } else {
        if (tileinv.getStackInSlot(0) == null) {
            tileinv.insertItem(0, heldItem, false);
            playerIn.setHeldItem(hand, null);
            return true;
        }
    }
    return false;
}
Also used : TileDollPedestal(mdc.voodoocraft.tile.TileDollPedestal) IItemHandler(net.minecraftforge.items.IItemHandler)

Example 2 with TileDollPedestal

use of mdc.voodoocraft.tile.TileDollPedestal in project VoodooCraft by Mod-DevCafeTeam.

the class BlockDollPedestal method breakBlock.

/**
	 * Drops item in the pedestal
	 * @param worldIn
	 * @param pos
	 * @param state
	 */
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    if (!worldIn.isRemote) {
        TileEntity te = worldIn.getTileEntity(pos);
        if (te != null) {
            TileDollPedestal tile = (TileDollPedestal) te;
            IItemHandler tileinv = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
            ItemStack stack = tileinv.getStackInSlot(0);
            if (stack != null) {
                EntityItem entItem = new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack);
                worldIn.spawnEntity(entItem);
            }
        }
    }
    super.breakBlock(worldIn, pos, state);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileDollPedestal(mdc.voodoocraft.tile.TileDollPedestal) IItemHandler(net.minecraftforge.items.IItemHandler) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

TileDollPedestal (mdc.voodoocraft.tile.TileDollPedestal)2 IItemHandler (net.minecraftforge.items.IItemHandler)2 EntityItem (net.minecraft.entity.item.EntityItem)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1