codechicken.lib.inventory.InventoryRange Java Examples

The following examples show how to use codechicken.lib.inventory.InventoryRange. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TileItemTranslocator.java    From Translocators with MIT License 6 votes vote down vote up
private boolean isSatsified(ItemAttachment ia, InventoryRange access)
{
    boolean filterSet = false;
    for(ItemStack filter : ia.filters)
        if(filter != null)
        {
            filterSet = true;
            if(ia.regulate)
            {
                if(countMatchingStacks(access, filter, !ia.a_eject) < filterCount(ia, filter))
                    return false;
            }
            else
            {
                if(InventoryUtils.getInsertibleQuantity(access, filter) > 0)
                    return false;
            }
        }
    
    return filterSet || !hasEmptySpace(access);
}
 
Example #2
Source File: TileItemTranslocator.java    From Translocators with MIT License 5 votes vote down vote up
private boolean canTransferFilter(ItemAttachment ia, InventoryRange access, InventoryRange[] attached)
{
    boolean filterSet = false;
    for(ItemStack filter : ia.filters)
        if(filter != null)
        {
            filterSet = true;
            if((!ia.regulate || countMatchingStacks(access, filter, false) > filterCount(ia, filter)) && 
                    insertAmount(filter, attached) > 0)
                return true;
        }
    
    return !filterSet;
}
 
Example #3
Source File: TileItemTranslocator.java    From Translocators with MIT License 5 votes vote down vote up
private boolean hasEmptySpace(InventoryRange inv)
{
    for(int slot : inv.slots)
    {
        ItemStack stack = inv.inv.getStackInSlot(slot);
        if(inv.canInsertItem(slot, new ItemStack(Items.diamond)) &&
                (stack == null || 
                stack.isStackable() && stack.stackSize < Math.min(stack.getMaxStackSize(), inv.inv.getInventoryStackLimit())))
            return true;
    }
    return false;
}
 
Example #4
Source File: TileItemTranslocator.java    From Translocators with MIT License 5 votes vote down vote up
private void spreadOutput(ItemStack move, int src, boolean rspass, InventoryRange[] attached)
{
    if(move.stackSize == 0)
        return;
    
    int outputCount = 0;
    int[] outputQuantities = new int[6];
    for(int i = 0; i < 6; i++)
    {
        ItemAttachment ia = (ItemAttachment) attachments[i];
        if(ia != null && !ia.a_eject && ia.redstone == rspass)
        {
            outputQuantities[i] = insertAmount(move, ia, attached[i]);
            if(outputQuantities[i] > 0)
                outputCount++;
        }
    }
    
    for(int dst = 0; dst < 6 && move.stackSize > 0; dst++)
    {
        int qty = outputQuantities[dst];
        if(qty <= 0)
            continue;
        
        qty = Math.min(qty, move.stackSize/outputCount + worldObj.rand.nextInt(move.stackSize%outputCount+1));
        outputCount--;
        
        if(qty == 0)
            continue;

        InventoryRange range = attached[dst];
        ItemStack add = InventoryUtils.copyStack(move, qty);
        InventoryUtils.insertItem(range, add, false);
        move.stackSize-=qty;
        
        sendTransferPacket(src, dst, add);
    }
}
 
Example #5
Source File: TileItemTranslocator.java    From Translocators with MIT License 5 votes vote down vote up
private int countMatchingStacks(InventoryRange inv, ItemStack filter, boolean insertable)
{
    int c = 0;
    for(int slot : inv.slots)
    {
        ItemStack stack = inv.inv.getStackInSlot(slot);
        if(stack != null && matches(filter, stack) && 
                (insertable ? inv.canInsertItem(slot, stack) : inv.canExtractItem(slot, stack)))
            c+=stack.stackSize;
    }
    return c;
}
 
Example #6
Source File: TileItemTranslocator.java    From Translocators with MIT License 5 votes vote down vote up
private int insertAmount(ItemStack stack, ItemAttachment ia, InventoryRange range)
{
    int filter = filterCount(ia, stack);
    if(filter == 0)
        return 0;
    
    int fit = InventoryUtils.getInsertibleQuantity(range, stack);
    if(fit == 0)
        return 0;

    if(ia.regulate && filter > 0)
        fit = Math.min(fit, filter-countMatchingStacks(range, stack, true));
    
    return fit > 0 ? fit : 0;
}
 
Example #7
Source File: TileItemTranslocator.java    From Translocators with MIT License 5 votes vote down vote up
private int extractAmount(ItemStack stack, ItemAttachment ia, InventoryRange range)
{
    int filter = filterCount(ia, stack);
    if(filter == 0)
        return ia.regulate ? stack.getMaxStackSize() : 0;
    
    int qty = filter < 0 ? stack.getMaxStackSize() : filter;
    
    if(ia.regulate && filter > 0)
        qty = Math.min(qty, countMatchingStacks(range, stack, false)-filter);
    
    return qty > 0 ? qty : 0;
}
 
Example #8
Source File: NEIServerUtils.java    From NotEnoughItems with MIT License 4 votes vote down vote up
public static boolean canItemFitInInventory(EntityPlayer player, ItemStack itemstack) {
    return InventoryUtils.insertItem(new InventoryRange(player.inventory, 0, 36), itemstack, true) == 0;
}
 
Example #9
Source File: NEIClientUtils.java    From NotEnoughItems with MIT License 4 votes vote down vote up
public static boolean canItemFitInInventory(EntityPlayer player, ItemStack itemstack) {
    return InventoryUtils.getInsertibleQuantity(new InventoryRange(player.inventory, 0, 36), itemstack) > 0;
}
 
Example #10
Source File: NEIServerUtils.java    From NotEnoughItems with MIT License 4 votes vote down vote up
public static boolean canItemFitInInventory(EntityPlayer player, ItemStack itemstack) {
    return InventoryUtils.insertItem(new InventoryRange(player.inventory, 0, 36), itemstack, true) == 0;
}
 
Example #11
Source File: NEIClientUtils.java    From NotEnoughItems with MIT License 4 votes vote down vote up
public static boolean canItemFitInInventory(EntityPlayer player, ItemStack itemstack) {
    return InventoryUtils.getInsertibleQuantity(new InventoryRange(player.inventory, 0, 36), itemstack) > 0;
}