Search in sources :

Example 51 with ItemIdentifier

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

the class ModuleItemSink method sinksItem.

@Override
public SinkReply sinksItem(ItemIdentifier item, int bestPriority, int bestCustomPriority, boolean allowDefault, boolean includeInTransit) {
    if (_isDefaultRoute && !allowDefault) {
        return null;
    }
    if (bestPriority > _sinkReply.fixedPriority.ordinal() || (bestPriority == _sinkReply.fixedPriority.ordinal() && bestCustomPriority >= _sinkReply.customPriority)) {
        return null;
    }
    if (_filterInventory.containsUndamagedItem(item.getUndamaged())) {
        if (_service.canUseEnergy(1)) {
            return _sinkReply;
        }
        return null;
    }
    if (_service.getUpgradeManager(slot, positionInt).isFuzzyUpgrade()) {
        for (Pair<ItemIdentifierStack, Integer> stack : _filterInventory) {
            if (stack == null) {
                continue;
            }
            if (stack.getValue1() == null) {
                continue;
            }
            ItemIdentifier ident1 = item;
            ItemIdentifier ident2 = stack.getValue1().getItem();
            if (ignoreData.get(stack.getValue2())) {
                ident1 = ident1.getIgnoringData();
                ident2 = ident2.getIgnoringData();
            }
            if (ignoreNBT.get(stack.getValue2())) {
                ident1 = ident1.getIgnoringNBT();
                ident2 = ident2.getIgnoringNBT();
            }
            if (ident1.equals(ident2)) {
                if (_service.canUseEnergy(5)) {
                    return _sinkReply;
                }
                return null;
            }
        }
    }
    if (_isDefaultRoute) {
        if (bestPriority > _sinkReplyDefault.fixedPriority.ordinal() || (bestPriority == _sinkReplyDefault.fixedPriority.ordinal() && bestCustomPriority >= _sinkReplyDefault.customPriority)) {
            return null;
        }
        if (_service.canUseEnergy(1)) {
            return _sinkReplyDefault;
        }
        return null;
    }
    return null;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 52 with ItemIdentifier

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

the class ModuleItemSink method importFromInventory.

public void importFromInventory() {
    if (_service == null) {
        return;
    }
    IInventoryUtil inv = _service.getPointedInventory(false);
    if (inv == null) {
        return;
    }
    int count = 0;
    for (ItemIdentifier item : inv.getItems()) {
        _filterInventory.setInventorySlotContents(count, item.makeStack(1));
        count++;
        if (count >= _filterInventory.getSizeInventory()) {
            break;
        }
    }
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil)

Example 53 with ItemIdentifier

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

the class PipeFluidProvider method getSpecificInterests.

@Override
public //work in progress, currently not active code.
Set<ItemIdentifier> getSpecificInterests() {
    Set<ItemIdentifier> l1 = new TreeSet<>();
    for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(false)) {
        boolean fallback = true;
        if (SimpleServiceLocator.specialTankHandler.hasHandlerFor(pair.getValue1())) {
            ISpecialTankHandler handler = SimpleServiceLocator.specialTankHandler.getTankHandlerFor(pair.getValue1());
            if (handler instanceof ISpecialTankAccessHandler) {
                fallback = false;
                Map<FluidIdentifier, Long> map = ((ISpecialTankAccessHandler) handler).getAvailableLiquid(pair.getValue1());
                l1.addAll(map.keySet().stream().map(FluidIdentifier::getItemIdentifier).collect(Collectors.toList()));
            }
        }
        if (fallback) {
            FluidTankInfo[] tanks = ((IFluidHandler) pair.getValue1()).getTankInfo(pair.getValue2().getOpposite());
            if (tanks != null) {
                for (FluidTankInfo tank : tanks) {
                    if (tank == null) {
                        continue;
                    }
                    FluidStack liquid;
                    if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
                        if (((IFluidHandler) pair.getValue1()).canDrain(pair.getValue2().getOpposite(), liquid.getFluid())) {
                            if (((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), 1, false) != null) {
                                FluidIdentifier ident = FluidIdentifier.get(liquid);
                                l1.add(ident.getItemIdentifier());
                            }
                        }
                    }
                }
            }
        }
    }
    return l1;
}
Also used : ISpecialTankHandler(logisticspipes.interfaces.ISpecialTankHandler) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) FluidStack(net.minecraftforge.fluids.FluidStack) ISpecialTankAccessHandler(logisticspipes.interfaces.ISpecialTankAccessHandler) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) TileEntity(net.minecraft.tileentity.TileEntity) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) TreeSet(java.util.TreeSet) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 54 with ItemIdentifier

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

the class PipeItemsFluidSupplier method throttledUpdateEntity.

