Search in sources :

Example 1 with Adjacent

use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.

the class LogisticsPowerProviderTileEntity method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    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) {
        double fullfillRatio = Math.min(1, Math.min(internalStorage, getMaxProvidePerTick()) / globalRequest);
        if (fullfillRatio > 0) {
            for (Entry<Integer, Double> order : orders.entrySet()) {
                double toSend = order.getValue() * fullfillRatio;
                if (toSend > internalStorage) {
                    toSend = internalStorage;
                }
                IRouter destinationRouter = SimpleServiceLocator.routerManager.getRouter(order.getKey());
                if (destinationRouter != null && destinationRouter.getPipe() != null) {
                    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(this);
                    outerTiles: for (AdjacentTileEntity adjacent : worldCoordinates.getAdjacentTileEntities().collect(Collectors.toList())) {
                        if (adjacent.tileEntity instanceof LogisticsTileGenericPipe) {
                            if (((LogisticsTileGenericPipe) adjacent.tileEntity).pipe instanceof CoreRoutedPipe) {
                                if (((CoreRoutedPipe) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).stillNeedReplace()) {
                                    continue;
                                }
                                IRouter sourceRouter = ((CoreRoutedPipe) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).getRouter();
                                if (sourceRouter != null) {
                                    outerRouters: for (ExitRoute exit : sourceRouter.getDistanceTo(destinationRouter)) {
                                        if (exit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                                            for (IFilter filter : exit.filters) {
                                                if (filter.blockPower()) {
                                                    continue outerRouters;
                                                }
                                            }
                                            CoreRoutedPipe pipe = sourceRouter.getPipe();
                                            if (pipe != null && pipe.isInitialized()) {
                                                pipe.container.addLaser(adjacent.direction.getOpposite(), 1, getLaserColor(), true, true);
                                            }
                                            sendPowerLaserPackets(sourceRouter, destinationRouter, exit.exitOrientation, exit.exitOrientation != adjacent.direction);
                                            internalStorage -= toSend;
                                            handlePower(destinationRouter.getPipe(), toSend);
                                            break outerTiles;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    orders.clear();
    if (MainProxy.isServer(worldObj)) {
        if (internalStorage != lastUpdateStorage) {
            updateClients();
            lastUpdateStorage = internalStorage;
        }
    }
}
Also used : IRouter(logisticspipes.routing.IRouter) IFilter(logisticspipes.interfaces.routing.IFilter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ExitRoute(logisticspipes.routing.ExitRoute) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity)

Example 2 with Adjacent

use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.

the class ModuleCrafter method spaceFor.

protected int spaceFor(ItemIdentifier item, boolean includeInTransit) {
    Pair<String, ItemIdentifier> key = new Pair<>("spaceFor", item);
    Object cache = _service.getCacheHolder().getCacheFor(CacheTypes.Inventory, key);
    if (cache != null) {
        int count = (Integer) cache;
        if (includeInTransit) {
            count -= _service.countOnRoute(item);
        }
        return count;
    }
    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(getWorld(), _service.getX(), _service.getY(), _service.getZ());
    //@formatter:off
    int count = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacent -> new Pair<>((IInventory) adjacent.tileEntity, adjacent.direction)).map(invDirPair -> {
        if (invDirPair.getValue1() instanceof ISidedInventory) {
            invDirPair.setValue1(new SidedInventoryMinecraftAdapter((ISidedInventory) invDirPair.getValue1(), invDirPair.getValue2().getOpposite(), false));
        }
        if (getUpgradeManager().hasSneakyUpgrade()) {
            invDirPair.setValue2(getUpgradeManager().getSneakyOrientation());
        }
        IInventoryUtil inv = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(invDirPair.getValue1(), invDirPair.getValue2());
        return inv.roomForItem(item, 9999);
    }).reduce(Integer::sum).orElse(0);
    _service.getCacheHolder().setCache(CacheTypes.Inventory, key, count);
    if (includeInTransit) {
        count -= _service.countOnRoute(item);
    }
    return count;
}
Also used : IInventory(net.minecraft.inventory.IInventory) FluidCraftingPipeAdvancedSatellitePrevPacket(logisticspipes.network.packets.pipe.FluidCraftingPipeAdvancedSatellitePrevPacket) CraftingPipeNextAdvancedSatellitePacket(logisticspipes.network.packets.block.CraftingPipeNextAdvancedSatellitePacket) CPipeSatelliteImportBack(logisticspipes.network.packets.cpipe.CPipeSatelliteImportBack) CraftingAdvancedSatelliteId(logisticspipes.network.packets.cpipe.CraftingAdvancedSatelliteId) Constants(net.minecraftforge.common.util.Constants) MainProxy(logisticspipes.proxy.MainProxy) FluidCraftingAmount(logisticspipes.network.packets.pipe.FluidCraftingAmount) SinkReply(logisticspipes.utils.SinkReply) Block(net.minecraft.block.Block) HUDStopModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStopModuleWatchingPacket) ItemCraftingTemplate(logisticspipes.request.ItemCraftingTemplate) Map(java.util.Map) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) CPipeSatelliteId(logisticspipes.network.packets.cpipe.CPipeSatelliteId) FluidCraftingAdvancedSatelliteId(logisticspipes.network.packets.pipe.FluidCraftingAdvancedSatelliteId) NewGuiHandler(logisticspipes.network.NewGuiHandler) SideOnly(cpw.mods.fml.relauncher.SideOnly) CPipeNextSatellite(logisticspipes.network.packets.cpipe.CPipeNextSatellite) FluidCraftingPipeAdvancedSatelliteNextPacket(logisticspipes.network.packets.pipe.FluidCraftingPipeAdvancedSatelliteNextPacket) LogisticsExtraPromise(logisticspipes.routing.LogisticsExtraPromise) LogisticsManager(logisticspipes.logistics.LogisticsManager) LogisticsGuiModule(logisticspipes.modules.abstractmodules.LogisticsGuiModule) Set(java.util.Set) PacketHandler(logisticspipes.network.PacketHandler) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ExitRoute(logisticspipes.routing.ExitRoute) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IFilter(logisticspipes.interfaces.routing.IFilter) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity) BufferMode(logisticspipes.utils.SinkReply.BufferMode) ICraftingRecipeProvider(logisticspipes.proxy.interfaces.ICraftingRecipeProvider) CraftingModuleInHand(logisticspipes.network.guis.module.inhand.CraftingModuleInHand) CraftingPipeOpenConnectedGuiPacket(logisticspipes.network.packets.cpipe.CraftingPipeOpenConnectedGuiPacket) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) CraftingModuleSlot(logisticspipes.network.guis.module.inpipe.CraftingModuleSlot) IWorldProvider(logisticspipes.interfaces.IWorldProvider) LogisticsDictPromise(logisticspipes.routing.LogisticsDictPromise) World(net.minecraft.world.World) CraftingPipePrevAdvancedSatellitePacket(logisticspipes.network.packets.block.CraftingPipePrevAdvancedSatellitePacket) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) CraftingPipePriorityDownPacket(logisticspipes.network.packets.pipe.CraftingPipePriorityDownPacket) LogisticsExtraDictPromise(logisticspipes.routing.LogisticsExtraDictPromise) DelayedGeneric(logisticspipes.utils.DelayedGeneric) ItemSendMode(logisticspipes.pipes.basic.CoreRoutedPipe.ItemSendMode) CPipeSatelliteImport(logisticspipes.network.packets.cpipe.CPipeSatelliteImport) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) IIcon(net.minecraft.util.IIcon) HUDStartModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStartModuleWatchingPacket) IResource(logisticspipes.request.resources.IResource) ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassi.ChassiTargetInformation) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) TileEntity(net.minecraft.tileentity.TileEntity) ItemBlock(net.minecraft.item.ItemBlock) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ModuleInHandGuiProvider(logisticspipes.network.abstractguis.ModuleInHandGuiProvider) PipeItemsSatelliteLogistics(logisticspipes.pipes.PipeItemsSatelliteLogistics) IRouter(logisticspipes.routing.IRouter) IRequestFluid(logisticspipes.interfaces.routing.IRequestFluid) ItemUpgrade(logisticspipes.items.ItemUpgrade) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) ICraftingTemplate(logisticspipes.request.ICraftingTemplate) Particles(logisticspipes.pipefxhandlers.Particles) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) DictCraftingTemplate(logisticspipes.request.DictCraftingTemplate) NBTTagList(net.minecraft.nbt.NBTTagList) FluidIdentifier(logisticspipes.utils.FluidIdentifier) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) ICraftItems(logisticspipes.interfaces.routing.ICraftItems) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) IIconRegister(net.minecraft.client.renderer.texture.IIconRegister) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) Side(cpw.mods.fml.relauncher.Side) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) FluidResource(logisticspipes.request.resources.FluidResource) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) IFuzzyRecipeProvider(logisticspipes.proxy.interfaces.IFuzzyRecipeProvider) RequestTreeNode(logisticspipes.request.RequestTreeNode) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) TransportMode(logisticspipes.logisticspipes.IRoutedItem.TransportMode) IItemSpaceControl(logisticspipes.interfaces.routing.IItemSpaceControl) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) CacheTypes(logisticspipes.utils.CacheHolder.CacheTypes) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) IHUDModuleHandler(logisticspipes.interfaces.IHUDModuleHandler) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) IPromise(logisticspipes.request.IPromise) PipeItemsCraftingLogistics(logisticspipes.pipes.PipeItemsCraftingLogistics) ItemResource(logisticspipes.request.resources.ItemResource) Getter(lombok.Getter) ModuleCoordinatesGuiProvider(logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider) CPipePrevSatellite(logisticspipes.network.packets.cpipe.CPipePrevSatellite) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) IReqCraftingTemplate(logisticspipes.request.IReqCraftingTemplate) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) CoordinatesPacket(logisticspipes.network.abstractpackets.CoordinatesPacket) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) CraftingPipePriorityUpPacket(logisticspipes.network.packets.pipe.CraftingPipePriorityUpPacket) IModuleWatchReciver(logisticspipes.interfaces.IModuleWatchReciver) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager) DelayQueue(java.util.concurrent.DelayQueue) WeakReference(java.lang.ref.WeakReference) PipeFluidSatellite(logisticspipes.pipes.PipeFluidSatellite) CraftingPriority(logisticspipes.network.packets.pipe.CraftingPriority) IHUDModuleRenderer(logisticspipes.interfaces.IHUDModuleRenderer) FixedPriority(logisticspipes.utils.SinkReply.FixedPriority) CraftingPipeUpdatePacket(logisticspipes.network.packets.pipe.CraftingPipeUpdatePacket) LogisticsPromise(logisticspipes.routing.LogisticsPromise) RequestTree(logisticspipes.request.RequestTree) ISidedInventory(net.minecraft.inventory.ISidedInventory) IInventory(net.minecraft.inventory.IInventory) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) Pair(logisticspipes.utils.tuples.Pair)

