Changed how tiles request liquid from the drain

It now takes a fluidStack and amount allowing for the fluidStack to be
null. As well Fluid was changed to FluidStack so that the tag could be
included
This commit is contained in:
DarkGuardsman 2013-07-25 12:50:36 -04:00
parent c18400cf95
commit 72682ea705
4 changed files with 40 additions and 37 deletions

View file

@ -9,13 +9,13 @@ import net.minecraftforge.fluids.IFluidHandler;
* input or output for a pipe system. In code in order to interact with the pump the drain actual * input or output for a pipe system. In code in order to interact with the pump the drain actual
* has to do the filling/draining for the pump. The pump only need to find the drain and tell it to * has to do the filling/draining for the pump. The pump only need to find the drain and tell it to
* fill or drain an area. * fill or drain an area.
* *
* The use of ITankContainer is optional but is need for the drain to be added to a Fluid Network */ * The use of ITankContainer is optional but is need for the drain to be added to a Fluid Network */
public interface IDrain extends IFluidHandler public interface IDrain extends IFluidHandler
{ {
/** In the drain you can use the ITankContainer.fill methods or use this to get the drain to /** In the drain you can use the ITankContainer.fill methods or use this to get the drain to
* place a liquid into the world * place a liquid into the world
* *
* @param stack - valid LiquidStack that has a Liquid Block for it * @param stack - valid LiquidStack that has a Liquid Block for it
* @param doFill - actual do the action of filling or check if it can * @param doFill - actual do the action of filling or check if it can
* @return amount of liquid used */ * @return amount of liquid used */
@ -23,15 +23,15 @@ public interface IDrain extends IFluidHandler
/** Requests that this drain give the pump this liquid. The pump will have to decide if it can /** Requests that this drain give the pump this liquid. The pump will have to decide if it can
* accept, request, and maintain this demand * accept, request, and maintain this demand
* *
* @param pump - requesting pump * @param pump - requesting pump
* @param stack - liquid this pump wants for this request */ * @param stack - liquid this pump wants for this request */
public void requestLiquid(TileEntity pump, Fluid fluid, int amount); public void requestLiquid(TileEntity pump, FluidStack fluid, int amount);
/** Request that this drain no longer supply the pump with a volume. By default a request will be /** Request that this drain no longer supply the pump with a volume. By default a request will be
* removed from the request map after being filled. However, this can be used too stop a request * removed from the request map after being filled. However, this can be used too stop a request
* short if the pump becomes full before the request is filled * short if the pump becomes full before the request is filled
* *
* @param tileEntity - requesting pump */ * @param tileEntity - requesting pump */
public void stopRequesting(TileEntity tileEntity); public void stopRequesting(TileEntity tileEntity);
} }

View file

@ -96,9 +96,9 @@ public abstract class TileEntityFluidStorage extends TileEntityFluidDevice imple
} }
}else }else
{ {
System.out.println("Loading fluid tank"); //System.out.println("Loading fluid tank");
getTank().readFromNBT(nbt.getCompoundTag("FluidTank")); getTank().readFromNBT(nbt.getCompoundTag("FluidTank"));
System.out.println("Tank: "+ (getTank().getFluid() != null ? getTank().getFluid().fluidID +"@"+getTank().getFluid().amount+"mb" : "Empty")); //System.out.println("Tank: "+ (getTank().getFluid() != null ? getTank().getFluid().fluidID +"@"+getTank().getFluid().amount+"mb" : "Empty"));
} }
} }
@ -109,8 +109,8 @@ public abstract class TileEntityFluidStorage extends TileEntityFluidDevice imple
super.writeToNBT(nbt); super.writeToNBT(nbt);
if (this.getTank() != null) if (this.getTank() != null)
{ {
System.out.println("Saving fluid tank"); //System.out.println("Saving fluid tank");
System.out.println("Tank: "+ (getTank().getFluid() != null ? getTank().getFluid().fluidID +"@"+getTank().getFluid().amount+"mb" : "Empty")); //System.out.println("Tank: "+ (getTank().getFluid() != null ? getTank().getFluid().fluidID +"@"+getTank().getFluid().amount+"mb" : "Empty"));
nbt.setCompoundTag("FluidTank", this.getTank().writeToNBT(new NBTTagCompound())); nbt.setCompoundTag("FluidTank", this.getTank().writeToNBT(new NBTTagCompound()));
} }
} }

View file

