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:
parent
c18400cf95
commit
72682ea705
4 changed files with 40 additions and 37 deletions
|
@ -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
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* The use of ITankContainer is optional but is need for the drain to be added to a Fluid Network */
|
||||
public interface IDrain extends IFluidHandler
|
||||
{
|
||||
/** In the drain you can use the ITankContainer.fill methods or use this to get the drain to
|
||||
* place a liquid into the world
|
||||
*
|
||||
*
|
||||
* @param stack - valid LiquidStack that has a Liquid Block for it
|
||||
* @param doFill - actual do the action of filling or check if it can
|
||||
* @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
|
||||
* accept, request, and maintain this demand
|
||||
*
|
||||
*
|
||||
* @param pump - requesting pump
|
||||
* @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
|
||||
* 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
|
||||
*
|
||||
*
|
||||
* @param tileEntity - requesting pump */
|
||||
public void stopRequesting(TileEntity tileEntity);
|
||||
}
|
||||
|
|
|
@ -96,9 +96,9 @@ public abstract class TileEntityFluidStorage extends TileEntityFluidDevice imple
|
|||
}
|
||||
}else
|
||||
{
|
||||
System.out.println("Loading fluid tank");
|
||||
//System.out.println("Loading fluid tank");
|
||||
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);
|
||||
if (this.getTank() != null)
|
||||
{
|
||||
System.out.println("Saving fluid tank");
|
||||
System.out.println("Tank: "+ (getTank().getFluid() != null ? getTank().getFluid().fluidID +"@"+getTank().getFluid().amount+"mb" : "Empty"));
|
||||
//System.out.println("Saving fluid tank");
|
||||
//System.out.println("Tank: "+ (getTank().getFluid() != null ? getTank().getFluid().fluidID +"@"+getTank().getFluid().amount+"mb" : "Empty"));
|
||||
nbt.setCompoundTag("FluidTank", this.getTank().writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,6 @@ public class LiquidPathFinder
|
|||
}
|
||||
|
||||
int id = node.getBlockID(world);
|
||||
int meta = node.getBlockID(world);
|
||||
if (this.fill && (id == 0 || (FluidHelper.isFillable(world, node))))
|
||||
{
|
||||
this.results.add(node);
|
||||
|
|
|
@ -22,6 +22,7 @@ import universalelectricity.core.vector.VectorHelper;
|
|||
import dark.api.fluid.IDrain;
|
||||
import dark.api.fluid.INetworkPipe;
|
||||
import dark.core.helpers.FluidHelper;
|
||||
import dark.core.helpers.Pair;
|
||||
import dark.fluid.common.prefab.TileEntityFluidDevice;
|
||||
|
||||
public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHandler, IDrain
|
||||
|
@ -31,7 +32,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
|
|||
private int currentWorldEdits = 0;
|
||||
|
||||
/* 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> updateQue = new ArrayList<Vector3>();
|
||||
|
@ -99,7 +100,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
|
|||
{
|
||||
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)
|
||||
{
|
||||
|
@ -125,33 +126,36 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
|
|||
{
|
||||
/* GET STACKS */
|
||||
|
||||
FluidStack requestStack = request.getValue();
|
||||
|
||||
if (stack != null && requestStack != null && (requestStack.isFluidEqual(stack) || requestStack.getFluid().getBlockID() == -111))
|
||||
Pair<FluidStack, Integer> requestStack = request.getValue();
|
||||
boolean flag = false;
|
||||
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()))
|
||||
{
|
||||
|
||||
/* EDIT REQUEST IN MAP */
|
||||
int requestAmmount = requestStack.amount - tank.fill(ForgeDirection.UNKNOWN, stack, true);
|
||||
if (requestAmmount <= 0)
|
||||
if (tank.fill(ForgeDirection.UNKNOWN, stack, false) > FluidContainerRegistry.BUCKET_VOLUME)
|
||||
{
|
||||
this.requestMap.remove(request);
|
||||
}
|
||||
else
|
||||
{
|
||||
request.setValue(FluidHelper.getStack(requestStack, requestAmmount));
|
||||
}
|
||||
|
||||
/* ADD TO UPDATE QUE */
|
||||
if (!this.updateQue.contains(loc))
|
||||
{
|
||||
this.updateQue.add(loc);
|
||||
}
|
||||
/* EDIT REQUEST IN MAP */
|
||||
int requestAmmount = requestStack.getValue() - tank.fill(ForgeDirection.UNKNOWN, stack, true);
|
||||
if (requestAmmount <= 0)
|
||||
{
|
||||
this.requestMap.remove(request);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.requestMap.put(request.getKey(),new Pair<FluidStack, Integer>(requestStack.getKey(),requestAmmount));
|
||||
}
|
||||
|
||||
/* REMOVE BLOCK */
|
||||
FluidHelper.drainBlock(this.worldObj, loc, true);
|
||||
this.currentWorldEdits++;
|
||||
/* ADD TO UPDATE QUE */
|
||||
if (!this.updateQue.contains(loc))
|
||||
{
|
||||
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 */
|
||||
final Vector3 faceVec = new Vector3(this.xCoord + this.getFacing().offsetX, this.yCoord + this.getFacing().offsetY, this.zCoord + this.getFacing().offsetZ);
|
||||
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 */
|
||||
try
|
||||
|
@ -419,9 +423,9 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
|
|||
}
|
||||
|
||||
@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
|
||||
|
|
Loading…
Reference in a new issue