Example 3 with Adjacent

use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.

the class PipeTransportLayer method itemArrived.

@Override
public ForgeDirection itemArrived(IRoutedItem item, ForgeDirection denyed) {
    if (item.getItemIdentifierStack() != null) {
        _trackStatistics.recievedItem(item.getItemIdentifierStack().getStackSize());
    }
    List<AdjacentTileEntity> adjacentEntities = new WorldCoordinatesWrapper(routedPipe.container).getConnectedAdjacentTileEntities(IPipeInformationProvider.ConnectionPipeType.ITEM).collect(Collectors.toList());
    LinkedList<ForgeDirection> possibleForgeDirection = new LinkedList<>();
    for (AdjacentTileEntity adjacent : adjacentEntities) {
        if (SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)) {
            continue;
        }
        if (_router.isRoutedExit(adjacent.direction)) {
            continue;
        }
        if (denyed != null && denyed.equals(adjacent.direction)) {
            continue;
        }
        CoreRoutedPipe pipe = _router.getPipe();
        if (pipe != null) {
            if (pipe.isLockedExit(adjacent.direction)) {
                continue;
            }
        }
        possibleForgeDirection.add(adjacent.direction);
    }
    if (possibleForgeDirection.size() != 0) {
        return possibleForgeDirection.get(routedPipe.getWorld().rand.nextInt(possibleForgeDirection.size()));
    }
    // 2nd prio, deliver to non-routed exit
    for (AdjacentTileEntity adjacent : adjacentEntities) {
        if (_router.isRoutedExit(adjacent.direction)) {
            continue;
        }
        CoreRoutedPipe pipe = _router.getPipe();
        if (pipe != null) {
            if (pipe.isLockedExit(adjacent.direction)) {
                continue;
            }
        }
        possibleForgeDirection.add(adjacent.direction);
    }
    if (possibleForgeDirection.size() == 0) {
        return null;
    }
    return possibleForgeDirection.get(routedPipe.getWorld().rand.nextInt(possibleForgeDirection.size()));
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) LinkedList(java.util.LinkedList) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity)

