Search in sources :

Example 31 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class PipeTransportLogistics method writeToNBT.

public void writeToNBT(NBTTagCompound nbt) {
    {
        NBTTagList nbttaglist = new NBTTagList();
        for (LPTravelingItem item : items) {
            if (item instanceof LPTravelingItemServer) {
                NBTTagCompound dataTag = new NBTTagCompound();
                nbttaglist.appendTag(dataTag);
                ((LPTravelingItemServer) item).writeToNBT(dataTag);
            }
        }
        nbt.setTag("travelingEntities", nbttaglist);
    }
    NBTTagList nbttaglist2 = new NBTTagList();
    for (Pair<ItemIdentifierStack, Pair<Integer, Integer>> stack : _itemBuffer) {
        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
        stack.getValue1().makeNormalStack().writeToNBT(nbttagcompound1);
        nbttaglist2.appendTag(nbttagcompound1);
    }
    nbt.setTag("buffercontents", nbttaglist2);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer) Pair(logisticspipes.utils.tuples.Pair)

Example 32 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class PipeTransportLogistics method readFromNBT.

public void readFromNBT(NBTTagCompound nbt) {
    NBTTagList nbttaglist = nbt.getTagList("travelingEntities", 10);
    for (int j = 0; j < nbttaglist.tagCount(); ++j) {
        try {
            NBTTagCompound dataTag = nbttaglist.getCompoundTagAt(j);
            LPTravelingItem item = new LPTravelingItemServer(dataTag);
            if (item.isCorrupted()) {
                continue;
            }
            items.scheduleLoad(item);
        } catch (Throwable t) {
        // It may be the case that entities cannot be reloaded between
        // two versions - ignore these errors.
        }
    }
    _itemBuffer.clear();
    NBTTagList nbttaglist2 = nbt.getTagList("buffercontents", 10);
    for (int i = 0; i < nbttaglist2.tagCount(); i++) {
        NBTTagCompound nbttagcompound1 = nbttaglist2.getCompoundTagAt(i);
        _itemBuffer.add(new Triplet<>(ItemIdentifierStack.getFromStack(ItemStackLoader.loadAndFixItemStackFromNBT(nbttagcompound1)), new Pair<>(_bufferTimeOut, 0), null));
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer) Pair(logisticspipes.utils.tuples.Pair)

Example 33 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class ReflectionHelper method getField.

private static Field getField(Class<?> clazz, String name, String srgName) throws NoSuchFieldException {
    Pair<Class<?>, String> key = new Pair<>(clazz, name);
    Field field = ReflectionHelper.fieldCache.get(key);
    if (field == null) {
        try {
            field = clazz.getDeclaredField(name);
        } catch (NoSuchFieldException e1) {
            try {
                field = clazz.getField(name);
            } catch (NoSuchFieldException e2) {
                try {
                    field = clazz.getDeclaredField(srgName);
                } catch (NoSuchFieldException e3) {
                    try {
                        field = clazz.getField(srgName);
                    } catch (NoSuchFieldException e4) {
                        field = clazz.getDeclaredField(name);
                    }
                }
            }
        }
        field.setAccessible(true);
        ReflectionHelper.fieldCache.put(key, field);
    }
    return field;
}
Also used : Field(java.lang.reflect.Field) Pair(logisticspipes.utils.tuples.Pair)

Example 34 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class LogisticsPowerProviderTileEntity method update.

@Override
public void update() {
    super.update();
    pauseRequesting = false;
    if (!init) {
        if (MainProxy.isClient(getWorld())) {
            LogisticsHUDRenderer.instance().add(this);
        }
        init = true;
    }
    double globalRequest = orders.values().stream().reduce(Double::sum).orElse(0.0);
    if (globalRequest > 0) {
        final double fullfillRatio = Math.min(1, Math.min(internalStorage, getMaxProvidePerTick()) / globalRequest);
        if (fullfillRatio > 0) {
            final Function<NeighborTileEntity<LogisticsTileGenericPipe>, CoreRoutedPipe> getPipe = (NeighborTileEntity<LogisticsTileGenericPipe> neighbor) -> (CoreRoutedPipe) neighbor.getTileEntity().pipe;
            orders.entrySet().stream().map(routerIdToOrderCount -> new Pair<>(SimpleServiceLocator.routerManager.getRouter(routerIdToOrderCount.getKey()), Math.min(internalStorage, routerIdToOrderCount.getValue() * fullfillRatio))).filter(destinationToPower -> destinationToPower.getValue1() != null && destinationToPower.getValue1().getPipe() != null).forEach(destinationToPower -> new WorldCoordinatesWrapper(this).allNeighborTileEntities().stream().flatMap(neighbor -> LPNeighborTileEntityKt.optionalIs(neighbor, LogisticsTileGenericPipe.class).map(Stream::of).orElseGet(Stream::empty)).filter(neighbor -> neighbor.getTileEntity().pipe instanceof CoreRoutedPipe && !getPipe.apply(neighbor).stillNeedReplace()).flatMap(neighbor -> getPipe.apply(neighbor).getRouter().getDistanceTo(destinationToPower.getValue1()).stream().map(exitRoute -> new Pair<>(neighbor, exitRoute))).filter(neighborToExit -> neighborToExit.getValue2().containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom) && neighborToExit.getValue2().filters.stream().noneMatch(IFilter::blockPower)).findFirst().ifPresent(neighborToSource -> {
                CoreRoutedPipe sourcePipe = getPipe.apply(neighborToSource.getValue1());
                if (sourcePipe.isInitialized()) {
                    sourcePipe.container.addLaser(neighborToSource.getValue1().getOurDirection(), 1, getLaserColor(), true, true);
                }
                sendPowerLaserPackets(sourcePipe.getRouter(), destinationToPower.getValue1(), neighborToSource.getValue2().exitOrientation, neighborToSource.getValue2().exitOrientation != neighborToSource.getValue1().getDirection());
                internalStorage -= destinationToPower.getValue2();
                // because calculations with floats
                if (internalStorage <= 0)
                    internalStorage = 0;
                handlePower(destinationToPower.getValue1().getPipe(), destinationToPower.getValue2());
            }));
        }
    }
    orders.clear();
    if (MainProxy.isServer(world)) {
        if (internalStorage != lastUpdateStorage) {
            updateClients();
            lastUpdateStorage = internalStorage;
        }
    }
}
Also used : PowerProviderGui(logisticspipes.network.guis.block.PowerProviderGui) IRouter(logisticspipes.routing.IRouter) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) LogisticsPipes(logisticspipes.LogisticsPipes) LogisticsSolidTileEntity(logisticspipes.blocks.LogisticsSolidTileEntity) HashMap(java.util.HashMap) CCType(logisticspipes.proxy.computers.interfaces.CCType) MainProxy(logisticspipes.proxy.MainProxy) Function(java.util.function.Function) IHeadUpDisplayRenderer(logisticspipes.interfaces.IHeadUpDisplayRenderer) HUDStartBlockWatchingPacket(logisticspipes.network.packets.hud.HUDStartBlockWatchingPacket) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) NBTTagFloat(net.minecraft.nbt.NBTTagFloat) IHeadUpDisplayBlockRendererProvider(logisticspipes.interfaces.IHeadUpDisplayBlockRendererProvider) ISubSystemPowerProvider(logisticspipes.interfaces.ISubSystemPowerProvider) CrashReportCategory(net.minecraft.crash.CrashReportCategory) LogisticsHUDRenderer(logisticspipes.renderer.LogisticsHUDRenderer) Map(java.util.Map) IBlockWatchingHandler(logisticspipes.interfaces.IBlockWatchingHandler) LPNeighborTileEntityKt(network.rs485.logisticspipes.connection.LPNeighborTileEntityKt) LinkedList(java.util.LinkedList) CoordinatesGuiProvider(logisticspipes.network.abstractguis.CoordinatesGuiProvider) CCCommand(logisticspipes.proxy.computers.interfaces.CCCommand) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NewGuiHandler(logisticspipes.network.NewGuiHandler) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) HUDStopBlockWatchingPacket(logisticspipes.network.packets.hud.HUDStopBlockWatchingPacket) IGuiOpenControler(logisticspipes.interfaces.IGuiOpenControler) EnumFacing(net.minecraft.util.EnumFacing) Triplet(logisticspipes.utils.tuples.Triplet) PacketHandler(logisticspipes.network.PacketHandler) ExitRoute(logisticspipes.routing.ExitRoute) PowerProviderLevel(logisticspipes.network.packets.block.PowerProviderLevel) ServerRouter(logisticspipes.routing.ServerRouter) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) Stream(java.util.stream.Stream) IFilter(logisticspipes.interfaces.routing.IFilter) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) IGuiTileEntity(logisticspipes.interfaces.IGuiTileEntity) IPowerLevelDisplay(logisticspipes.interfaces.IPowerLevelDisplay) BitSet(java.util.BitSet) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) HUDPowerLevel(logisticspipes.gui.hud.HUDPowerLevel) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) Stream(java.util.stream.Stream) Pair(logisticspipes.utils.tuples.Pair)

