Reworked the pumps

Construction pump now extends the basic pump. This was mainly done to
reduce duplicate code and make coding the two pumps easier.
This commit is contained in:
DarkGuardsman 2013-07-30 03:10:54 -04:00
parent 3b3be98019
commit cd7995661f
5 changed files with 198 additions and 73 deletions

View file

@ -27,13 +27,7 @@ public class HydraulicNetworkHelper
if (network != null && network instanceof NetworkFluidTiles)
{
network.removeTile(tileEntity);
for (IFluidHandler tank : ((NetworkFluidTiles) network).connectedTanks)
{
if (tank instanceof IDrain)
{
((IDrain) tank).stopRequesting(tileEntity);
}
}
}
}
}

View file

@ -47,7 +47,7 @@ public class RenderPump extends RenderMachine
break;
}
model.render(0.0625F);
model.renderMotion(0.0625F, te.pos);
model.renderMotion(0.0625F, te.rotation);
GL11.glPopMatrix();
}

View file

@ -2,9 +2,13 @@ package dark.fluid.common.prefab;
import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.prefab.tile.TileEntityAdvanced;
import dark.api.ITileConnector;
import dark.api.IToolReadOut;
import dark.api.IToolReadOut.EnumTools;
import dark.core.network.fluid.HydraulicNetworkHelper;
public abstract class TileEntityFluidDevice extends TileEntityAdvanced implements IToolReadOut, ITileConnector
@ -17,4 +21,14 @@ public abstract class TileEntityFluidDevice extends TileEntityAdvanced implement
super.invalidate();
HydraulicNetworkHelper.invalidate(this);
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side, EnumTools tool)
{
if (tool != null && tool == EnumTools.PIPE_GUAGE)
{
return " IndirectlyPower:"+this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
}
return null;
}
}

View file

@ -1,6 +1,10 @@
package dark.fluid.common.pump;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
@ -11,25 +15,31 @@ import net.minecraftforge.fluids.IFluidHandler;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
import dark.api.ITileConnector;
import dark.api.fluid.IDrain;
import dark.api.fluid.INetworkPipe;
import dark.core.blocks.TileEntityMachine;
import dark.core.helpers.MetaGroup;
import dark.core.helpers.Pair;
import dark.core.network.fluid.HydraulicNetworkHelper;
import dark.core.network.fluid.NetworkFluidTiles;
public class TileEntityConstructionPump extends TileEntityMachine implements IFluidHandler, ITileConnector
public class TileEntityConstructionPump extends TileEntityStarterPump implements IFluidHandler, ITileConnector
{
/* LIQUID FLOW CONNECTION SIDES */
/** Internal tank for interaction but not real storage */
private FluidTank fakeTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
private int liquidRequest = 5;
public int rotation = 0;
List<IDrain> drainsUsed = new ArrayList<IDrain>();
public TileEntityConstructionPump()
{
super(5);
super(5, 10, 30);
}
/** Gets the facing direction
*
* @param input true for input side, false for output side
* @return */
public ForgeDirection getFacing(boolean input)
{
int meta = 0;
@ -49,16 +59,45 @@ public class TileEntityConstructionPump extends TileEntityMachine implements IFl
}
@Override
public void updateEntity()
public Pair<World, Vector3> getDrainOrigin()
{
super.updateEntity();
if (!worldObj.isRemote && this.ticks % 10 == 0)
{
this.rotation = Math.max(Math.min(this.rotation + 1, 7), 0);
TileEntity inputTile = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), getFacing(true));
TileEntity outputTile = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), getFacing(false));
IDrain drain = this.getNextDrain(inputTile, outputTile, drainsUsed);
if (drain == null)
{
this.drainsUsed.clear();
drain = this.getNextDrain(inputTile, outputTile, drainsUsed);
}
if (drain instanceof TileEntity)
{
this.drainsUsed.add(drain);
return new Pair<World, Vector3>(((TileEntity) drain).worldObj, new Vector3(((TileEntity) drain)));
}
return null;
}
@Override
public boolean canRun()
{
return super.canRun() && this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
}
/** Gets the nextDrain in the list
*
* @param inputTile - input tile must be an instance of INetworkPipe
* @param outputTile - output tile must be an instance of IFluidHandler
* @param ignoreList - list of drains to ignore so that the next one is selected
* @return the next drain it finds or null if it went threw the entire list. Its suggested to
* clear the ignoreList after getting null */
public IDrain getNextDrain(TileEntity inputTile, TileEntity outputTile, List<IDrain> ignoreList)
{
IDrain drain = null;
if (ignoreList == null)
{
ignoreList = new ArrayList<IDrain>();
}
if (inputTile instanceof INetworkPipe && ((INetworkPipe) inputTile).getTileNetwork() instanceof NetworkFluidTiles)
{
@ -66,24 +105,15 @@ public class TileEntityConstructionPump extends TileEntityMachine implements IFl
{
for (IFluidHandler tank : ((NetworkFluidTiles) ((INetworkPipe) inputTile).getTileNetwork()).connectedTanks)
{
if (tank instanceof TileEntityDrain)
if (tank instanceof IDrain && !ignoreList.contains((IDrain) tank))
{
if (this.canRun() && this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
{
((TileEntityDrain) tank).requestLiquid(this, null, liquidRequest * FluidContainerRegistry.BUCKET_VOLUME);
}
else
{
((TileEntityDrain) tank).stopRequesting(this);
}
}
drain = (IDrain) tank;
break;
}
}
}
}
return drain;
}
@Override