Example 4 with Adjacent

use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.

the class ModuleSatellite method spaceFor.

private int spaceFor(ItemIdentifier item, boolean includeInTransit) {
    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(pipe.container);
    //@formatter:off
    int count = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacent -> {
        IInventory inv = (IInventory) adjacent.tileEntity;
        if (inv instanceof net.minecraft.inventory.ISidedInventory) {
            inv = new SidedInventoryMinecraftAdapter((net.minecraft.inventory.ISidedInventory) inv, adjacent.direction.getOpposite(), false);
        }
        IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv, adjacent.direction);
        return util.roomForItem(item, 9999);
    }).reduce(Integer::sum).orElse(0);
    if (includeInTransit) {
        count -= pipe.countOnRoute(item);
    }
    return count;
}
Also used : IIconRegister(net.minecraft.client.renderer.texture.IIconRegister) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Side(cpw.mods.fml.relauncher.Side) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) SideOnly(cpw.mods.fml.relauncher.SideOnly) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) Collection(java.util.Collection) FixedPriority(logisticspipes.utils.SinkReply.FixedPriority) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) IIcon(net.minecraft.util.IIcon) SinkReply(logisticspipes.utils.SinkReply) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) IWorldProvider(logisticspipes.interfaces.IWorldProvider) IInventory(net.minecraft.inventory.IInventory) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) IInventory(net.minecraft.inventory.IInventory) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper)

