Fixed tank not working when only one block

This commit is contained in:
Calclavia 2014-01-19 14:44:34 +08:00
parent 20dcbce5c5
commit 0f977d5b8a
5 changed files with 29 additions and 25 deletions

View file

@ -10,8 +10,9 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.api.fluid.IFluidNetwork;
import resonantinduction.api.fluid.IFluidConnector; import resonantinduction.api.fluid.IFluidConnector;
import resonantinduction.api.fluid.IFluidNetwork;
import resonantinduction.mechanical.fluid.tank.TileTank;
import universalelectricity.api.net.IConnector; import universalelectricity.api.net.IConnector;
import universalelectricity.core.net.ConnectionPathfinder; import universalelectricity.core.net.ConnectionPathfinder;
import universalelectricity.core.net.Network; import universalelectricity.core.net.Network;
@ -99,6 +100,7 @@ public abstract class FluidNetwork extends Network<IFluidNetwork, IFluidConnecto
{ {
this.rebuildHandler(); this.rebuildHandler();
} }
return fill; return fill;
} }

View file

@ -35,12 +35,11 @@ public class BlockPipe extends BlockFluidNetwork
} }
// Use Vanilla Couldron to fill it.
@Deprecated
@Override @Override
public void fillWithRain(World world, int x, int y, int z) public void fillWithRain(World world, int x, int y, int z)
{ {
int meta = world.getBlockMetadata(x, y, z); int meta = world.getBlockMetadata(x, y, z);
if (meta == FluidContainerMaterial.WOOD.ordinal() || meta == FluidContainerMaterial.STONE.ordinal()) if (meta == FluidContainerMaterial.WOOD.ordinal() || meta == FluidContainerMaterial.STONE.ordinal())
{ {
// TODO fill pipe since it will have an open top and can gather rain // TODO fill pipe since it will have an open top and can gather rain

View file

@ -22,17 +22,17 @@ public class PipeNetwork extends FluidNetwork
@Override @Override
public void update() public void update()
{ {
System.out.println("PipeNetwork:" + this.toString());
System.out.println("FluidVol: " + this.getTank().getFluidAmount());
super.update(); super.update();
// Slight delay to allow visual effect to take place before draining the pipe's internal /*
// tank * Slight delay to allow visual effect to take place before draining the pipe's internal
if (this.ticks % 2 == 0 && this.getTank().getFluidAmount() > 0) * tank
*/
if (this.getTank().getFluidAmount() > 0)
{ {
FluidStack stack = this.getTank().getFluid().copy(); FluidStack stack = this.getTank().getFluid().copy();
int count = this.connectionMap.size(); int count = this.connectionMap.size();
for (Entry<IFluidHandler, EnumSet<ForgeDirection>> entry : this.connectionMap.entrySet()) for (Entry<IFluidHandler, EnumSet<ForgeDirection>> entry : this.connectionMap.entrySet())
{ {
int sideCount = entry.getValue().size(); int sideCount = entry.getValue().size();
@ -46,7 +46,9 @@ public class PipeNetwork extends FluidNetwork
{ {
maxFill = ((IFluidPipe) entity).getMaxFlowRate(); maxFill = ((IFluidPipe) entity).getMaxFlowRate();
} }
stack.amount -= entry.getKey().fill(dir, FluidUtility.getStack(stack, Math.min(volPerSide, maxFill)), true); stack.amount -= entry.getKey().fill(dir, FluidUtility.getStack(stack, Math.min(volPerSide, maxFill)), true);
if (sideCount > 1) if (sideCount > 1)
--sideCount; --sideCount;
if (volPer <= 0) if (volPer <= 0)
@ -57,6 +59,7 @@ public class PipeNetwork extends FluidNetwork
if (stack == null || stack.amount <= 0) if (stack == null || stack.amount <= 0)
break; break;
} }
this.getTank().setFluid(stack); this.getTank().setFluid(stack);
// TODO check for change before rebuilding // TODO check for change before rebuilding
this.rebuildHandler(); this.rebuildHandler();
@ -72,7 +75,7 @@ public class PipeNetwork extends FluidNetwork
@Override @Override
public boolean continueUpdate() public boolean continueUpdate()
{ {
return true;// this.getConnectors().size() > 0; return this.getConnectors().size() > 0;
} }
@Override @Override

View file

@ -15,6 +15,18 @@ public class BlockFluidNetwork extends BlockRI
super(name); super(name);
} }
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileFluidNetwork)
{
((TileFluidNetwork) tile).refresh();
((TileFluidNetwork) tile).getNetwork().reconstruct();
}
}
@Override @Override
public void onNeighborBlockChange(World world, int x, int y, int z, int par5) public void onNeighborBlockChange(World world, int x, int y, int z, int par5)
{ {

View file

@ -100,31 +100,19 @@ public abstract class TileFluidNetwork<N extends FluidNetwork> extends TileEntit
@Override @Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{ {
if (this.getNetwork() != null && resource != null) return this.getNetwork().fill(this, from, resource, doFill);
{
return this.getNetwork().fill(this, from, resource, doFill);
}
return 0;
} }
@Override @Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{ {
if (this.getNetwork() != null && resource != null) return this.getNetwork().drain(this, from, resource, doDrain);
{
return this.getNetwork().drain(this, from, resource, doDrain);
}
return null;
} }
@Override @Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{ {
if (this.getNetwork() != null) return this.getNetwork().drain(this, from, maxDrain, doDrain);
{
return this.getNetwork().drain(this, from, maxDrain, doDrain);
}
return null;
} }
@Override @Override