Example usage for net.minecraftforge.items ItemStackHandler getSlotLimit

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

Introduction

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

Prototype

@Override
    public int getSlotLimit(int slot) 

Source Link

Usage

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

License:Apache License

/**
 * Calculate the redstone current from a item stack handler
 * //from  w  w  w .  ja  v  a 2 s  .  c  o m
 * @param handler
 *            The handler
 * @return The redstone power
 */
public static int calculateRedstone(ItemStackHandler handler) {
    int i = 0;
    float f = 0.0F;
    for (int j = 0; j < handler.getSlots(); j++) {
        ItemStack stack = handler.getStackInSlot(j);
        if (!stack.isEmpty()) {
            f += (float) stack.getCount() / (float) Math.min(handler.getSlotLimit(j), stack.getMaxStackSize());
            i++;
        }
    }
    f = f / (float) handler.getSlots();
    return MathHelper.floor(f * 14.0F) + (i > 0 ? 1 : 0);
}