Example 5 with Adjacent

use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.

the class ModuleCrafterMK3 method tick.

@Override
public void tick() {
    super.tick();
    if (inv.isEmpty()) {
        return;
    }
    if (!_service.isNthTick(6)) {
        return;
    }
    //Add from internal buffer
    List<AdjacentTileEntity> crafters = locateCrafters();
    boolean change = false;
    for (AdjacentTileEntity adjacent : crafters) {
        for (int i = inv.getSizeInventory() - 1; i >= 0; i--) {
            ItemIdentifierStack slot = inv.getIDStackInSlot(i);
            if (slot == null) {
                continue;
            }
            ForgeDirection insertion = adjacent.direction.getOpposite();
            if (getUpgradeManager().hasSneakyUpgrade()) {
                insertion = getUpgradeManager().getSneakyOrientation();
            }
            ItemIdentifierStack toadd = slot.clone();
            toadd.setStackSize(Math.min(toadd.getStackSize(), toadd.getItem().getMaxStackSize()));
            if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING)) {
                toadd.setStackSize(Math.min(toadd.getStackSize(), ((IInventory) adjacent.tileEntity).getInventoryStackLimit()));
                ItemStack added = InventoryHelper.getTransactorFor(adjacent.tileEntity, adjacent.direction.getOpposite()).add(toadd.makeNormalStack(), insertion, true);
                slot.setStackSize(slot.getStackSize() - added.stackSize);
                if (added.stackSize != 0) {
                    change = true;
                }
            } else {
                _service.queueRoutedItem(SimpleServiceLocator.routedItemHelper.createNewTravelItem(toadd), adjacent.direction.getOpposite());
                slot.setStackSize(slot.getStackSize() - toadd.getStackSize());
                change = true;
            }
            if (slot.getStackSize() <= 0) {
                inv.clearInventorySlotContents(i);
            } else {
                inv.setInventorySlotContents(i, slot);
            }
        }
    }
    if (change) {
        inv.markDirty();
        _service.getCacheHolder().trigger(CacheTypes.Inventory);
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity)

Aggregations

WorldCoordinatesWrapper (network.rs485.logisticspipes.world.WorldCoordinatesWrapper)16 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)13 IFilter (logisticspipes.interfaces.routing.IFilter)12 TileEntity (net.minecraft.tileentity.TileEntity)12 Pair (logisticspipes.utils.tuples.Pair)11 List (java.util.List)10 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)10 MainProxy (logisticspipes.proxy.MainProxy)10 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)10 ItemStack (net.minecraft.item.ItemStack)10 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)10 Map (java.util.Map)9 PacketHandler (logisticspipes.network.PacketHandler)9 EntityPlayer (net.minecraft.entity.player.EntityPlayer)9 LinkedList (java.util.LinkedList)8 Collectors (java.util.stream.Collectors)8 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)8 PlayerCollectionList (logisticspipes.utils.PlayerCollectionList)8 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)8