Search in sources :

Example 6 with CoreRoutedPipe

use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.

the class LogisticsFluidManager method getBestReply.

@Override
public Pair<Integer, Integer> getBestReply(FluidStack stack, IRouter sourceRouter, List<Integer> jamList) {
    for (ExitRoute candidateRouter : sourceRouter.getIRoutersByCost()) {
        if (!candidateRouter.containsFlag(PipeRoutingConnectionType.canRouteTo)) {
            continue;
        }
        if (candidateRouter.destination.getSimpleID() == sourceRouter.getSimpleID()) {
            continue;
        }
        if (jamList.contains(candidateRouter.destination.getSimpleID())) {
            continue;
        }
        if (candidateRouter.destination.getPipe() == null || !candidateRouter.destination.getPipe().isEnabled()) {
            continue;
        }
        CoreRoutedPipe pipe = candidateRouter.destination.getPipe();
        if (!(pipe instanceof IFluidSink)) {
            continue;
        }
        int amount = ((IFluidSink) pipe).sinkAmount(stack);
        if (amount > 0) {
            Pair<Integer, Integer> result = new Pair<>(candidateRouter.destination.getSimpleID(), amount);
            return result;
        }
    }
    Pair<Integer, Integer> result = new Pair<>(0, 0);
    return result;
}
Also used : IFluidSink(logisticspipes.interfaces.routing.IFluidSink) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ExitRoute(logisticspipes.routing.ExitRoute) Pair(logisticspipes.utils.tuples.Pair)

Example 7 with CoreRoutedPipe

use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.

the class LogisticsManager method getBestReply.

private Triplet<Integer, SinkReply, List<IFilter>> getBestReply(ItemIdentifier stack, IRouter sourceRouter, List<ExitRoute> validDestinations, boolean excludeSource, List<Integer> jamList, Triplet<Integer, SinkReply, List<IFilter>> result, boolean allowDefault) {
    if (result == null) {
        result = new Triplet<>(null, null, null);
    }
    outer: for (ExitRoute candidateRouter : validDestinations) {
        if (excludeSource) {
            if (candidateRouter.destination.getId().equals(sourceRouter.getId())) {
                continue;
            }
        }
        if (jamList.contains(candidateRouter.destination.getSimpleID())) {
            continue;
        }
        if (!candidateRouter.containsFlag(PipeRoutingConnectionType.canRouteTo)) {
            continue;
        }
        for (IFilter filter : candidateRouter.filters) {
            if (filter.blockRouting() || (filter.isBlocked() == filter.isFilteredItem(stack))) {
                continue outer;
            }
        }
        SinkReply reply = LogisticsManager.canSink(candidateRouter.destination, sourceRouter, excludeSource, stack, result.getValue2(), false, allowDefault);
        if (reply == null) {
            continue;
        }
        if (result.getValue1() == null) {
            result.setValue1(candidateRouter.destination.getSimpleID());
            result.setValue2(reply);
            List<IFilter> list = new LinkedList<>();
            result.setValue3(list);
            continue;
        }
        if (reply.fixedPriority.ordinal() > result.getValue2().fixedPriority.ordinal()) {
            result.setValue1(candidateRouter.destination.getSimpleID());
            result.setValue2(reply);
            List<IFilter> list = new LinkedList<>();
            result.setValue3(list);
            continue;
        }
        if (reply.fixedPriority == result.getValue2().fixedPriority && reply.customPriority > result.getValue2().customPriority) {
            result.setValue1(candidateRouter.destination.getSimpleID());
            result.setValue2(reply);
            List<IFilter> list = new LinkedList<>();
            result.setValue3(list);
            continue;
        }
    }
    if (result.getValue1() != null) {
        CoreRoutedPipe pipe = SimpleServiceLocator.routerManager.getRouterUnsafe(result.getValue1(), false).getPipe();
        pipe.useEnergy(result.getValue2().energyUse);
        pipe.spawnParticle(Particles.BlueParticle, 10);
    }
    return result;
}
Also used : IFilter(logisticspipes.interfaces.routing.IFilter) SinkReply(logisticspipes.utils.SinkReply) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ExitRoute(logisticspipes.routing.ExitRoute)

Example 8 with CoreRoutedPipe

use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.

the class PipeController method getContainer.

