Example usage for net.minecraftforge.items ItemStackHandler setStackInSlot

List of usage examples for net.minecraftforge.items ItemStackHandler setStackInSlot

Introduction

In this page you can find the example usage for net.minecraftforge.items ItemStackHandler setStackInSlot.

Prototype

@Override
    public void setStackInSlot(int slot, @Nonnull ItemStack stack) 

Source Link

Usage

From source file:com.buuz135.industrial.utils.ItemStackUtils.java

License:Open Source License

public static void fillItemFromTank(ItemStackHandler fluidItems, IFluidTank tank) {
    if (tank.getFluid() == null)
        return;//from   w ww .ja v  a2 s  .  c o  m
    ItemStack stack = fluidItems.getStackInSlot(0).copy();
    if (!stack.isEmpty()) {
        if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
            FluidActionResult result = FluidUtil.tryFillContainer(stack, (IFluidHandler) tank,
                    tank.getCapacity(), null, false);
            if (result.isSuccess() && (fluidItems.getStackInSlot(1).isEmpty()
                    || (ItemHandlerHelper.canItemStacksStack(result.getResult(), fluidItems.getStackInSlot(1))
                            && result.getResult().getCount() + fluidItems.getStackInSlot(1).getCount() <= result
                                    .getResult().getMaxStackSize()))) {
                result = FluidUtil.tryFillContainer(stack, (IFluidHandler) tank, tank.getCapacity(), null,
                        true);
                if (fluidItems.getStackInSlot(1).isEmpty()) {
                    fluidItems.setStackInSlot(1, result.getResult());
                } else {
                    fluidItems.getStackInSlot(1).grow(1);
                }
                fluidItems.getStackInSlot(0).shrink(1);
            }
        }
    }
}

From source file:com.buuz135.industrial.utils.ItemStackUtils.java

License:Open Source License

public static void fillTankFromItem(ItemStackHandler fluidItems, IFluidTank tank) {
    ItemStack stack = fluidItems.getStackInSlot(0).copy();
    if (!stack.isEmpty()) {
        if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
            IFluidHandlerItem cap = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY,
                    null);/*from   www.j a va  2s.c om*/
            FluidStack fluidStack = cap.drain(1000, false);
            if (fluidStack != null && tank.fill(fluidStack, false) == 0)
                return;
            FluidActionResult result = FluidUtil.tryEmptyContainer(stack, (IFluidHandler) tank, 1000, null,
                    false);
            if (result.isSuccess() && (fluidItems.getStackInSlot(1).isEmpty()
                    || (ItemHandlerHelper.canItemStacksStack(result.getResult(), fluidItems.getStackInSlot(1))
                            && result.getResult().getCount() + fluidItems.getStackInSlot(1).getCount() <= result
                                    .getResult().getMaxStackSize()))) {
                result = FluidUtil.tryEmptyContainer(stack, (IFluidHandler) tank, tank.getCapacity(), null,
                        true);
                if (fluidItems.getStackInSlot(1).isEmpty()) {
                    fluidItems.setStackInSlot(1, result.getResult());
                } else {
                    fluidItems.getStackInSlot(1).grow(1);
                }
                fluidItems.getStackInSlot(0).shrink(1);
            }
        }
    }
}

From source file:daxum.temporalconvergence.block.BlockBrazier.java

License:Open Source License

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    if (world.getTileEntity(pos) instanceof TileBrazier) {
        ItemStackHandler invToDrop = ((TileBrazier) world.getTileEntity(pos)).getInventory();

        for (int i = 0; i < invToDrop.getSlots(); i++) {
            InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(),
                    invToDrop.getStackInSlot(i));
            invToDrop.setStackInSlot(i, ItemStack.EMPTY);
        }/*from www  . j a  v a  2 s.co m*/
    }

    if (world.getBlockState(pos.down()).getBlock() instanceof BlockBrazierBottom) {
        world.setBlockToAir(pos.down());
    }
}

From source file:daxum.temporalconvergence.block.BlockCrafter.java

License:Open Source License

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    if (world.getTileEntity(pos) instanceof TileCrafter) {
        ItemStackHandler inventory = ((TileCrafter) world.getTileEntity(pos)).getInventory();

        for (int i = 0; i < inventory.getSlots(); i++) {
            InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(),
                    inventory.getStackInSlot(i));
            inventory.setStackInSlot(i, ItemStack.EMPTY);
        }//from w w  w.ja v  a  2 s .com
    }
}

