Example usage for net.minecraftforge.items IItemHandler getSlotLimit

List of usage examples for net.minecraftforge.items IItemHandler getSlotLimit

Introduction

In this page you can find the example usage for net.minecraftforge.items IItemHandler getSlotLimit.

Prototype

int getSlotLimit(int slot);

Source Link

Document

Retrieves the maximum stack size allowed to exist in the given slot.

Usage

From source file:ru.ivansteklow.isdev.utils.Utils.java

License:Apache License

/**
 * Checks if the inventory is full//from ww w  . j  a  v a 2  s .  c o  m
 * 
 * @param handler
 *            The inventory
 * @return true if it is full
 */
public static boolean isInventoryFull(IItemHandler handler) {
    int filledSlots = 0;
    for (int slot = 0; slot < handler.getSlots(); slot++) {
        if (handler.getStackInSlot(slot).getCount() == handler.getSlotLimit(slot))
            filledSlots++;
    }
    return filledSlots == handler.getSlots();
}

From source file:ru.ivansteklow.isdev.utils.Utils.java

License:Apache License

/**
 * Checks if the inventory is full//from ww w.j  a v  a 2  s .c  om
 * 
 * @param handler
 *            The inventory
 * @param maxSlot
 *            The number of slots to check
 * @return true if it is full
 */
public static boolean isInventoryFull(IItemHandler handler, int maxSlot) {
    int filledSlots = 0;
    for (int slot = 0; slot < maxSlot; slot++) {
        if (handler.getStackInSlot(slot).getCount() == handler.getSlotLimit(slot))
            filledSlots++;
    }
    return filledSlots == maxSlot;
}

From source file:therogue.storehouse.multiblock.block.ItemCapabilityWrapper.java

License:Open Source License

@Override
public IItemHandler getWrappedCapability(IItemHandler wrappable) {
    return new IItemHandler() {

        @Override// ww w .ja va 2  s  . c om
        public int getSlots() {
            return wrappable.getSlots();
        }

        @Override
        public ItemStack getStackInSlot(int slot) {
            return wrappable.getStackInSlot(slot);
        }

        @Override
        public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
            return canInsert ? wrappable.insertItem(slot, stack, simulate) : stack;
        }

        @Override
        public ItemStack extractItem(int slot, int amount, boolean simulate) {
            return canExtract ? wrappable.extractItem(slot, amount, simulate) : ItemStack.EMPTY;
        }

        @Override
        public int getSlotLimit(int slot) {
            return wrappable.getSlotLimit(slot);
        }
    };
}

From source file:therogue.storehouse.tile.machine.TileCrystaliser.java

License:Open Source License

@Override
public void update() {
    if (GeneralUtils.isServerSide(world)) {
        IItemHandler internalView = this.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null,
                ModuleContext.INTERNAL);
        if (!internalView.getStackInSlot(2).isEmpty()) {
            ItemStack tankItem = internalView.extractItem(2, -1, true);
            ItemStack outputSlot = internalView.getStackInSlot(3);
            ItemStack result = FluidUtil.tryEmptyContainer(tankItem, tank,
                    tank.getCapacity() - tank.getFluidAmount(), null, false).result;
            if (ItemStackUtils.areStacksMergableWithLimit(internalView.getSlotLimit(3), result, outputSlot)) {
                internalView.extractItem(2, -1, false);
                internalView.insertItem(3,
                        ItemStackUtils.mergeStacks(internalView.getSlotLimit(3), true,
                                internalView.extractItem(3, -1, false), FluidUtil.tryEmptyContainer(tankItem,
                                        tank, tank.getCapacity() - tank.getFluidAmount(), null, true).result),
                        false);/*from  w  w  w .ja  v a 2 s  .  c  om*/
            }
        }
    }
}

From source file:therogue.storehouse.tile.machine.TileLiquidGenerator.java

License:Open Source License

@Override
public void update() {
    super.update();
    if (GeneralUtils.isServerSide(world)) {
        IItemHandler internalView = inventory.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null,
                ModuleContext.INTERNAL);
        if (!internalView.getStackInSlot(2).isEmpty()) {
            ItemStack tankItem = internalView.extractItem(2, -1, true);
            ItemStack outputSlot = internalView.getStackInSlot(3);
            ItemStack result = FluidUtil.tryEmptyContainer(tankItem, tank,
                    tank.getCapacity() - tank.getFluidAmount(), null, false).result;
            if (ItemStackUtils.areStacksMergableWithLimit(internalView.getSlotLimit(3), result, outputSlot)) {
                internalView.extractItem(2, -1, false);
                internalView.insertItem(3,
                        ItemStackUtils.mergeStacks(internalView.getSlotLimit(3), true,
                                internalView.extractItem(3, -1, false), FluidUtil.tryEmptyContainer(tankItem,
                                        tank, tank.getCapacity() - tank.getFluidAmount(), null, true).result),
                        false);// w  ww.  j a v a  2s . c  om
            }
        }
    }
}