use of logisticspipes.logisticspipes.IRoutedItem in project LogisticsPipes by RS485.
the class CoreRoutedPipe method sendStack.
/* ISendRoutedItem */
@Override
public IRoutedItem sendStack(@Nonnull ItemStack stack, Pair<Integer, SinkReply> reply, ItemSendMode mode, EnumFacing direction) {
IRoutedItem itemToSend = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stack);
itemToSend.setDestination(reply.getValue1());
if (reply.getValue2().isPassive) {
if (reply.getValue2().isDefault) {
itemToSend.setTransportMode(TransportMode.Default);
} else {
itemToSend.setTransportMode(TransportMode.Passive);
}
}
itemToSend.setAdditionalTargetInformation(reply.getValue2().addInfo);
queueRoutedItem(itemToSend, direction, mode);
return itemToSend;
}
use of logisticspipes.logisticspipes.IRoutedItem in project LogisticsPipes by RS485.
the class FluidRoutedPipe method endReached.
public boolean endReached(LPTravelingItemServer arrivingItem, TileEntity tile) {
if (canInsertToTanks() && MainProxy.isServer(getWorld())) {
getCacheHolder().trigger(CacheTypes.Inventory);
if (arrivingItem.getItemIdentifierStack() == null || !(arrivingItem.getItemIdentifierStack().getItem().isFluidContainer())) {
return false;
}
if (getRouter().getSimpleID() != arrivingItem.getDestination()) {
return false;
}
int filled;
FluidIdentifierStack liquid = SimpleServiceLocator.logisticsFluidManager.getFluidFromContainer(arrivingItem.getItemIdentifierStack());
if (isConnectableTank(tile, arrivingItem.output, false)) {
// Try to put liquid into all adjacent tanks.
for (Pair<NeighborTileEntity<TileEntity>, ITankUtil> util : PipeFluidUtil.INSTANCE.getAdjacentTanks(this, false)) {
filled = util.getValue2().fill(liquid, true);
liquid.lowerAmount(filled);
if (liquid.getAmount() != 0) {
continue;
}
return true;
}
// Try inserting the liquid into the pipe side tank
filled = ((PipeFluidTransportLogistics) transport).sideTanks[arrivingItem.output.ordinal()].fill(liquid.makeFluidStack(), true);
if (filled == liquid.getAmount()) {
return true;
}
liquid.lowerAmount(filled);
}
// Try inserting the liquid into the pipe internal tank
filled = ((PipeFluidTransportLogistics) transport).internalTank.fill(liquid.makeFluidStack(), true);
if (filled == liquid.getAmount()) {
return true;
}
// If liquids still exist,
liquid.lowerAmount(filled);
// TODO: FIX THIS
if (this instanceof IRequireReliableFluidTransport) {
((IRequireReliableFluidTransport) this).liquidNotInserted(liquid.getFluid(), liquid.getAmount());
}
IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(SimpleServiceLocator.logisticsFluidManager.getFluidContainer(liquid));
Pair<Integer, FluidSinkReply> replies = SimpleServiceLocator.logisticsFluidManager.getBestReply(liquid, getRouter(), routedItem.getJamList());
if (replies == null) {
// clear destination without marking item as lost
routedItem.setDestination(0);
} else {
int dest = replies.getValue1();
routedItem.setDestination(dest);
}
routedItem.setTransportMode(TransportMode.Passive);
this.queueRoutedItem(routedItem, arrivingItem.output.getOpposite());
return true;
}
return false;
}
use of logisticspipes.logisticspipes.IRoutedItem in project LogisticsPipes by RS485.
the class PipeFluidProvider method enabledUpdateEntity.
@Override
public void enabledUpdateEntity() {
super.enabledUpdateEntity();
if (!getFluidOrderManager().hasOrders(ResourceType.PROVIDER) || !isNthTick(6)) {
return;
}
LogisticsFluidOrder order = getFluidOrderManager().peekAtTopRequest(ResourceType.PROVIDER);
AtomicInteger amountToSend = new AtomicInteger();
AtomicInteger attemptedAmount = new AtomicInteger();
amountToSend.set(Math.min(order.getAmount(), 5000));
attemptedAmount.set(Math.min(order.getAmount(), 5000));
for (Pair<NeighborTileEntity<TileEntity>, ITankUtil> pair : PipeFluidUtil.INSTANCE.getAdjacentTanks(this, false)) {
if (amountToSend.get() <= 0) {
break;
}
boolean fallback = true;
if (pair.getValue2() instanceof ISpecialTankUtil) {
ISpecialTankUtil util = (ISpecialTankUtil) pair.getValue2();
fallback = false;
ISpecialTankAccessHandler handler = util.getSpecialHandler();
FluidStack drained = handler.drainFrom(pair.getValue1().getTileEntity(), order.getFluid(), amountToSend.get(), false);
if (drained != null && drained.amount > 0 && order.getFluid().equals(FluidIdentifier.get(drained))) {
drained = handler.drainFrom(pair.getValue1().getTileEntity(), order.getFluid(), amountToSend.get(), true);
int amount = drained.amount;
amountToSend.addAndGet(-amount);
ItemIdentifierStack stack = SimpleServiceLocator.logisticsFluidManager.getFluidContainer(FluidIdentifierStack.getFromStack(drained));
IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stack);
item.setDestination(order.getRouter().getSimpleID());
item.setTransportMode(TransportMode.Active);
this.queueRoutedItem(item, pair.getValue1().getDirection());
getFluidOrderManager().sendSuccessfull(amount, false, item);
if (amountToSend.get() <= 0) {
break;
}
}
}
if (fallback) {
if (pair.getValue2().containsTanks()) {
pair.getValue2().tanks().map(tank -> FluidIdentifierStack.getFromStack(tank.getContents())).forEach(fluidStack -> {
if (amountToSend.get() <= 0) {
return;
}
if (fluidStack != null && fluidStack.getFluid() != null) {
if (order.getFluid().equals(fluidStack.getFluid())) {
int amount = Math.min(fluidStack.getAmount(), amountToSend.get());
FluidIdentifierStack drained = pair.getValue2().drain(amount, false);
if (drained != null && drained.getAmount() > 0 && order.getFluid().equals(drained.getFluid())) {
drained = pair.getValue2().drain(amount, true);
while (drained.getAmount() < amountToSend.get()) {
FluidIdentifierStack addition = pair.getValue2().drain(amountToSend.get() - drained.getAmount(), false);
if (addition != null && addition.getAmount() > 0 && order.getFluid().equals(addition.getFluid())) {
addition = pair.getValue2().drain(amountToSend.get() - drained.getAmount(), true);
drained.raiseAmount(addition.getAmount());
} else {
break;
}
}
amount = drained.getAmount();
amountToSend.addAndGet(-amount);
ItemIdentifierStack stack = SimpleServiceLocator.logisticsFluidManager.getFluidContainer(drained);
IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stack);
item.setDestination(order.getRouter().getSimpleID());
item.setTransportMode(TransportMode.Active);
queueRoutedItem(item, pair.getValue1().getDirection());
getFluidOrderManager().sendSuccessfull(amount, false, item);
}
}
}
});
}
}
}
if (amountToSend.get() >= attemptedAmount.get()) {
getFluidOrderManager().sendFailed();
}
}
use of logisticspipes.logisticspipes.IRoutedItem in project LogisticsPipes by RS485.
the class PipeItemsInvSysConnector method sendStack.
public void sendStack(ItemRoutingInformation info, ForgeDirection dir) {
IRoutedItem itemToSend = SimpleServiceLocator.routedItemHelper.createNewTravelItem(info);
super.queueRoutedItem(itemToSend, dir);
spawnParticle(Particles.OrangeParticle, 4);
}
use of logisticspipes.logisticspipes.IRoutedItem in project LogisticsPipes by RS485.
the class CoreRoutedPipe method sendStack.
@Override
public IRoutedItem sendStack(ItemStack stack, int destination, ItemSendMode mode, IAdditionalTargetInformation info) {
IRoutedItem itemToSend = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stack);
itemToSend.setDestination(destination);
itemToSend.setTransportMode(TransportMode.Active);
itemToSend.setAdditionalTargetInformation(info);
queueRoutedItem(itemToSend, getPointedOrientation(), mode);
return itemToSend;
}
Aggregations