From source file:daxum.temporalconvergence.block.BlockFutureChest.java

License:Open Source License

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    if (world.getTileEntity(pos) instanceof TileFutureChest) {
        ItemStackHandler invToDrop = ((TileFutureChest) world.getTileEntity(pos)).getInventory();

        for (int i = 0; i < invToDrop.getSlots(); i++) {
            InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(),
                    invToDrop.getStackInSlot(i));
            invToDrop.setStackInSlot(i, ItemStack.EMPTY);
        }/*w  ww  . jav a 2 s .c om*/
    }
}

From source file:daxum.temporalconvergence.block.BlockPedestal.java

License:Open Source License

@Override
//Once again, x, y, and z ARE NOT WORLD COORDINATES!!!!
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player,
        EnumHand hand, EnumFacing facing, float x, float y, float z) {
    if (!world.isRemote && world.getTileEntity(pos) instanceof TilePedestal) {
        ItemStackHandler inventory = ((TilePedestal) world.getTileEntity(pos)).getInventory();
        ItemStack playerStack = player.getHeldItemMainhand();
        ItemStack invStack = inventory.getStackInSlot(0);

        if (!invStack.isEmpty()) {
            world.spawnEntity(/*from w w  w.jav a  2 s.  com*/
                    new EntityItem(world, pos.getX() + 0.5f, pos.getY() + 1.0f, pos.getZ() + 0.5f, invStack));
            inventory.setStackInSlot(0, ItemStack.EMPTY);
        } else if (!playerStack.isEmpty()) {
            inventory.setStackInSlot(0, playerStack.splitStack(1));
        }
    }

    return true;
}

From source file:daxum.temporalconvergence.block.BlockPedestal.java

License:Open Source License

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    if (world.getTileEntity(pos) instanceof TilePedestal) {
        ItemStackHandler inventory = ((TilePedestal) world.getTileEntity(pos)).getInventory();

        InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), inventory.getStackInSlot(0));
        inventory.setStackInSlot(0, ItemStack.EMPTY);
    }//from  w  ww  .  j  a  v  a2  s.  c  o m

    DirectPowerHelper.signalProviderRemove(world, pos, TilePedestal.PROVIDER_RANGE);
}

From source file:daxum.temporalconvergence.block.BlockTimeChest.java

License:Open Source License

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    if (world.getTileEntity(pos) instanceof TileTimeChest) {
        ItemStackHandler invToDrop = ((TileTimeChest) world.getTileEntity(pos)).getInventory();

        for (int i = 0; i < invToDrop.getSlots(); i++) {
            InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(),
                    invToDrop.getStackInSlot(i)); //It doesn't count if Minecraft modifies the stack, right?
            invToDrop.setStackInSlot(i, ItemStack.EMPTY);
        }//  w w w.j  a v a 2 s  . c o  m
    }
}

From source file:daxum.temporalconvergence.block.BlockTimeFurnace.java

License:Open Source License

private void dropControllerInventory(World world, BlockPos pos, ItemStackHandler inventory) {
    for (int i = 0; i < inventory.getSlots(); i++) {
        InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), inventory.getStackInSlot(i));
        inventory.setStackInSlot(i, ItemStack.EMPTY);
    }//w  w  w . j a  v  a 2s  .  com
}

From source file:hellfirepvp.astralsorcery.common.block.network.BlockRitualPedestal.java

License:Open Source License

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
        EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    TileRitualPedestal pedestal = MiscUtils.getTileAt(worldIn, pos, TileRitualPedestal.class, true);
    if (pedestal == null) {
        return false;
    }//www. j  a  v a 2 s  .  c  o m
    ItemStack heldItem = playerIn.getHeldItem(hand);

    ItemStackHandler handle = pedestal.getInventoryHandler();
    ItemStack in = handle.getStackInSlot(0);
    if (!heldItem.isEmpty()) {
        Item i = heldItem.getItem();
        if (i instanceof ItemTunedCrystalBase) {
            if (in.isEmpty()) {
                handle.setStackInSlot(0, ItemUtils.copyStackWithSize(heldItem, 1));
                playerIn.setHeldItem(hand, ItemStack.EMPTY);
            }
        }
    }
    if (!in.isEmpty() && playerIn.isSneaking()) {
        ItemUtils.dropItem(worldIn, pos.getX() + 0.5, pos.getY() + 0.75, pos.getZ() + 0.5, in);
        handle.setStackInSlot(0, ItemStack.EMPTY);
    }
    return true;
}