Search in sources :

Example 31 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.

the class LogisticsCraftingTable method importFuzzyFlags.

@Override
public void importFuzzyFlags(TileEntity tile, ItemIdentifierInventory inventory, DictResource[] flags, DictResource output) {
    if (!(tile instanceof LogisticsCraftingTableTileEntity)) {
        return;
    }
    LogisticsCraftingTableTileEntity bench = (LogisticsCraftingTableTileEntity) tile;
    if (!bench.isFuzzy()) {
        return;
    }
    for (int i = 0; i < bench.fuzzyFlags.length; i++) {
        if (i >= flags.length) {
            break;
        }
        flags[i].loadFromBitSet(bench.fuzzyFlags[i].getBitSet());
    }
    output.loadFromBitSet(bench.outputFuzzyFlags.getBitSet());
    for (int i = 0; i < 9; i++) {
        final ItemIdentifierStack stackInSlot = inventory.getIDStackInSlot(i);
        if (stackInSlot == null) {
            continue;
        }
        final ItemIdentifier itemInSlot = stackInSlot.getItem();
        for (int j = i + 1; j < 9; j++) {
            final ItemIdentifierStack stackInOtherSlot = inventory.getIDStackInSlot(j);
            if (stackInOtherSlot == null) {
                continue;
            }
            if (itemInSlot.equals(stackInOtherSlot.getItem()) && flags[i].getBitSet().equals(flags[j].getBitSet())) {
                stackInSlot.setStackSize(stackInSlot.getStackSize() + stackInOtherSlot.getStackSize());
                inventory.clearInventorySlotContents(j);
                // clear
                flags[j].loadFromBitSet(new BitSet());
            }
        }
        inventory.setInventorySlotContents(i, stackInSlot);
    }
    for (int i = 0; i < 9; i++) {
        if (inventory.getStackInSlot(i) != null) {
            continue;
        }
        for (int j = i + 1; j < 9; j++) {
            if (inventory.getStackInSlot(j) == null) {
                continue;
            }
            inventory.setInventorySlotContents(i, inventory.getStackInSlot(j));
            flags[i].loadFromBitSet(flags[j].getBitSet());
            inventory.clearInventorySlotContents(j);
            // clear
            flags[j].loadFromBitSet(new BitSet());
            break;
        }
    }
    return;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) BitSet(java.util.BitSet) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity)

Example 32 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.

the class ItemAmountPipeSign method spread.

private void spread(Map<ItemIdentifier, Integer> availableItems, BitSet set) {
    // Improve performance by updating a wall of Amount pipe signs all at once
    IRouter router = pipe.getRouter();
    if (set.get(router.getSimpleID()))
        return;
    set.set(router.getSimpleID());
    for (ExitRoute exit : router.getIRoutersByCost()) {
        // Only when the signs are in one wall. To not spread to far.
        if (exit.distanceToDestination > 2)
            break;
        if (!exit.filters.isEmpty())
            continue;
        if (set.get(exit.destination.getSimpleID()))
            continue;
        if (exit.connectionDetails.contains(PipeRoutingConnectionType.canRequestFrom) && exit.connectionDetails.contains(PipeRoutingConnectionType.canRouteTo)) {
            CoreRoutedPipe cachedPipe = exit.destination.getCachedPipe();
            if (cachedPipe != null) {
                List<Pair<ForgeDirection, IPipeSign>> pipeSigns = cachedPipe.getPipeSigns();
                pipeSigns.stream().filter(signPair -> signPair != null && signPair.getValue2() instanceof ItemAmountPipeSign).forEach(signPair -> ((ItemAmountPipeSign) signPair.getValue2()).updateStats(availableItems, set));
            }
        }
    }
}
Also used : IRouter(logisticspipes.routing.IRouter) Item(net.minecraft.item.Item) MainProxy(logisticspipes.proxy.MainProxy) StringUtils(logisticspipes.utils.string.StringUtils) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) LogisticsRenderPipe(logisticspipes.renderer.LogisticsRenderPipe) GL11(org.lwjgl.opengl.GL11) ItemAmountSignUpdatePacket(logisticspipes.network.packets.pipe.ItemAmountSignUpdatePacket) ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NewGuiHandler(logisticspipes.network.NewGuiHandler) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) Side(cpw.mods.fml.relauncher.Side) ItemAmountSignGui(logisticspipes.network.guis.item.ItemAmountSignGui) SideOnly(cpw.mods.fml.relauncher.SideOnly) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) PacketHandler(logisticspipes.network.PacketHandler) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ExitRoute(logisticspipes.routing.ExitRoute) ServerRouter(logisticspipes.routing.ServerRouter) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) ISimpleInventoryEventHandler(logisticspipes.utils.ISimpleInventoryEventHandler) List(java.util.List) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) FontRenderer(net.minecraft.client.gui.FontRenderer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) IInventory(net.minecraft.inventory.IInventory) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) Data(lombok.Data) BitSet(java.util.BitSet) IRouter(logisticspipes.routing.IRouter) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ExitRoute(logisticspipes.routing.ExitRoute) Pair(logisticspipes.utils.tuples.Pair)

