use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class LogisticsManager method canSink.
public static SinkReply canSink(IRouter destination, IRouter sourceRouter, boolean excludeSource, ItemIdentifier stack, SinkReply result, boolean activeRequest, boolean allowDefault) {
SinkReply reply = null;
LogisticsModule module = destination.getLogisticsModule();
CoreRoutedPipe crp = destination.getPipe();
if (module == null) {
return null;
}
if (!(module.recievePassive() || activeRequest)) {
return null;
}
if (crp == null || !crp.isEnabled()) {
return null;
}
if (excludeSource && sourceRouter != null) {
if (destination.getPipe().sharesInterestWith(sourceRouter.getPipe())) {
return null;
}
}
if (result == null) {
reply = module.sinksItem(stack, -1, 0, allowDefault, true);
} else {
reply = module.sinksItem(stack, result.fixedPriority.ordinal(), result.customPriority, allowDefault, true);
}
if (result != null && result.maxNumberOfItems < 0) {
return null;
}
return reply;
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ModuleCrafter method registerPosition.
@Override
public void registerPosition(ModulePositionType slot, int positionInt) {
super.registerPosition(slot, positionInt);
_sinkReply = new SinkReply(FixedPriority.ItemSink, 0, true, false, 1, 0, new ChassiTargetInformation(getPositionInt()));
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ModulePassiveSupplier method sinksItem.
@Override
public SinkReply sinksItem(ItemIdentifier item, int bestPriority, int bestCustomPriority, boolean allowDefault, boolean includeInTransit) {
if (bestPriority > _sinkReply.fixedPriority.ordinal() || (bestPriority == _sinkReply.fixedPriority.ordinal() && bestCustomPriority >= _sinkReply.customPriority)) {
return null;
}
IInventoryUtil targetUtil = _service.getSneakyInventory(false, slot, positionInt);
if (targetUtil == null) {
return null;
}
if (!_filterInventory.containsItem(item)) {
return null;
}
int targetCount = _filterInventory.itemCount(item);
int haveCount = targetUtil.itemCount(item);
if (targetCount <= haveCount) {
return null;
}
if (_service.canUseEnergy(2)) {
return new SinkReply(_sinkReply, targetCount - haveCount);
}
return null;
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ModulePolymorphicItemSink method registerPosition.
@Override
public void registerPosition(ModulePositionType slot, int positionInt) {
super.registerPosition(slot, positionInt);
_sinkReply = new SinkReply(FixedPriority.ItemSink, 0, true, false, 3, 0, new ChassiTargetInformation(getPositionInt()));
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ModuleProvider method sendStack.
// returns -1 on permanently failed, don't try another stack this tick
// returns 0 on "unable to do this delivery"
private int sendStack(ItemIdentifierStack stack, int maxCount, int destination, IAdditionalTargetInformation info) {
ItemIdentifier item = stack.getItem();
IInventoryUtil inv = _service.getPointedInventory(_extractionMode, true);
if (inv == null) {
_service.getItemOrderManager().sendFailed();
return 0;
}
int available = inv.itemCount(item);
if (available == 0) {
_service.getItemOrderManager().sendFailed();
return 0;
}
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) {
_service.getItemOrderManager().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) {
_service.getItemOrderManager().deferSend();
return 0;
}
defersend = true;
}
}
if (!_service.canUseEnergy(wanted * neededEnergy())) {
return -1;
}
ItemStack removed = inv.getMultipleItems(item, wanted);
if (removed == null || removed.stackSize == 0) {
_service.getItemOrderManager().sendFailed();
return 0;
}
int sent = removed.stackSize;
_service.useEnergy(sent * neededEnergy());
IRoutedItem sendedItem = _service.sendStack(removed, destination, itemSendMode(), info);
_service.getItemOrderManager().sendSuccessfull(sent, defersend, sendedItem);
return sent;
}
Aggregations