View file

@ -3,9 +3,11 @@ package dark.fluid.common.pump;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
@ -13,24 +15,32 @@ import net.minecraftforge.fluids.IFluidHandler;
import universalelectricity.core.vector.Vector3;
import dark.api.ITileConnector;
import dark.api.IToolReadOut;
import dark.api.fluid.IDrain;
import dark.core.blocks.TileEntityMachine;
import dark.core.helpers.FluidHelper;
import dark.core.helpers.Pair;
public class TileEntityStarterPump extends TileEntityMachine implements IToolReadOut, ITileConnector
{
private int currentWorldEdits = 0;
private static final int MAX_WORLD_EDITS_PER_PROCESS = 5;
private int currentWorldEdits, MAX_WORLD_EDITS_PER_PROCESS;
public static float ENERGY_PER_DRAIN = 5;
public float ENERGY_PER_DRAIN = 5;
private List<Vector3> updateQue = new ArrayList<Vector3>();
private LiquidPathFinder pathLiquid;
private Vector3 lastDrainOrigin;
public int pos = 0;
public int rotation = 0;
public TileEntityStarterPump()
{
super(1, (MAX_WORLD_EDITS_PER_PROCESS * ENERGY_PER_DRAIN) + 20);
this(1, 5, 5);
}
public TileEntityStarterPump(float wattTick, float wattDrain, int maxEdits)
{
super(wattTick, (maxEdits * wattDrain) + (wattTick * 20));
this.MAX_WORLD_EDITS_PER_PROCESS = maxEdits;
this.ENERGY_PER_DRAIN = wattDrain;
}
public LiquidPathFinder getLiquidFinder()
@ -47,30 +57,99 @@ public class TileEntityStarterPump extends TileEntityMachine implements IToolRea
{
super.updateEntity();
if (!this.worldObj.isRemote && !this.isDisabled() && this.ticks % 20 == 0 && this.canRun())
if (this.ticks % 20 == 0)
{
this.currentWorldEdits = 0;
TileEntity entity = new Vector3(this).modifyPositionFromSide(ForgeDirection.DOWN).getTileEntity(worldObj);
if (this.running)
{
this.rotation = Math.max(Math.min(this.rotation + 1, 7), 0);
if (!this.worldObj.isRemote)
{
Pair<World, Vector3> pair = this.getDrainOrigin();
if (pair != null && pair.getKey() != null && pair.getValue() != null)
{
this.drainAroundArea(pair.getKey(), pair.getValue(), 3);
}
}
}
}
}
/** Gets the origin the path finder starts on */
public Pair<World, Vector3> getDrainOrigin()
{
//TODO change this to lower by the amount of air between the pump and bottom
return new Pair<World, Vector3>(this.worldObj, new Vector3(this).modifyPositionFromSide(ForgeDirection.DOWN));
}
/** Drains an area starting at the given location
*
* @param world - world to drain in, most cases will be the TileEntities world
* @param loc - origin to start the path finder with. If this is an instance of IDrain this
* method will act different */
public void drainAroundArea(World world, Vector3 vec, int update)
{
Vector3 origin = vec.clone();
if (origin == null)
{
return;
}
/* Update last drain origin to prevent failed path finding */
if (this.lastDrainOrigin == null || !this.lastDrainOrigin.equals(origin))
{
this.lastDrainOrigin = origin.clone();
this.getLiquidFinder().reset();
}
TileEntity drain = vec.clone().getTileEntity(world);
TileEntity entity = null;
Set<Vector3> drainList = null;
if (drain instanceof IDrain)
{
if (!((IDrain) drain).canDrain(((IDrain) drain).getDirection()))
{
return;
}
origin = vec.modifyPositionFromSide(((IDrain) drain).getDirection());
entity = origin.getTileEntity(world);
if (entity instanceof IFluidHandler)
{
FluidStack draStack = ((IFluidHandler) entity).drain(ForgeDirection.UP, MAX_WORLD_EDITS_PER_PROCESS * FluidContainerRegistry.BUCKET_VOLUME, false);
if (draStack != null && FluidHelper.fillTanksAllSides(worldObj, new Vector3(this), draStack, false, ForgeDirection.DOWN) > 0)
{
((IFluidHandler) entity).drain(ForgeDirection.UP, FluidHelper.fillTanksAllSides(worldObj, new Vector3(this), draStack, true, ForgeDirection.DOWN), true);
}
return;
}
else
{
drainList = ((IDrain) drain).getFluidList();
}
}
if (drainList == null)
{
if (this.getLiquidFinder().results.size() < TileEntityDrain.MAX_WORLD_EDITS_PER_PROCESS + 10)
{
this.getLiquidFinder().refresh().start(new Vector3(this).modifyPositionFromSide(ForgeDirection.DOWN), false);
this.getLiquidFinder().setWorld(world).refresh().start(origin, false);
}
drainList = this.getLiquidFinder().refresh().results;
}
if (entity == null && this.getLiquidFinder().results.size() > 0)
if (entity == null && drainList != null && drainList.size() > 0)
{
System.out.println("StartPump>>DrainArea>>Targets>" + this.getLiquidFinder().results.size());
//System.out.println("StartPump>>DrainArea>>Targets>" + this.getLiquidFinder().results.size());
Iterator<Vector3> fluidList = this.getLiquidFinder().results.iterator();
Iterator<Vector3> fluidList = drainList.iterator();
while (fluidList.hasNext() && this.consumePower(ENERGY_PER_DRAIN, false))
{
@ -80,25 +159,33 @@ public class TileEntityStarterPump extends TileEntityMachine implements IToolRea
}
Vector3 drainLocation = fluidList.next();
FluidStack drainStack = FluidHelper.drainBlock(this.worldObj, drainLocation, false, 3);
System.out.println("StartPump>>DrainArea>>Draining>>NextFluidBlock>" + (drainStack == null ? "Null" : drainStack.amount + "mb of " + drainStack.getFluid().getName()));
FluidStack drainStack = FluidHelper.drainBlock(world, drainLocation, false, 3);
// System.out.println("StartPump>>DrainArea>>Draining>>NextFluidBlock>" + (drainStack == null ? "Null" : drainStack.amount + "mb of " + drainStack.getFluid().getName()));
int fillV = FluidHelper.fillTanksAllSides(worldObj, new Vector3(this), drainStack, false, ForgeDirection.DOWN);
System.out.println("StartPump>>DrainArea>>Draining>>NextFluidBlock>Filled>" + fillV + "mb");
//int fillV = FluidHelper.fillTanksAllSides(worldObj, new Vector3(this), drainStack, false, ForgeDirection.DOWN);
//System.out.println("StartPump>>DrainArea>>Draining>>NextFluidBlock>Filled>" + fillV + "mb");
if (drainStack != null && fillV >= drainStack.amount && this.consumePower(ENERGY_PER_DRAIN, true))
if (drainStack != null && this.fill(drainStack, false) >= drainStack.amount && this.consumePower(ENERGY_PER_DRAIN, true))
{
System.out.println("StartPump>>DrainArea>>Draining>>Fluid>" + drainLocation.toString());
//System.out.println("StartPump>>DrainArea>>Draining>>Fluid>" + drainLocation.toString());
/* REMOVE BLOCK */
FluidHelper.drainBlock(this.worldObj, drainLocation, true, 3);
FluidHelper.fillTanksAllSides(worldObj, new Vector3(this), drainStack, true, ForgeDirection.DOWN);
FluidHelper.drainBlock(this.worldObj, drainLocation, true, update);
this.fill(drainStack, true);
this.currentWorldEdits++;
fluidList.remove();
if (drain instanceof IDrain)
{
((IDrain) drain).onUse(drainLocation);
}
}
}
}
}
public int fill(FluidStack stack, boolean doFill)
{
return FluidHelper.fillTanksAllSides(worldObj, new Vector3(this), stack, doFill, ForgeDirection.DOWN);
}
@Override