forked from RS485/LogisticsPipes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing Module system for PipeFluidExtractor, PipeFluidInsertion…
…, PipeFluidSatellite, PipeFluidSupplierMk2, PipeItemsFluidSupplier. Change conditions stuff in PipeItemsSatelliteLogistics (Commit for: RS485#1679)
- Loading branch information
1 parent
bdd1aba
commit 6ff8fd8
Showing
11 changed files
with
425 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package logisticspipes.modules; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import net.minecraft.util.EnumFacing; | ||
|
||
import net.minecraftforge.fluids.FluidStack; | ||
|
||
import logisticspipes.interfaces.ITankUtil; | ||
import logisticspipes.pipes.PipeFluidUtil; | ||
import logisticspipes.transport.PipeFluidTransportLogistics; | ||
import logisticspipes.utils.FluidIdentifierStack; | ||
import network.rs485.logisticspipes.property.IntListProperty; | ||
import network.rs485.logisticspipes.property.Property; | ||
|
||
public class ModuleFluidExtractor extends ModuleFluidInsertion { | ||
|
||
private static final int flowRate = 500; | ||
private static final int energyPerFlow = 5; | ||
|
||
public final IntListProperty liquidToExtract = new IntListProperty("liquidToExtract"); | ||
|
||
@NotNull | ||
@Override | ||
public String getLPName() { | ||
throw new RuntimeException("Cannot get LP name for " + this); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public List<Property<?>> getProperties() { | ||
return Collections.singletonList(liquidToExtract); | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
PipeFluidUtil.INSTANCE.getAdjacentTanks(fluidPipe, false) | ||
.forEach(tankData -> extractFrom(tankData.getValue2(), tankData.getValue1().getDirection())); | ||
} | ||
|
||
private void extractFrom(ITankUtil container, EnumFacing side) { | ||
int sideID = side.ordinal(); | ||
FluidStack contained = ((PipeFluidTransportLogistics) fluidPipe.transport).getTankProperties(side)[0].getContents(); | ||
int amountMissing = ((PipeFluidTransportLogistics) fluidPipe.transport).getSideCapacity() - (contained != null ? contained.amount : 0); | ||
if (liquidToExtract.get(sideID) < Math.min(ModuleFluidExtractor.flowRate, amountMissing)) { | ||
if (fluidPipe.useEnergy(ModuleFluidExtractor.energyPerFlow)) { | ||
liquidToExtract.set(sideID, Math.min(ModuleFluidExtractor.flowRate, amountMissing)); | ||
} | ||
} | ||
FluidIdentifierStack extracted = container.drain(Math.min(liquidToExtract.get(sideID), ModuleFluidExtractor.flowRate), false); | ||
|
||
int inserted = 0; | ||
if (extracted != null) { | ||
inserted = ((PipeFluidTransportLogistics) fluidPipe.transport).fill(side, extracted.makeFluidStack(), true); | ||
container.drain(inserted, true); | ||
} | ||
liquidToExtract.increase(sideID, -inserted); | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
common/logisticspipes/modules/ModuleFluidInsertion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package logisticspipes.modules; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import net.minecraft.util.EnumFacing; | ||
|
||
import net.minecraftforge.fluids.FluidStack; | ||
|
||
import logisticspipes.logisticspipes.IRoutedItem; | ||
import logisticspipes.pipes.basic.fluid.FluidRoutedPipe; | ||
import logisticspipes.proxy.SimpleServiceLocator; | ||
import logisticspipes.transport.PipeFluidTransportLogistics; | ||
import logisticspipes.utils.FluidIdentifierStack; | ||
import logisticspipes.utils.FluidSinkReply; | ||
import logisticspipes.utils.item.ItemIdentifierStack; | ||
import logisticspipes.utils.tuples.Pair; | ||
import network.rs485.logisticspipes.property.IntListProperty; | ||
import network.rs485.logisticspipes.property.Property; | ||
|
||
public class ModuleFluidInsertion extends LogisticsModule { | ||
|
||
protected final FluidRoutedPipe fluidPipe = (FluidRoutedPipe) Objects.requireNonNull(_service, "service object was null in " + this); | ||
public final IntListProperty nextSendMax = new IntListProperty("nextSendMax"); | ||
public final IntListProperty nextSendMin = new IntListProperty("nextSendMin"); | ||
|
||
@NotNull | ||
@Override | ||
public String getLPName() { | ||
throw new RuntimeException("Cannot get LP name for " + this); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public List<Property<?>> getProperties() { | ||
return ImmutableList.<Property<?>>builder() | ||
.add(nextSendMax) | ||
.add(nextSendMin) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
PipeFluidTransportLogistics transport = (PipeFluidTransportLogistics) fluidPipe.transport; | ||
for (EnumFacing dir : EnumFacing.VALUES) { | ||
FluidStack stack = transport.sideTanks[dir.ordinal()].getFluid(); | ||
if (stack == null) { | ||
continue; | ||
} | ||
stack = stack.copy(); | ||
|
||
if (this.nextSendMax.get(dir.ordinal()) > 0 && stack.amount < transport.sideTanks[dir.ordinal()].getCapacity()) { | ||
this.nextSendMax.increase(dir.ordinal(), -1); | ||
continue; | ||
} | ||
if (nextSendMin.get(dir.ordinal()) > 0) { | ||
this.nextSendMin.increase(dir.ordinal(), -1); | ||
continue; | ||
} | ||
|
||
Pair<Integer, FluidSinkReply> result = SimpleServiceLocator.logisticsFluidManager.getBestReply(FluidIdentifierStack.getFromStack(stack), fluidPipe.getRouter(), new ArrayList<>()); | ||
if (result == null || result.getValue2().sinkAmount <= 0) { | ||
this.nextSendMax.set(dir.ordinal(), 100); | ||
this.nextSendMin.set(dir.ordinal(), 10); | ||
continue; | ||
} | ||
|
||
if (!fluidPipe.useEnergy((int) (0.01 * result.getValue2().getSinkAmountInt()))) { | ||
this.nextSendMax.set(dir.ordinal(), 100); | ||
this.nextSendMin.set(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(IRoutedItem.TransportMode.Passive); | ||
fluidPipe.queueRoutedItem(routed, dir); | ||
this.nextSendMax.set(dir.ordinal(), 100); | ||
this.nextSendMin.set(dir.ordinal(), 5); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean hasGenericInterests() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean interestedInAttachedInventory() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean interestedInUndamagedID() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean receivePassive() { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package logisticspipes.modules; | ||
|
||
import java.util.List; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import logisticspipes.pipes.PipeFluidSupplierMk2; | ||
import logisticspipes.utils.item.ItemIdentifierInventory; | ||
import network.rs485.logisticspipes.property.*; | ||
|
||
public class ModuleFluidSupplierMK2 extends ModuleFluidSupplier { | ||
|
||
public final InventoryProperty dummyInventory = new InventoryProperty( | ||
new ItemIdentifierInventory(1, "Fluid to keep stocked", 127, true), ""); | ||
public final IntegerProperty amount = new IntegerProperty(0, "amount"); | ||
public final BooleanProperty _requestPartials = new BooleanProperty(false, "requestpartials"); | ||
public final EnumProperty<PipeFluidSupplierMk2.MinMode> _bucketMinimum = new EnumProperty<>(PipeFluidSupplierMk2.MinMode.ONEBUCKET, | ||
"_bucketMinimum", PipeFluidSupplierMk2.MinMode.values()); | ||
|
||
@NotNull | ||
@Override | ||
public List<Property<?>> getProperties() { | ||
return ImmutableList.<Property<?>>builder() | ||
.add(dummyInventory) | ||
.add(amount) | ||
.add(_requestPartials) | ||
.add(_bucketMinimum) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.