@ -68,7 +68,6 @@ public class LiquidPathFinder
} }
int id = node.getBlockID(world); int id = node.getBlockID(world);
int meta = node.getBlockID(world);
if (this.fill && (id == 0 || (FluidHelper.isFillable(world, node)))) if (this.fill && (id == 0 || (FluidHelper.isFillable(world, node))))
{ {
this.results.add(node); this.results.add(node);

View file

@ -22,6 +22,7 @@ import universalelectricity.core.vector.VectorHelper;
import dark.api.fluid.IDrain; import dark.api.fluid.IDrain;
import dark.api.fluid.INetworkPipe; import dark.api.fluid.INetworkPipe;
import dark.core.helpers.FluidHelper; import dark.core.helpers.FluidHelper;
import dark.core.helpers.Pair;
import dark.fluid.common.prefab.TileEntityFluidDevice; import dark.fluid.common.prefab.TileEntityFluidDevice;
public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHandler, IDrain public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHandler, IDrain
@ -31,7 +32,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
private int currentWorldEdits = 0; private int currentWorldEdits = 0;
/* LIST OF PUMPS AND THERE REQUESTS FOR THIS DRAIN */ /* LIST OF PUMPS AND THERE REQUESTS FOR THIS DRAIN */
private HashMap<TileEntity, FluidStack> requestMap = new HashMap<TileEntity, FluidStack>(); private HashMap<TileEntity, Pair<FluidStack, Integer>> requestMap = new HashMap<TileEntity, Pair<FluidStack, Integer>>();
private List<Vector3> targetSources = new ArrayList<Vector3>(); private List<Vector3> targetSources = new ArrayList<Vector3>();
private List<Vector3> updateQue = new ArrayList<Vector3>(); private List<Vector3> updateQue = new ArrayList<Vector3>();
@ -99,7 +100,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
{ {
this.getNextFluidBlock(); this.getNextFluidBlock();
} }
for (Entry<TileEntity, FluidStack> request : requestMap.entrySet()) for (Entry<TileEntity, Pair<FluidStack, Integer>> request : requestMap.entrySet())
{ {
if (this.currentWorldEdits >= MAX_WORLD_EDITS_PER_PROCESS) if (this.currentWorldEdits >= MAX_WORLD_EDITS_PER_PROCESS)
{ {
@ -125,33 +126,36 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
{ {
/* GET STACKS */ /* GET STACKS */
FluidStack requestStack = request.getValue(); Pair<FluidStack, Integer> requestStack = request.getValue();
boolean flag = false;
if (stack != null && requestStack != null && (requestStack.isFluidEqual(stack) || requestStack.getFluid().getBlockID() == -111)) if (requestStack != null && requestStack.getValue() > 0)
{ {
if (tank.fill(ForgeDirection.UNKNOWN, stack, false) > FluidContainerRegistry.BUCKET_VOLUME) if (requestStack.getKey() == null || requestStack.getKey() != null && stack.isFluidEqual(requestStack.getKey().copy()))
{ {
if (tank.fill(ForgeDirection.UNKNOWN, stack, false) > FluidContainerRegistry.BUCKET_VOLUME)
/* EDIT REQUEST IN MAP */
int requestAmmount = requestStack.amount - tank.fill(ForgeDirection.UNKNOWN, stack, true);
if (requestAmmount <= 0)
{ {
this.requestMap.remove(request);
}
else
{
request.setValue(FluidHelper.getStack(requestStack, requestAmmount));
}
/* ADD TO UPDATE QUE */ /* EDIT REQUEST IN MAP */
if (!this.updateQue.contains(loc)) int requestAmmount = requestStack.getValue() - tank.fill(ForgeDirection.UNKNOWN, stack, true);
{ if (requestAmmount <= 0)
this.updateQue.add(loc); {
} this.requestMap.remove(request);
}
else
{
this.requestMap.put(request.getKey(),new Pair<FluidStack, Integer>(requestStack.getKey(),requestAmmount));
}
/* REMOVE BLOCK */ /* ADD TO UPDATE QUE */
FluidHelper.drainBlock(this.worldObj, loc, true); if (!this.updateQue.contains(loc))
this.currentWorldEdits++; {
this.updateQue.add(loc);
}
/* REMOVE BLOCK */
FluidHelper.drainBlock(this.worldObj, loc, true);
this.currentWorldEdits++;
}
} }
} }
} }
@ -324,7 +328,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
/* FIND ALL VALID BLOCKS ON LEVEL OR BELLOW */ /* FIND ALL VALID BLOCKS ON LEVEL OR BELLOW */
final Vector3 faceVec = new Vector3(this.xCoord + this.getFacing().offsetX, this.yCoord + this.getFacing().offsetY, this.zCoord + this.getFacing().offsetZ); final Vector3 faceVec = new Vector3(this.xCoord + this.getFacing().offsetX, this.yCoord + this.getFacing().offsetY, this.zCoord + this.getFacing().offsetZ);
getLiquidFinder().init(faceVec, true); getLiquidFinder().init(faceVec, true);
//System.out.println("Drain:FillArea: Targets -> " + getLiquidFinder().results.size()); System.out.println("Drain:FillArea: Targets -> " + getLiquidFinder().results.size());
/* SORT RESULTS TO PUT THE LOWEST AND CLOSEST AT THE TOP */ /* SORT RESULTS TO PUT THE LOWEST AND CLOSEST AT THE TOP */
try try
@ -419,9 +423,9 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
} }
@Override @Override
public void requestLiquid(TileEntity pump, Fluid fluid, int amount) public void requestLiquid(TileEntity pump, FluidStack fluid, int amount)
{ {
this.requestMap.put(pump, new FluidStack(-111, amount)); this.requestMap.put(pump, new Pair<FluidStack, Integer>(fluid, amount));
} }
@Override @Override