use of logisticspipes.transport.PipeFluidTransportLogistics in project LogisticsPipes by RS485.
the class FluidRoutedPipe method enabledUpdateEntity.
@Override
public void enabledUpdateEntity() {
super.enabledUpdateEntity();
if (canInsertFromSideToTanks()) {
int validDirections = 0;
final List<Pair<NeighborTileEntity<TileEntity>, ITankUtil>> list = PipeFluidUtil.INSTANCE.getAdjacentTanks(this, true);
for (Pair<NeighborTileEntity<TileEntity>, ITankUtil> pair : list) {
if (pair.getValue2() instanceof LogisticsTileGenericPipe) {
if (((LogisticsTileGenericPipe) pair.getValue2()).pipe instanceof CoreRoutedPipe) {
continue;
}
}
FluidTank internalTank = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue1().getDirection().ordinal()];
validDirections++;
if (internalTank.getFluid() == null) {
continue;
}
int filled = pair.getValue2().fill(FluidIdentifierStack.getFromStack(internalTank.getFluid()), true);
if (filled == 0) {
continue;
}
FluidStack drain = internalTank.drain(filled, true);
if (drain == null || filled != drain.amount) {
if (LogisticsPipes.isDEBUG()) {
throw new UnsupportedOperationException("Fluid Multiplication");
}
}
}
if (validDirections == 0) {
return;
}
FluidTank tank = ((PipeFluidTransportLogistics) transport).internalTank;
FluidStack stack = tank.getFluid();
if (stack == null) {
return;
}
for (Pair<NeighborTileEntity<TileEntity>, ITankUtil> pair : list) {
if (pair.getValue1().isLogisticsPipe()) {
if (((LogisticsTileGenericPipe) pair.getValue1().getTileEntity()).pipe instanceof CoreRoutedPipe) {
continue;
}
}
FluidTank tankSide = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue1().getDirection().ordinal()];
stack = tank.getFluid();
if (stack == null) {
continue;
}
stack = stack.copy();
int filled = tankSide.fill(stack, true);
if (filled == 0) {
continue;
}
FluidStack drain = tank.drain(filled, true);
if (drain == null || filled != drain.amount) {
if (LogisticsPipes.isDEBUG()) {
throw new UnsupportedOperationException("Fluid Multiplication");
}
}
}
}
}
use of logisticspipes.transport.PipeFluidTransportLogistics in project LogisticsPipes by RS485.
the class PipeFluidExtractor method extractFrom.
private void extractFrom(ITankUtil container, EnumFacing side) {
int sideID = side.ordinal();
FluidStack contained = ((PipeFluidTransportLogistics) transport).getTankProperties(side)[0].getContents();
int amountMissing = ((PipeFluidTransportLogistics) transport).getSideCapacity() - (contained != null ? contained.amount : 0);
if (liquidToExtract[sideID] < Math.min(PipeFluidExtractor.flowRate, amountMissing)) {
if (this.useEnergy(PipeFluidExtractor.energyPerFlow)) {
liquidToExtract[sideID] += Math.min(PipeFluidExtractor.flowRate, amountMissing);
}
}
FluidIdentifierStack extracted = container.drain(Math.min(liquidToExtract[sideID], PipeFluidExtractor.flowRate), false);
int inserted = 0;
if (extracted != null) {
inserted = ((PipeFluidTransportLogistics) transport).fill(side, extracted.makeFluidStack(), true);
container.drain(inserted, true);
}
liquidToExtract[sideID] -= inserted;
}
use of logisticspipes.transport.PipeFluidTransportLogistics in project LogisticsPipes by RS485.
the class PipeFluidInsertion method enabledUpdateEntity.
@Override
public void enabledUpdateEntity() {
super.enabledUpdateEntity();
List<Integer> tempJamList = new ArrayList<>();
if (!localJamList.isEmpty()) {
List<Pair<Integer, Integer>> toRemove = new ArrayList<>();
for (Pair<Integer, Integer> part : localJamList) {
part.setValue2(part.getValue2() - 1);
if (part.getValue2() <= 0) {
toRemove.add(part);
} else {
tempJamList.add(part.getValue1());
}
}
if (!toRemove.isEmpty()) {
localJamList.removeAll(toRemove);
}
}
PipeFluidTransportLogistics transport = (PipeFluidTransportLogistics) this.transport;
for (EnumFacing dir : EnumFacing.VALUES) {
FluidStack stack = transport.sideTanks[dir.ordinal()].getFluid();
if (stack == null) {
continue;
}
stack = stack.copy();
if (nextSendMax[dir.ordinal()] > 0 && stack.amount < transport.sideTanks[dir.ordinal()].getCapacity()) {
nextSendMax[dir.ordinal()]--;
continue;
}
if (nextSendMin[dir.ordinal()] > 0) {
nextSendMin[dir.ordinal()]--;
continue;
}
Pair<Integer, FluidSinkReply> result = SimpleServiceLocator.logisticsFluidManager.getBestReply(FluidIdentifierStack.getFromStack(stack), getRouter(), tempJamList);
if (result == null || result.getValue2().sinkAmount <= 0) {
nextSendMax[dir.ordinal()] = 100;
nextSendMin[dir.ordinal()] = 10;
continue;
}
if (!useEnergy((int) (0.01 * result.getValue2().getSinkAmountInt()))) {
nextSendMax[dir.ordinal()] = 100;
nextSendMin[dir.ordinal()] = 10;
continue;
}
FluidStack toSend = transport.sideTanks[dir.ordinal()].drain(result.getValue2().getSinkAmountInt(), true);
ItemIdentifierStack liquidContainer = SimpleServiceLocator.logisticsFluidManager.getFluidContainer(FluidIdentifierStack.getFromStack(toSend));
IRoutedItem routed = SimpleServiceLocator.routedItemHelper.createNewTravelItem(liquidContainer);
routed.setDestination(result.getValue1());
routed.setTransportMode(TransportMode.Passive);
this.queueRoutedItem(routed, dir);
nextSendMax[dir.ordinal()] = 100;
nextSendMin[dir.ordinal()] = 5;
}
}
use of logisticspipes.transport.PipeFluidTransportLogistics in project LogisticsPipes by RS485.
the class PipeFluidSupplierMk2 method throttledUpdateEntity.
@Override
public void throttledUpdateEntity() {
if (!isEnabled()) {
return;
}
if (MainProxy.isClient(Objects.requireNonNull(container).getWorld())) {
return;
}
super.throttledUpdateEntity();
if (dummyInventory.getIDStackInSlot(0) == null) {
return;
}
PipeFluidUtil.INSTANCE.getAdjacentTanks(this, false).forEach(fluidHandlerDirectionPair -> {
if (!fluidHandlerDirectionPair.getValue2().containsTanks()) {
return;
}
// How much do I want?
Map<FluidIdentifier, Integer> wantFluids = new HashMap<>();
ItemIdentifierStack stack = dummyInventory.getIDStackInSlot(0);
if (stack == null)
return;
FluidIdentifier fIdent = FluidIdentifier.get(stack.getItem());
wantFluids.put(fIdent, amount);
// How much do I have?
HashMap<FluidIdentifier, Integer> haveFluids = new HashMap<>();
// Check what is inside the connected tank
fluidHandlerDirectionPair.getValue2().tanks().map(tank -> FluidIdentifierStack.getFromStack(tank.getContents())).filter(Objects::nonNull).forEach(fluid -> haveFluids.merge(fluid.getFluid(), fluid.getAmount(), Integer::sum));
// What does our sided internal tank have
int directionOrdinal = fluidHandlerDirectionPair.getValue1().getDirection().ordinal();
if (directionOrdinal < ((PipeFluidTransportLogistics) transport).sideTanks.length) {
FluidTank sideTank = ((PipeFluidTransportLogistics) transport).sideTanks[directionOrdinal];
if (sideTank != null && sideTank.getFluid() != null && wantFluids.containsKey(FluidIdentifier.get(sideTank.getFluid()))) {
haveFluids.merge(FluidIdentifier.get(sideTank.getFluid()), sideTank.getFluid().amount, Integer::sum);
}
}
// What does our center internal tank have
FluidTank centerTank = ((PipeFluidTransportLogistics) transport).internalTank;
if (centerTank != null && centerTank.getFluid() != null && wantFluids.containsKey(FluidIdentifier.get(centerTank.getFluid()))) {
haveFluids.merge(FluidIdentifier.get(centerTank.getFluid()), centerTank.getFluid().amount, Integer::sum);
}
// Reduce what I have and what have been requested already
for (Entry<FluidIdentifier, Integer> liquidId : wantFluids.entrySet()) {
Integer haveCount = haveFluids.get(liquidId.getKey());
if (haveCount != null) {
liquidId.setValue(liquidId.getValue() - haveCount);
}
// @formatter:off
_requestedItems.entrySet().stream().filter(requestedItem -> requestedItem.getKey().equals(liquidId.getKey())).forEach(requestedItem -> liquidId.setValue(liquidId.getValue() - requestedItem.getValue()));
// @formatter:on
}
setRequestFailed(false);
for (FluidIdentifier need : wantFluids.keySet()) {
int countToRequest = wantFluids.get(need);
if (countToRequest < 1) {
continue;
}
if (_bucketMinimum.getAmount() != 0 && countToRequest < _bucketMinimum.getAmount()) {
continue;
}
if (!useEnergy(11)) {
break;
}
boolean success = false;
if (_requestPartials) {
countToRequest = RequestTree.requestFluidPartial(need, countToRequest, this, null);
if (countToRequest > 0) {
success = true;
}
} else {
success = RequestTree.requestFluid(need, countToRequest, this, null);
}
if (success) {
Integer currentRequest = _requestedItems.get(need);
if (currentRequest == null) {
_requestedItems.put(need, countToRequest);
} else {
_requestedItems.put(need, currentRequest + countToRequest);
}
} else {
setRequestFailed(true);
}
}
});
}
Aggregations