use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ModuleElectricManager method registerPosition.
@Override
public void registerPosition(ModulePositionType slot, int positionInt) {
super.registerPosition(slot, positionInt);
_sinkReply = new SinkReply(FixedPriority.ElectricManager, 0, true, false, 1, 1, new ChassiTargetInformation(getPositionInt()));
}
use of logisticspipes.utils.SinkReply 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;
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class LogisticsManager method hasDestination.
/**
* Method used to check if a given stack has a destination.
*
* @return Triplet of destinationSimpleID, sinkreply, relays; null if
* nothing found
* @param stack
* The stack to check if it has destination.
* @param allowDefault
* Boolean, if true then a default route will be considered a
* valid destination.
* @param sourceRouter
* The UUID of the router pipe that wants to send the stack.
* @param excludeSource
* Boolean, true means it will not consider the pipe itself as a
* valid destination.
*/
@Override
public Triplet<Integer, SinkReply, List<IFilter>> hasDestination(ItemIdentifier stack, boolean allowDefault, int sourceID, List<Integer> routerIDsToExclude) {
IRouter sourceRouter = SimpleServiceLocator.routerManager.getRouter(sourceID);
if (sourceRouter == null) {
return null;
}
BitSet routersIndex = ServerRouter.getRoutersInterestedIn(stack);
// get the routing table
List<ExitRoute> validDestinations = new ArrayList<>();
for (int i = routersIndex.nextSetBit(0); i >= 0; i = routersIndex.nextSetBit(i + 1)) {
IRouter r = SimpleServiceLocator.routerManager.getRouterUnsafe(i, false);
List<ExitRoute> exits = sourceRouter.getDistanceTo(r);
if (exits != null) {
validDestinations.addAll(exits.stream().filter(e -> e.containsFlag(PipeRoutingConnectionType.canRouteTo)).collect(Collectors.toList()));
}
}
Collections.sort(validDestinations);
Triplet<Integer, SinkReply, List<IFilter>> search = getBestReply(stack, sourceRouter, validDestinations, true, routerIDsToExclude, null, allowDefault);
if (search.getValue2() == null) {
return null;
}
if (!allowDefault && search.getValue2().isDefault) {
return null;
}
return search;
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ModuleExtractor method tick.
@Override
public void tick() {
if (++currentTick < ticksToAction()) {
return;
}
currentTick = 0;
//Extract Item
IInventory realInventory = _service.getRealInventory();
if (realInventory == null) {
return;
}
ForgeDirection extractOrientation = _sneakyDirection;
if (extractOrientation == ForgeDirection.UNKNOWN) {
extractOrientation = _service.inventoryOrientation().getOpposite();
}
IInventoryUtil targetUtil = _service.getSneakyInventory(extractOrientation, true);
for (int i = 0; i < targetUtil.getSizeInventory(); i++) {
ItemStack slot = targetUtil.getStackInSlot(i);
if (slot == null) {
continue;
}
ItemIdentifier slotitem = ItemIdentifier.get(slot);
List<Integer> jamList = new LinkedList<>();
Pair<Integer, SinkReply> reply = _service.hasDestination(slotitem, true, jamList);
if (reply == null) {
continue;
}
int itemsleft = itemsToExtract();
while (reply != null) {
int count = Math.min(itemsleft, slot.stackSize);
count = Math.min(count, slotitem.getMaxStackSize());
if (reply.getValue2().maxNumberOfItems > 0) {
count = Math.min(count, reply.getValue2().maxNumberOfItems);
}
while (!_service.useEnergy(neededEnergy() * count) && count > 0) {
_service.spawnParticle(Particles.OrangeParticle, 2);
count--;
}
if (count <= 0) {
break;
}
ItemStack stackToSend = targetUtil.decrStackSize(i, count);
if (stackToSend == null || stackToSend.stackSize == 0) {
break;
}
count = stackToSend.stackSize;
_service.sendStack(stackToSend, reply, itemSendMode());
itemsleft -= count;
if (itemsleft <= 0) {
break;
}
slot = targetUtil.getStackInSlot(i);
if (slot == null) {
break;
}
jamList.add(reply.getValue1());
reply = _service.hasDestination(ItemIdentifier.get(slot), true, jamList);
}
break;
}
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ModuleFluidSupplier method registerPosition.
@Override
public void registerPosition(ModulePositionType slot, int positionInt) {
super.registerPosition(slot, positionInt);
_sinkReply = new SinkReply(FixedPriority.ItemSink, 0, true, false, 0, 0, new ChassiTargetInformation(getPositionInt()));
}
Aggregations