Search in sources :

Example 1 with TileItemInterface

use of com.cjm721.overloaded.block.tile.TileItemInterface in project Overloaded by CJ-MC-Mods.

the class BlockItemInterface method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (worldIn.isRemote)
        return true;
    TileEntity te = worldIn.getTileEntity(pos);
    if (!(te instanceof TileItemInterface))
        return true;
    TileItemInterface anInterface = (TileItemInterface) te;
    ItemStack stack = anInterface.getStoredItem();
    if (stack.isEmpty()) {
        ItemStack handStack = playerIn.getHeldItem(hand);
        if (handStack.isEmpty())
            return true;
        ItemStack returnedItem = anInterface.insertItem(0, handStack, false);
        playerIn.setHeldItem(hand, returnedItem);
    } else {
        if (!playerIn.getHeldItem(hand).isEmpty())
            return true;
        ItemStack toSpawn = anInterface.extractItem(0, 1, false);
        if (toSpawn.isEmpty())
            return true;
        worldIn.spawnEntity(new EntityItem(worldIn, playerIn.posX, playerIn.posY, playerIn.posZ, toSpawn));
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ItemStack(net.minecraft.item.ItemStack) TileItemInterface(com.cjm721.overloaded.block.tile.TileItemInterface) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

TileItemInterface (com.cjm721.overloaded.block.tile.TileItemInterface)1 EntityItem (net.minecraft.entity.item.EntityItem)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1