Example 33 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.

the class ItemAmountPipeSign method updateServerSide.

@Override
public void updateServerSide() {
    if (!pipe.isNthTick(20)) {
        return;
    }
    if (hasUpdated) {
        hasUpdated = false;
        return;
    }
    int newAmount = 0;
    if (itemTypeInv.getIDStackInSlot(0) != null) {
        Map<ItemIdentifier, Integer> availableItems = SimpleServiceLocator.logisticsManager.getAvailableItems(pipe.getRouter().getIRoutersByCost());
        if (availableItems != null) {
            BitSet set = new BitSet(ServerRouter.getBiggestSimpleID());
            spread(availableItems, set);
            if (availableItems.containsKey(itemTypeInv.getIDStackInSlot(0).getItem())) {
                newAmount = availableItems.get(itemTypeInv.getIDStackInSlot(0).getItem());
            }
        }
    }
    if (newAmount != amount) {
        amount = newAmount;
        sendUpdatePacket();
    }
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) BitSet(java.util.BitSet)

Example 34 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.

the class AssemblyAdvancedWorkbench method importRecipe.

@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
    if (!(tile instanceof TileAdvancedCraftingTable)) {
        return false;
    }
    TileAdvancedCraftingTable bench = (TileAdvancedCraftingTable) tile;
    ItemStack result = bench.getOutputSlot().getStackInSlot(0);
    if (result == null) {
        return false;
    }
    inventory.setInventorySlotContents(9, result);
    // Import
    for (int i = 0; i < bench.getCraftingSlots().getSizeInventory(); i++) {
        if (i >= inventory.getSizeInventory() - 2) {
            break;
        }
        final ItemStack newStack = bench.getCraftingSlots().getStackInSlot(i) == null ? null : bench.getCraftingSlots().getStackInSlot(i).copy();
        inventory.setInventorySlotContents(i, newStack);
    }
    // Compact
    for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
        final ItemIdentifierStack stackInSlot = inventory.getIDStackInSlot(i);
        if (stackInSlot == null) {
            continue;
        }
        final ItemIdentifier itemInSlot = stackInSlot.getItem();
        for (int j = i + 1; j < inventory.getSizeInventory() - 2; j++) {
            final ItemIdentifierStack stackInOtherSlot = inventory.getIDStackInSlot(j);
            if (stackInOtherSlot == null) {
                continue;
            }
            if (itemInSlot.equals(stackInOtherSlot.getItem())) {
                stackInSlot.setStackSize(stackInSlot.getStackSize() + stackInOtherSlot.getStackSize());
                inventory.setInventorySlotContents(i, stackInSlot);
                inventory.clearInventorySlotContents(j);
            }
        }
    }
    for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
        if (inventory.getStackInSlot(i) != null) {
            continue;
        }
        for (int j = i + 1; j < inventory.getSizeInventory() - 2; j++) {
            if (inventory.getStackInSlot(j) == null) {
                continue;
            }
            inventory.setInventorySlotContents(i, inventory.getIDStackInSlot(j));
            inventory.clearInventorySlotContents(j);
            break;
        }
    }
    return true;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) TileAdvancedCraftingTable(buildcraft.silicon.TileAdvancedCraftingTable) ItemStack(net.minecraft.item.ItemStack) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 35 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.

the class AEInterfaceInventoryHandler method getItems.

@Override
public Set<ItemIdentifier> getItems() {
    Set<ItemIdentifier> result = new TreeSet<>();
    IStorageMonitorable tmp = tile.getMonitorable(dir, source);
    if (tmp == null || tmp.getItemInventory() == null || tmp.getItemInventory().getStorageList() == null) {
        return result;
    }
    for (IAEItemStack items : tmp.getItemInventory().getStorageList()) {
        ItemIdentifier ident = ItemIdentifier.get(items.getItemStack());
        result.add(ident);
    }
    return result;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) TreeSet(java.util.TreeSet) IAEItemStack(appeng.api.storage.data.IAEItemStack) IStorageMonitorable(appeng.api.storage.IStorageMonitorable)

Aggregations

ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)69 ItemStack (net.minecraft.item.ItemStack)37 ArrayList (java.util.ArrayList)23 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)23 HashMap (java.util.HashMap)14 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)13 TreeSet (java.util.TreeSet)12 IFilter (logisticspipes.interfaces.routing.IFilter)11 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)11 LinkedList (java.util.LinkedList)10 List (java.util.List)10 Map (java.util.Map)10 SinkReply (logisticspipes.utils.SinkReply)10 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)9 IRouter (logisticspipes.routing.IRouter)9 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)9 BitSet (java.util.BitSet)8 Entry (java.util.Map.Entry)7 LogisticsModule (logisticspipes.modules.abstractmodules.LogisticsModule)7 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)7