@Override
public void throttledUpdateEntity() {
    if (!isEnabled()) {
        return;
    }
    if (MainProxy.isClient(getWorld())) {
        return;
    }
    super.throttledUpdateEntity();
    //@formatter:off
    Iterator<IFluidHandler> iterator = new WorldCoordinatesWrapper(container).getConnectedAdjacentTileEntities().filter(adjacent -> adjacent.tileEntity instanceof IFluidHandler).filter(adjacent -> !SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)).map(adjacent -> (IFluidHandler) adjacent.tileEntity).iterator();
    while (iterator.hasNext()) {
        IFluidHandler next = iterator.next();
        FluidTankInfo[] result = next.getTankInfo(ForgeDirection.UNKNOWN);
        if (result == null || result.length == 0) {
            continue;
        }
        //How much do I want?
        Map<ItemIdentifier, Integer> wantContainers = dummyInventory.getItemsAndCount();
        HashMap<FluidIdentifier, Integer> wantFluids = new HashMap<>();
        for (Entry<ItemIdentifier, Integer> item : wantContainers.entrySet()) {
            ItemStack wantItem = item.getKey().unsafeMakeNormalStack(1);
            FluidStack liquidstack = FluidContainerRegistry.getFluidForFilledItem(wantItem);
            if (liquidstack == null) {
                continue;
            }
            wantFluids.put(FluidIdentifier.get(liquidstack), item.getValue() * liquidstack.amount);
        }
        //How much do I have?
        HashMap<FluidIdentifier, Integer> haveFluids = new HashMap<>();
        for (FluidTankInfo slot : result) {
            if (slot == null || slot.fluid == null || slot.fluid.getFluidID() == 0 || !wantFluids.containsKey(FluidIdentifier.get(slot.fluid))) {
                continue;
            }
            Integer liquidWant = haveFluids.get(FluidIdentifier.get(slot.fluid));
            if (liquidWant == null) {
                haveFluids.put(FluidIdentifier.get(slot.fluid), slot.fluid.amount);
            } else {
                haveFluids.put(FluidIdentifier.get(slot.fluid), liquidWant + slot.fluid.amount);
            }
        }
        //Reduce what I have and what have been requested already
        for (Entry<FluidIdentifier, Integer> liquidId : wantFluids.entrySet()) {
            Integer haveCount = haveFluids.get(liquidId.getKey());
            if (haveCount != null) {
                liquidId.setValue(liquidId.getValue() - haveCount);
            }
        }
        for (Entry<ItemIdentifier, Integer> requestedItem : _requestedItems.entrySet()) {
            ItemStack wantItem = requestedItem.getKey().unsafeMakeNormalStack(1);
            FluidStack requestedFluidId = FluidContainerRegistry.getFluidForFilledItem(wantItem);
            if (requestedFluidId == null) {
                continue;
            }
            FluidIdentifier requestedFluid = FluidIdentifier.get(requestedFluidId);
            Integer want = wantFluids.get(requestedFluid);
            if (want != null) {
                wantFluids.put(requestedFluid, want - requestedItem.getValue() * requestedFluidId.amount);
            }
        }
        ((PipeItemsFluidSupplier) container.pipe).setRequestFailed(false);
        for (ItemIdentifier need : wantContainers.keySet()) {
            FluidStack requestedFluidId = FluidContainerRegistry.getFluidForFilledItem(need.unsafeMakeNormalStack(1));
            if (requestedFluidId == null) {
                continue;
            }
            if (!wantFluids.containsKey(FluidIdentifier.get(requestedFluidId))) {
                continue;
            }
            int countToRequest = wantFluids.get(FluidIdentifier.get(requestedFluidId)) / requestedFluidId.amount;
            if (countToRequest < 1) {
                continue;
            }
            if (!useEnergy(11)) {
                break;
            }
            boolean success = false;
            if (_requestPartials) {
                countToRequest = RequestTree.requestPartial(need.makeStack(countToRequest), (IRequestItems) container.pipe, null);
                if (countToRequest > 0) {
                    success = true;
                }
            } else {
                success = RequestTree.request(need.makeStack(countToRequest), (IRequestItems) container.pipe, null, null);
            }
            if (success) {
                Integer currentRequest = _requestedItems.get(need);
                if (currentRequest == null) {
                    _requestedItems.put(need, countToRequest);
                } else {
                    _requestedItems.put(need, currentRequest + countToRequest);
                }
            } else {
                ((PipeItemsFluidSupplier) container.pipe).setRequestFailed(true);
            }
        }
    }
}
Also used : FluidContainerRegistry(net.minecraftforge.fluids.FluidContainerRegistry) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) Textures(logisticspipes.textures.Textures) LogisticsPipes(logisticspipes.LogisticsPipes) Item(net.minecraft.item.Item) HashMap(java.util.HashMap) MainProxy(logisticspipes.proxy.MainProxy) IRequireReliableTransport(logisticspipes.interfaces.routing.IRequireReliableTransport) ItemStack(net.minecraft.item.ItemStack) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) Map(java.util.Map) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Iterator(java.util.Iterator) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) TextureType(logisticspipes.textures.Textures.TextureType) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) RequestTree(logisticspipes.request.RequestTree) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) PipeTransportLogistics(logisticspipes.transport.PipeTransportLogistics) CacheTypes(logisticspipes.utils.CacheHolder.CacheTypes) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) GuiIDs(logisticspipes.network.GuiIDs) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) HashMap(java.util.HashMap) FluidStack(net.minecraftforge.fluids.FluidStack) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) ItemStack(net.minecraft.item.ItemStack)

Example 55 with ItemIdentifier

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

the class PipeItemsInvSysConnector method getExpectedItems.

public Set<ItemIdentifierStack> getExpectedItems() {
    // got to be a TreeMap, because a TreeSet doesn't have the ability to retrieve the key.
    Set<ItemIdentifierStack> list = new TreeSet<>();
    for (Entry<ItemIdentifier, List<ItemRoutingInformation>> entry : itemsOnRoute.entrySet()) {
        if (entry.getValue().isEmpty()) {
            continue;
        }
        ItemIdentifierStack currentStack = new ItemIdentifierStack(entry.getKey(), 0);
        for (ItemRoutingInformation e : entry.getValue()) {
            currentStack.setStackSize(currentStack.getStackSize() + e.getItem().getStackSize());
        }
        list.add(currentStack);
    }
    return list;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) TreeSet(java.util.TreeSet) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

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