@Override
public DummyContainer getContainer(EntityPlayer player) {
    LogisticsTileGenericPipe tile = getPipe(player.getEntityWorld());
    if (tile == null || !(tile.pipe instanceof CoreRoutedPipe)) {
        return null;
    }
    final CoreRoutedPipe pipe = (CoreRoutedPipe) tile.pipe;
    DummyContainer dummy = new DummyContainer(player, null, pipe.getOriginalUpgradeManager().getGuiController(), new IGuiOpenControler() {

        //Network Statistics
        @Override
        public void guiOpenedByPlayer(EntityPlayer player) {
            pipe.playerStartWatching(player, 0);
        }

        @Override
        public void guiClosedByPlayer(EntityPlayer player) {
            pipe.playerStopWatching(player, 0);
        }
    });
    dummy.addNormalSlotsForPlayerInventory(0, 0);
    // TAB_1 SLOTS
    for (int pipeSlot = 0; pipeSlot < 9; pipeSlot++) {
        dummy.addUpgradeSlot(pipeSlot, pipe.getOriginalUpgradeManager(), pipeSlot, 8 + pipeSlot * 18, 18, itemStack -> {
            if (itemStack == null) {
                return false;
            }
            if (itemStack.getItem() == LogisticsPipes.UpgradeItem) {
                if (!LogisticsPipes.UpgradeItem.getUpgradeForItem(itemStack, null).isAllowedForPipe(pipe)) {
                    return false;
                }
            } else {
                return false;
            }
            return true;
        });
    }
    for (int pipeSlot = 0; pipeSlot < 9; pipeSlot++) {
        dummy.addSneakyUpgradeSlot(pipeSlot, pipe.getOriginalUpgradeManager(), pipeSlot + 9, 8 + pipeSlot * 18, 48, itemStack -> {
            if (itemStack == null) {
                return false;
            }
            if (itemStack.getItem() == LogisticsPipes.UpgradeItem) {
                IPipeUpgrade upgrade = LogisticsPipes.UpgradeItem.getUpgradeForItem(itemStack, null);
                if (!(upgrade instanceof SneakyUpgrade) && !(upgrade instanceof SneakyUpgradeConfig)) {
                    return false;
                }
                if (!upgrade.isAllowedForPipe(pipe)) {
                    return false;
                }
            } else {
                return false;
            }
            return true;
        });
    }
    // TAB_2 SLOTS
    dummy.addStaticRestrictedSlot(0, pipe.getOriginalUpgradeManager().getSecInv(), 8 + 8 * 18, 18, itemStack -> {
        if (itemStack == null) {
            return false;
        }
        if (itemStack.getItem() != LogisticsPipes.LogisticsItemCard) {
            return false;
        }
        if (itemStack.getItemDamage() != LogisticsItemCard.SEC_CARD) {
            return false;
        }
        return SimpleServiceLocator.securityStationManager.isAuthorized(UUID.fromString(itemStack.getTagCompound().getString("UUID")));
    }, 1);
    dummy.addRestrictedSlot(0, tile.logicController.diskInv, 14, 36, LogisticsPipes.LogisticsItemDisk);
    return dummy;
}
Also used : DummyContainer(logisticspipes.utils.gui.DummyContainer) IPipeUpgrade(logisticspipes.pipes.upgrades.IPipeUpgrade) IGuiOpenControler(logisticspipes.interfaces.IGuiOpenControler) SneakyUpgradeConfig(logisticspipes.pipes.upgrades.SneakyUpgradeConfig) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SneakyUpgrade(logisticspipes.pipes.upgrades.SneakyUpgrade)

Example 9 with CoreRoutedPipe

use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.

the class ItemAmountSignGui method getContainer.

@Override
public DummyContainer getContainer(EntityPlayer player) {
    LogisticsTileGenericPipe pipe = getPipe(player.getEntityWorld());
    if (pipe == null || !(pipe.pipe instanceof CoreRoutedPipe)) {
        return null;
    }
    ItemAmountPipeSign sign = ((ItemAmountPipeSign) ((CoreRoutedPipe) pipe.pipe).getPipeSign(dir));
    DummyContainer dummy = new DummyContainer(player.inventory, sign.itemTypeInv);
    dummy.addDummySlot(0, 0, 0);
    dummy.addNormalSlotsForPlayerInventory(0, 0);
    return dummy;
}
Also used : DummyContainer(logisticspipes.utils.gui.DummyContainer) ItemAmountPipeSign(logisticspipes.pipes.signs.ItemAmountPipeSign) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe)

Example 10 with CoreRoutedPipe

use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.

the class RequestAmountTaskSubGui method processPacket.

@Override
public void processPacket(EntityPlayer player) {
    LogisticsStatisticsTileEntity tile = this.getTile(player.getEntityWorld(), LogisticsStatisticsTileEntity.class);
    CoreRoutedPipe pipe = tile.getConnectedPipe();
    if (pipe == null) {
        return;
    }
    Map<ItemIdentifier, Integer> _availableItems = SimpleServiceLocator.logisticsManager.getAvailableItems(pipe.getRouter().getIRoutersByCost());
    LinkedList<ItemIdentifier> _craftableItems = SimpleServiceLocator.logisticsManager.getCraftableItems(pipe.getRouter().getIRoutersByCost());
    TreeSet<ItemIdentifierStack> _allItems = new TreeSet<>();
    for (Entry<ItemIdentifier, Integer> item : _availableItems.entrySet()) {
        ItemIdentifierStack newStack = item.getKey().makeStack(item.getValue());
        _allItems.add(newStack);
    }
    for (ItemIdentifier item : _craftableItems) {
        if (_availableItems.containsKey(item)) {
            continue;
        }
        _allItems.add(item.makeStack(0));
    }
    MainProxy.sendPacketToPlayer(PacketHandler.getPacket(AmountTaskSubGui.class).setIdentSet(_allItems), player);
}
Also used : LogisticsStatisticsTileEntity(logisticspipes.blocks.stats.LogisticsStatisticsTileEntity) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) TreeSet(java.util.TreeSet) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Aggregations

CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)68 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)43 TileEntity (net.minecraft.tileentity.TileEntity)22 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)16 ExitRoute (logisticspipes.routing.ExitRoute)15 ArrayList (java.util.ArrayList)14 LinkedList (java.util.LinkedList)13 IRouter (logisticspipes.routing.IRouter)11 Pair (logisticspipes.utils.tuples.Pair)10 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)10 List (java.util.List)9 HashMap (java.util.HashMap)8 IFilter (logisticspipes.interfaces.routing.IFilter)8 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)7 Map (java.util.Map)6 PipeRoutingConnectionType (logisticspipes.routing.PipeRoutingConnectionType)6 World (net.minecraft.world.World)6 BitSet (java.util.BitSet)5 Collections (java.util.Collections)5 EnumSet (java.util.EnumSet)5