use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ModuleCrafter method tick.
@Override
public void tick() {
enabledUpdateEntity();
if (_lostItems.isEmpty()) {
return;
}
// if(true) return;
DelayedGeneric<Pair<ItemIdentifierStack, IAdditionalTargetInformation>> lostItem = _lostItems.poll();
int rerequested = 0;
while (lostItem != null && rerequested < 100) {
Pair<ItemIdentifierStack, IAdditionalTargetInformation> pair = lostItem.get();
if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING)) {
SinkReply reply = LogisticsManager.canSink(getRouter(), null, true, pair.getValue1().getItem(), null, true, true);
if (reply == null || reply.maxNumberOfItems < 1) {
_lostItems.add(new DelayedGeneric<>(pair, 9000 + (int) (Math.random() * 2000)));
lostItem = _lostItems.poll();
continue;
}
}
int received = RequestTree.requestPartial(pair.getValue1(), (CoreRoutedPipe) _service, pair.getValue2());
rerequested++;
if (received < pair.getValue1().getStackSize()) {
pair.getValue1().setStackSize(pair.getValue1().getStackSize() - received);
_lostItems.add(new DelayedGeneric<>(pair, 4500 + (int) (Math.random() * 1000)));
}
lostItem = _lostItems.poll();
}
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ModuleCrafter method cacheAreAllOrderesToBuffer.
public void cacheAreAllOrderesToBuffer() {
boolean result = true;
for (LogisticsItemOrder order : _service.getItemOrderManager()) {
if (order.getDestination() instanceof IItemSpaceControl) {
SinkReply reply = LogisticsManager.canSink(order.getDestination().getRouter(), null, true, order.getResource().getItem(), null, true, false);
if (reply != null && reply.bufferMode == BufferMode.NONE && reply.maxNumberOfItems >= 1) {
result = false;
break;
}
} else {
// No Space control
result = false;
break;
}
}
cachedAreAllOrderesToBuffer = result;
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ChassiTransportLayer method stillWantItem.
@Override
public boolean stillWantItem(IRoutedItem item) {
LogisticsModule module = _chassiPipe.getLogisticsModule();
if (module == null) {
_chassiPipe.notifyOfItemArival(item.getInfo());
return false;
}
if (!_chassiPipe.isEnabled()) {
_chassiPipe.notifyOfItemArival(item.getInfo());
return false;
}
SinkReply reply = module.sinksItem(item.getItemIdentifierStack().getItem(), -1, 0, true, false);
if (reply == null || reply.maxNumberOfItems < 0) {
_chassiPipe.notifyOfItemArival(item.getInfo());
return false;
}
if (reply.maxNumberOfItems > 0 && item.getItemIdentifierStack().getStackSize() > reply.maxNumberOfItems) {
ForgeDirection o = _chassiPipe.getPointedOrientation();
if (o == null || o == ForgeDirection.UNKNOWN) {
o = ForgeDirection.UP;
}
item.split(reply.maxNumberOfItems, o);
}
return true;
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ChassiModule method sinksItem.
@Override
public SinkReply sinksItem(ItemIdentifier item, int bestPriority, int bestCustomPriority, boolean allowDefault, boolean includeInTransit) {
SinkReply bestresult = null;
for (LogisticsModule module : modules) {
if (module != null) {
SinkReply result = module.sinksItem(item, bestPriority, bestCustomPriority, allowDefault, includeInTransit);
if (result != null && result.maxNumberOfItems >= 0) {
bestresult = result;
bestPriority = result.fixedPriority.ordinal();
bestCustomPriority = result.customPriority;
}
}
}
if (bestresult == null) {
return null;
}
//Always deny items when we can't put the item anywhere
IInventoryUtil invUtil = parentChassis.getSneakyInventory(false, ModulePositionType.SLOT, ((ChassiTargetInformation) bestresult.addInfo).getModuleSlot());
if (invUtil == null) {
return null;
}
int roomForItem = invUtil.roomForItem(item);
if (roomForItem < 1) {
return null;
}
if (includeInTransit) {
int onRoute = parentChassis.countOnRoute(item);
roomForItem = invUtil.roomForItem(item, onRoute + item.getMaxStackSize());
roomForItem -= onRoute;
if (roomForItem < 1) {
return null;
}
}
if (bestresult.maxNumberOfItems == 0) {
return new SinkReply(bestresult, roomForItem);
}
return new SinkReply(bestresult, Math.min(bestresult.maxNumberOfItems, roomForItem));
}
use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.
the class ModuleAdvancedExtractor method checkExtract.
private void checkExtract(IInventoryUtil invUtil) {
Map<ItemIdentifier, Integer> items = invUtil.getItemsAndCount();
for (Entry<ItemIdentifier, Integer> item : items.entrySet()) {
if (!CanExtract(item.getKey().makeNormalStack(item.getValue()))) {
continue;
}
List<Integer> jamList = new LinkedList<>();
Pair<Integer, SinkReply> reply = _service.hasDestination(item.getKey(), true, jamList);
if (reply == null) {
continue;
}
int itemsleft = itemsToExtract();
while (reply != null) {
int count = Math.min(itemsleft, item.getValue());
count = Math.min(count, item.getKey().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 = invUtil.getMultipleItems(item.getKey(), count);
if (stackToSend == null || stackToSend.stackSize == 0) {
break;
}
count = stackToSend.stackSize;
_service.sendStack(stackToSend, reply, itemSendMode());
itemsleft -= count;
if (itemsleft <= 0) {
break;
}
jamList.add(reply.getValue1());
reply = _service.hasDestination(item.getKey(), true, jamList);
}
return;
}
}
Aggregations