Example 35 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class ModuleProvider method getAllItems.

@Override
public void getAllItems(Map<ItemIdentifier, Integer> items, List<IFilter> filters) {
    final IPipeServiceProvider service = _service;
    if (service == null)
        return;
    items.putAll(inventoriesWithMode().map(IInventoryUtil::getItemsAndCount).flatMap(inventory -> inventory.entrySet().stream()).filter(item -> {
        if (items.containsKey(item.getKey()))
            // already provided by any previous module. No comparison of the amount
            return false;
        // skip provider-filtered items
        if (filterBlocksItem(item.getKey()))
            return false;
        final boolean blockedInFilters = filters.stream().anyMatch(filter -> filter.isBlocked() == filter.isFilteredItem(item.getKey().getUndamaged()) || filter.blockProvider());
        // skip filters-parameter-filtered items
        return !blockedInFilters;
    }).map(item -> new Pair<>(item.getKey(), item.getValue() - service.getItemOrderManager().totalItemsCountInOrders(item.getKey()))).filter(itemIdentAndRemaining -> itemIdentAndRemaining.getValue2() > // reduce what has been reserved
    0).collect(// sum up the provided amount by the inventories
    Pair.toMap(Integer::sum)));
}
Also used : ModuleInHandGuiProvider(logisticspipes.network.abstractguis.ModuleInHandGuiProvider) IRouter(logisticspipes.routing.IRouter) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) SneakyModuleDirectionUpdate(logisticspipes.network.packets.modules.SneakyModuleDirectionUpdate) Particles(logisticspipes.pipefxhandlers.Particles) CCType(logisticspipes.proxy.computers.interfaces.CCType) MainProxy(logisticspipes.proxy.MainProxy) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) SinkReply(logisticspipes.utils.SinkReply) HUDStopModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStopModuleWatchingPacket) Map(java.util.Map) CCCommand(logisticspipes.proxy.computers.interfaces.CCCommand) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) NewGuiHandler(logisticspipes.network.NewGuiHandler) Collection(java.util.Collection) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) LogisticsManager(logisticspipes.logistics.LogisticsManager) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) IModuleInventoryReceive(logisticspipes.interfaces.IModuleInventoryReceive) PacketHandler(logisticspipes.network.PacketHandler) RequestTreeNode(logisticspipes.request.RequestTreeNode) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) SneakyDirection(network.rs485.logisticspipes.module.SneakyDirection) ProviderModuleInHand(logisticspipes.network.guis.module.inhand.ProviderModuleInHand) Objects(java.util.Objects) NullableEnumProperty(network.rs485.logisticspipes.property.NullableEnumProperty) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) Stream(java.util.stream.Stream) IFilter(logisticspipes.interfaces.routing.IFilter) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BooleanProperty(network.rs485.logisticspipes.property.BooleanProperty) Pair(logisticspipes.utils.tuples.Pair) IHUDModuleHandler(logisticspipes.interfaces.IHUDModuleHandler) Gui(network.rs485.logisticspipes.module.Gui) EnumProperty(network.rs485.logisticspipes.property.EnumProperty) Property(network.rs485.logisticspipes.property.Property) ProviderMode(network.rs485.logisticspipes.inventory.ProviderMode) ItemResource(logisticspipes.request.resources.ItemResource) IItemIdentifierInventory(network.rs485.logisticspipes.inventory.IItemIdentifierInventory) ModuleCoordinatesGuiProvider(logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider) LogisticsOrder(logisticspipes.routing.order.LogisticsOrder) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IClientInformationProvider(logisticspipes.interfaces.IClientInformationProvider) InventoryProperty(network.rs485.logisticspipes.property.InventoryProperty) ImmutableList(com.google.common.collect.ImmutableList) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) ProviderModuleGuiProvider(logisticspipes.network.guis.module.inpipe.ProviderModuleGuiProvider) IModuleWatchReciver(logisticspipes.interfaces.IModuleWatchReciver) Nonnull(javax.annotation.Nonnull) Iterator(java.util.Iterator) IHUDModuleRenderer(logisticspipes.interfaces.IHUDModuleRenderer) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) EnumFacing(net.minecraft.util.EnumFacing) LogisticsPromise(logisticspipes.routing.LogisticsPromise) ItemSendMode(logisticspipes.pipes.basic.CoreRoutedPipe.ItemSendMode) RequestTree(logisticspipes.request.RequestTree) HUDProviderModule(logisticspipes.gui.hud.modules.HUDProviderModule) HUDStartModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStartModuleWatchingPacket) IResource(logisticspipes.request.resources.IResource) ModuleInventory(logisticspipes.network.packets.module.ModuleInventory) TreeMap(java.util.TreeMap) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ILegacyActiveModule(logisticspipes.interfaces.ILegacyActiveModule) TileEntity(net.minecraft.tileentity.TileEntity) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) Pair(logisticspipes.utils.tuples.Pair)

Aggregations

Pair (logisticspipes.utils.tuples.Pair)42 List (java.util.List)21 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)19 IFilter (logisticspipes.interfaces.routing.IFilter)18 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)18 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)18 Map (java.util.Map)16 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)16 TileEntity (net.minecraft.tileentity.TileEntity)16 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)13 Collection (java.util.Collection)12 ExitRoute (logisticspipes.routing.ExitRoute)12 ItemStack (net.minecraft.item.ItemStack)12 Nonnull (javax.annotation.Nonnull)11 IAdditionalTargetInformation (logisticspipes.interfaces.routing.IAdditionalTargetInformation)11 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)11 MainProxy (logisticspipes.proxy.MainProxy)11 IRouter (logisticspipes.routing.IRouter)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)11