aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/tileentities/TE_TFFTMultiHatch.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/main/java/tileentities/TE_TFFTMultiHatch.java b/src/main/java/tileentities/TE_TFFTMultiHatch.java
index 94d7d9283a..1f92f924c4 100644
--- a/src/main/java/tileentities/TE_TFFTMultiHatch.java
+++ b/src/main/java/tileentities/TE_TFFTMultiHatch.java
@@ -2,7 +2,13 @@ package tileentities;
import java.util.List;
+import blocks.Block_TFFTStorageFieldBlockT1;
+import blocks.Block_TFFTStorageFieldBlockT2;
+import blocks.Block_TFFTStorageFieldBlockT3;
+import blocks.Block_TFFTStorageFieldBlockT4;
+import blocks.Block_TFFTStorageFieldBlockT5;
import kekztech.MultiFluidHandler;
+import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
@@ -13,13 +19,87 @@ import net.minecraftforge.fluids.IFluidHandler;
public class TE_TFFTMultiHatch extends TileEntity implements IFluidHandler {
+ private static final int OUTPUT_SPEED = 100; // L/s
+
private MultiFluidHandler mfh;
+ private int tickCounter = 0;
public void setMultiFluidHandler(MultiFluidHandler mfh) {
+ System.out.println("Set MFH");
this.mfh = mfh;
}
@Override
+ public void updateEntity() {
+ tickCounter++;
+ if(tickCounter == 100 && mfh != null) {
+
+ final ForgeDirection d = getOutwardsFacingDirection();
+ if(d == ForgeDirection.UNKNOWN) {
+ return;
+ }
+ final TileEntity t = this.getWorldObj().getTileEntity(
+ this.xCoord + d.offsetX,
+ this.yCoord + d.offsetY,
+ this.zCoord + d.offsetZ);
+
+ if(t != null && t instanceof IFluidHandler) {
+
+ final IFluidHandler fh = (IFluidHandler) t;
+
+ System.out.println("Found connecting tank");
+
+ // Cycle through fluids
+ for(FluidStack volume : mfh.getFluids()) {
+
+ // Use API methods
+ if(fh.canFill(d.getOpposite(), volume.getFluid())) {
+ System.out.println("Can fill " + volume.getLocalizedName());
+
+ // Test how much can be output
+ final FluidStack copy = volume.copy();
+ copy.amount = Math.min(volume.amount, OUTPUT_SPEED);
+
+ final int drawn = mfh.pullFluid(copy, false);
+ copy.amount = drawn;
+
+ System.out.println("Can output " + copy.amount + "L of" + copy.getLocalizedName());
+
+ // Test how much can be filled (and fill if possible)
+ final int filled = fh.fill(d.getOpposite(), copy, true);
+ copy.amount = Math.min(drawn, filled);
+
+ // Actually deplete storage
+ mfh.pullFluid(copy, true);
+ }
+ }
+ }
+
+ tickCounter = 0;
+ }
+ }
+
+ private ForgeDirection getOutwardsFacingDirection() {
+ // TODO Revisit this once the hatch has a facing side
+ // Look up which side has the storage field block and choose the other side.
+ // This is important so the tank doesn't output into itself in case
+ // there is another hatch next to this one.
+ for(ForgeDirection direction : ForgeDirection.values()) {
+
+ final Block b = this.getWorldObj().getBlock(this.xCoord + direction.offsetX, this.yCoord + direction.offsetY, this.zCoord + direction.offsetZ);
+ if(b != null && (
+ b.equals(Block_TFFTStorageFieldBlockT1.getInstance())
+ || b.equals(Block_TFFTStorageFieldBlockT2.getInstance())
+ || b.equals(Block_TFFTStorageFieldBlockT3.getInstance())
+ || b.equals(Block_TFFTStorageFieldBlockT4.getInstance())
+ || b.equals(Block_TFFTStorageFieldBlockT5.getInstance()))) {
+ return direction.getOpposite();
+ }
+ }
+ return ForgeDirection.UNKNOWN;
+ }
+
+ @Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
return (mfh != null) ? mfh.pushFluid(resource, doFill) : 0;
}