use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ModuleApiaristTerminus method registerPosition.
@Override
public void registerPosition(ModulePositionType slot, int positionInt) {
super.registerPosition(slot, positionInt);
_sinkReply = new SinkReply(FixedPriority.Terminus, 0, true, false, 5, 0, new ChassiTargetInformation(getPositionInt()));
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ModuleTerminus method registerPosition.
@Override
public void registerPosition(ModulePositionType slot, int positionInt) {
super.registerPosition(slot, positionInt);
_sinkReply = new SinkReply(FixedPriority.Terminus, 0, true, false, 2, 0, new ChassiTargetInformation(getPositionInt()));
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ModuleThaumicAspectSink method registerPosition.
@Override
public void registerPosition(ModulePositionType slot, int positionInt) {
super.registerPosition(slot, positionInt);
_sinkReply = new SinkReply(FixedPriority.ItemSink, -2, true, false, 5, 0, new ChassiTargetInformation(getPositionInt()));
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class PipeItemsProviderLogistics method sendStack.
private int sendStack(ItemIdentifierStack stack, int maxCount, int destination, IAdditionalTargetInformation info) {
ItemIdentifier item = stack.getItem();
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(container);
//@formatter:off
Iterator<Pair<IInventoryUtil, ForgeDirection>> iterator = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).filter(adjacent -> !SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)).map(adjacent -> new Pair<>(getAdaptedInventoryUtil(adjacent), adjacent.direction)).iterator();
while (iterator.hasNext()) {
Pair<IInventoryUtil, ForgeDirection> next = iterator.next();
int available = next.getValue1().itemCount(item);
if (available == 0) {
continue;
}
int wanted = Math.min(available, stack.getStackSize());
wanted = Math.min(wanted, maxCount);
wanted = Math.min(wanted, item.getMaxStackSize());
IRouter dRtr = SimpleServiceLocator.routerManager.getRouterUnsafe(destination, false);
if (dRtr == null) {
_orderManager.sendFailed();
return 0;
}
SinkReply reply = LogisticsManager.canSink(dRtr, null, true, stack.getItem(), null, true, false);
boolean defersend = false;
if (reply != null) {
// some pipes are not aware of the space in the adjacent inventory, so they return null
if (reply.maxNumberOfItems < wanted) {
wanted = reply.maxNumberOfItems;
if (wanted <= 0) {
_orderManager.deferSend();
return 0;
}
defersend = true;
}
}
if (!canUseEnergy(wanted * neededEnergy())) {
return -1;
}
ItemStack removed = next.getValue1().getMultipleItems(item, wanted);
if (removed == null || removed.stackSize == 0) {
continue;
}
int sent = removed.stackSize;
useEnergy(sent * neededEnergy());
IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(removed);
routedItem.setDestination(destination);
routedItem.setTransportMode(TransportMode.Active);
routedItem.setAdditionalTargetInformation(info);
super.queueRoutedItem(routedItem, next.getValue2());
_orderManager.sendSuccessfull(sent, defersend, routedItem);
return sent;
}
_orderManager.sendFailed();
return 0;
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class LogisticsManager method assignDestinationFor.
/**
* Will assign a destination for a IRoutedItem based on a best sink reply
* recieved from other pipes.
*
* @param item
* The item that needs to be routed.
* @param sourceRouterID
* The SimpleID of the pipe that is sending the item. (the
* routedItem will cache the UUID, and that the SimpleID belongs
* to the UUID will be checked when appropriate)
* @param excludeSource
* Boolean, true means that it wont set the source as the
* destination.
* @return IRoutedItem with a newly assigned destination
*/
@Override
public IRoutedItem assignDestinationFor(IRoutedItem item, int sourceRouterID, boolean excludeSource) {
//Assert: only called server side.
//If we for some reason can't get the router we can't do anything either
IRouter sourceRouter = SimpleServiceLocator.routerManager.getRouterUnsafe(sourceRouterID, false);
if (sourceRouter == null) {
return item;
}
//Wipe current destination
item.clearDestination();
BitSet routersIndex = ServerRouter.getRoutersInterestedIn(item.getItemIdentifierStack().getItem());
// 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);
if (item.getItemIdentifierStack() != null && item.getItemIdentifierStack().makeNormalStack().getItem() instanceof LogisticsFluidContainer) {
Pair<Integer, Integer> bestReply = SimpleServiceLocator.logisticsFluidManager.getBestReply(SimpleServiceLocator.logisticsFluidManager.getFluidFromContainer(item.getItemIdentifierStack()), sourceRouter, item.getJamList());
if (bestReply.getValue1() != null && bestReply.getValue1() != 0) {
item.setDestination(bestReply.getValue1());
}
return item;
} else {
Triplet<Integer, SinkReply, List<IFilter>> bestReply = getBestReply(item.getItemIdentifierStack().getItem(), sourceRouter, validDestinations, excludeSource, item.getJamList(), null, true);
if (bestReply.getValue1() != null && bestReply.getValue1() != 0) {
item.setDestination(bestReply.getValue1());
if (bestReply.getValue2().isPassive) {
if (bestReply.getValue2().isDefault) {
item.setTransportMode(TransportMode.Default);
} else {
item.setTransportMode(TransportMode.Passive);
}
} else {
item.setTransportMode(TransportMode.Active);
}
item.setAdditionalTargetInformation(bestReply.getValue2().addInfo);
}
return item;
}
}
Aggregations