Cleaned up errors in pumps

Need to check these later too see if they actually function at all
This commit is contained in:
DarkGuardsman 2013-07-09 22:17:51 -04:00
parent e096748451
commit 6f0411f1fe
3 changed files with 90 additions and 128 deletions

View file

@ -74,7 +74,7 @@ public class LiquidPathFinder
int id = node.getBlockID(world);
int meta = node.getBlockID(world);
if (this.fill && (id == 0 || (FluidHelper.getLiquidFromBlockId(id) != null && meta != 0)))
if (this.fill && (id == 0 || (FluidHelper.getBlockFluidStack(id) != null && meta != 0)))
{
this.results.add(node);
}
@ -136,11 +136,11 @@ public class LiquidPathFinder
int blockID = pos.getBlockID(world);
if (!this.fill)
{
return FluidHelper.getLiquidFromBlockId(pos.getBlockID(world)) != null;
return FluidHelper.getBlockFluidStack(pos.getBlockID(world)) != null;
}
else
{
return FluidHelper.getLiquidFromBlockId(pos.getBlockID(world)) != null || (blockID == 0 && FluidHelper.getConnectedSources(world, pos) > 0);
return FluidHelper.getBlockFluidStack(pos.getBlockID(world)) != null || (blockID == 0 && FluidHelper.getConnectedSources(world, pos) > 0);
}
}

View file

@ -12,7 +12,10 @@ import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import universalelectricity.core.vector.Vector2;
import universalelectricity.core.vector.Vector3;
@ -97,16 +100,16 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
{
this.getNextFluidBlock();
}
for (Entry<TileEntity, LiquidStack> request : requestMap.entrySet())
for (Entry<TileEntity, FluidStack> request : requestMap.entrySet())
{
if (this.currentWorldEdits >= MAX_WORLD_EDITS_PER_PROCESS)
{
break;
}
if (request.getKey() instanceof ITankContainer)
if (request.getKey() instanceof IFluidHandler)
{
ITankContainer tank = (ITankContainer) request.getKey();
IFluidHandler tank = (IFluidHandler) request.getKey();
Vector3[] sortedList = this.sortedDrainList();
@ -118,20 +121,20 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
{
break;
}
if (FluidHelper.isSourceBlock(this.worldObj, loc))
FluidStack stack = FluidHelper.drainBlock(this.worldObj, loc, false);
if (stack != null)
{
/* GET STACKS */
LiquidStack stack = FluidHelper.getLiquidFromBlockId(loc.getBlockID(this.worldObj));
LiquidStack requestStack = request.getValue();
if (stack != null && requestStack != null && (requestStack.isLiquidEqual(stack) || requestStack.itemID == -1))
FluidStack requestStack = request.getValue();
if (stack != null && requestStack != null && (requestStack.isFluidEqual(stack) || requestStack.getFluid().getBlockID() == -111))
{
if (tank.fill(0, stack, false) > 0)
if (tank.fill(ForgeDirection.UNKNOWN, stack, false) > FluidContainerRegistry.BUCKET_VOLUME)
{
/* EDIT REQUEST IN MAP */
int requestAmmount = requestStack.amount - tank.fill(0, stack, true);
int requestAmmount = requestStack.amount - tank.fill(ForgeDirection.UNKNOWN, stack, true);
if (requestAmmount <= 0)
{
this.requestMap.remove(request);
@ -148,7 +151,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
}
/* REMOVE BLOCK */
loc.setBlock(this.worldObj, 0, 0, 2);
FluidHelper.drainBlock(this.worldObj, loc, true);
this.currentWorldEdits++;
}
}
@ -197,7 +200,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
while (requests.hasNext())
{
Entry<TileEntityConstructionPump, LiquidStack> entry = (Entry<TileEntityConstructionPump, LiquidStack>) requests.next();
Entry<TileEntityConstructionPump, FluidStack> entry = (Entry<TileEntityConstructionPump, FluidStack>) requests.next();
TileEntity entity = entry.getKey();
if (entity == null)
{
@ -224,7 +227,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
while (targetIt.hasNext())
{
Vector3 vec = targetIt.next();
if (!FluidHelper.isSourceBlock(this.worldObj, vec))
if (FluidHelper.drainBlock(this.worldObj, vec, false) == null)
{
targetIt.remove();
}
@ -304,42 +307,20 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
}
@Override
public int fillArea(LiquidStack resource, boolean doFill)
public int fillArea(FluidStack resource, boolean doFill)
{
int drained = 0;
if (!this.canDrainSources() && this.currentWorldEdits < MAX_WORLD_EDITS_PER_PROCESS)
{
/* ID LIQUID BLOCK AND SET VARS FOR BLOCK PLACEMENT */
if (resource == null || resource.amount < LiquidContainerRegistry.BUCKET_VOLUME)
if (resource == null || resource.amount < FluidContainerRegistry.BUCKET_VOLUME)
{
return 0;
}
int blockID = resource.itemID;
int meta = resource.itemMeta;
if (resource.itemID == Block.waterStill.blockID)
{
blockID = Block.waterStill.blockID;
meta = 0;
}
else if (resource.itemID != Block.lavaStill.blockID)
{
blockID = Block.lavaStill.blockID;
meta = 0;
}
else if (Block.blocksList[resource.itemID] instanceof ILiquid)
{
ILiquid liquidBlock = (ILiquid) Block.blocksList[resource.itemID];
blockID = liquidBlock.stillLiquidId();
meta = liquidBlock.stillLiquidMeta();
}
else
{
return 0;
}
int blocks = (resource.amount / LiquidContainerRegistry.BUCKET_VOLUME);
int blockID = resource.getFluid().getBlockID();
int blocks = (resource.amount / FluidContainerRegistry.BUCKET_VOLUME);
/* 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);
@ -389,14 +370,14 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
{
break;
}
LiquidStack stack = FluidHelper.getLiquidFromBlockId(loc.getBlockID(worldObj));
if (stack != null && stack.isLiquidEqual(resource) && loc.getBlockMetadata(worldObj) != 0)
Fluid stack = FluidHelper.getFluidFromBlockID(loc.getBlockID(worldObj));
if (stack != null && stack.getBlockID() == blockID && loc.getBlockMetadata(worldObj) != 0)
{
drained += LiquidContainerRegistry.BUCKET_VOLUME;
drained += FluidContainerRegistry.BUCKET_VOLUME;
blocks--;
if (doFill)
{
loc.setBlock(worldObj, blockID, meta);
loc.setBlock(worldObj, blockID, 0);
this.currentWorldEdits++;
if (!this.updateQue.contains(loc))
{
@ -415,11 +396,11 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
}
if (loc.getBlockID(worldObj) == 0)
{
drained += LiquidContainerRegistry.BUCKET_VOLUME;
drained += FluidContainerRegistry.BUCKET_VOLUME;
blocks--;
if (doFill)
{
loc.setBlock(worldObj, blockID, meta);
loc.setBlock(worldObj, blockID, 0);
this.currentWorldEdits++;
if (!this.updateQue.contains(loc))
{
@ -439,9 +420,9 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
}
@Override
public void requestLiquid(TileEntity pump, LiquidStack stack)
public void requestLiquid(TileEntity pump, Fluid fluid, int amount)
{
this.requestMap.put(pump, stack);
this.requestMap.put(pump, new FluidStack(-111, amount));
}
@Override
@ -462,19 +443,9 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
}
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
if (this.canDrainSources())
{
return 0;
}
return this.fill(0, resource, doFill);
}
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{
if (resource == null || tankIndex != 0)
if (this.canDrainSources() || resource == null)
{
return 0;
}
@ -482,29 +453,32 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand
}
@Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
if (from != this.getFacing().getOpposite())
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
// TODO Auto-generated method stub
return null;
}
return this.drain(0, maxDrain, doDrain);
}
@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return null;
}
@Override
public ILiquidTank[] getTanks(ForgeDirection direction)
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return null;
return this.getFacing() == from;
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return false;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return null;
}

View file

@ -5,10 +5,9 @@ import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidStack;
import universalelectricity.core.electricity.ElectricityPack;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
import universalelectricity.prefab.network.IPacketReceiver;
@ -17,9 +16,8 @@ import com.google.common.io.ByteArrayDataInput;
import dark.core.api.ColorCode;
import dark.core.api.IColorCoded;
import dark.core.api.IToolReadOut;
import dark.core.api.ITileConnector;
import dark.core.api.IToolReadOut.EnumTools;
import dark.core.api.IToolReadOut;
import dark.core.hydraulic.helpers.FluidHelper;
import dark.core.hydraulic.helpers.FluidRestrictionHandler;
import dark.helpers.MetaGroup;
@ -27,7 +25,7 @@ import dark.library.machine.TileEntityRunnableMachine;
public class TileEntityStarterPump extends TileEntityRunnableMachine implements IPacketReceiver, IToolReadOut, ITileConnector
{
public final double WATTS_PER_TICK = (400 / 20);
public final static float WATTS_PER_TICK = 20;
private double percentPumped = 0.0;
public int pos = 0;
@ -37,6 +35,12 @@ public class TileEntityStarterPump extends TileEntityRunnableMachine implements
ForgeDirection wireConnection = ForgeDirection.EAST;
ForgeDirection pipeConnection = ForgeDirection.EAST;
public TileEntityStarterPump()
{
super(20);
// TODO Auto-generated constructor stub
}
/** gets the side connection for the wire and pipe */
public void getConnections()
{
@ -66,9 +70,8 @@ public class TileEntityStarterPump extends TileEntityRunnableMachine implements
if (!this.worldObj.isRemote && !this.isDisabled())
{
if (this.canPump(xCoord, yCoord - 1, zCoord) && this.wattsReceived >= this.WATTS_PER_TICK)
if (this.canPump(new Vector3(xCoord, yCoord - 1, zCoord)) && this.canRun())
{
wattsReceived -= this.WATTS_PER_TICK;
if (percentPumped < 10)
{
percentPumped++;
@ -101,7 +104,6 @@ public class TileEntityStarterPump extends TileEntityRunnableMachine implements
try
{
this.color = ColorCode.get(data.readInt());
this.wattsReceived = data.readDouble();
}
catch (Exception e)
{
@ -110,35 +112,8 @@ public class TileEntityStarterPump extends TileEntityRunnableMachine implements
}
/** gets the fluidConductor or storageTank to ouput its pumped liquids too if there is not one it
* will not function */
public ITankContainer getFillTarget()
{
TileEntity ent = worldObj.getBlockTileEntity(xCoord + pipeConnection.offsetX, yCoord + pipeConnection.offsetY, zCoord + pipeConnection.offsetZ);
if (ent instanceof ITankContainer)
{
return (ITankContainer) ent;
}
return null;
}
/** gets the search range the pump used to find valid block to pump */
public int getPumpRange()
{
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
switch (MetaGroup.getGrouping(meta))
{
case 2:
return 20;
case 3:
return 50;
}
return 1;
}
@Override
public double getRequest(ForgeDirection side)
public float getRequest(ForgeDirection side)
{
return this.WATTS_PER_TICK;
}
@ -147,9 +122,10 @@ public class TileEntityStarterPump extends TileEntityRunnableMachine implements
*
* @param x y z - location of the block, use the tileEntities world
* @return true if it can pump */
boolean canPump(int x, int y, int z)
boolean canPump(Vector3 vec)
{
return getFillTarget() != null && FluidHelper.getLiquidId(worldObj.getBlockId(x, y, z)) != -1 && worldObj.getBlockMetadata(x, y, z) == 0;
FluidStack stack = FluidHelper.drainBlock(this.worldObj, vec, false);
return stack != null;
}
/** drains the block(removes) at the location given
@ -158,40 +134,52 @@ public class TileEntityStarterPump extends TileEntityRunnableMachine implements
* @return true if the block was drained */
boolean drainBlock(Vector3 loc)
{
int blockID = worldObj.getBlockId(loc.intX(), loc.intY(), loc.intZ());
LiquidStack stack = FluidHelper.getLiquidFromBlockId(blockID);
if (FluidRestrictionHandler.isValidLiquid(color, stack) && getFillTarget() != null)
FluidStack stack = FluidHelper.drainBlock(this.worldObj, loc, false);
if (FluidRestrictionHandler.isValidLiquid(color, stack.getFluid()) && this.fillAroundTile(stack, false) >= FluidContainerRegistry.BUCKET_VOLUME)
{
stack.amount = LiquidContainerRegistry.BUCKET_VOLUME;
int fillAmmount = getFillTarget().fill(pipeConnection.getOpposite(), stack, true);
if (fillAmmount > 0)
{
worldObj.setBlockMetadataWithNotify(xCoord, yCoord - 1, zCoord, 0, 0);
return true;
return this.fillAroundTile(FluidHelper.drainBlock(this.worldObj, loc, true), true) > 0;
}
}
return false;
}
public int fillAroundTile(FluidStack stack, boolean doFill)
{
if (stack != null && stack.getFluid() != null)
{
int amount = stack.amount;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity entity = new Vector3(this).modifyPositionFromSide(direction).getTileEntity(this.worldObj);
if (direction != ForgeDirection.DOWN && entity instanceof IFluidHandler)
{
amount -= ((IFluidHandler) entity).fill(direction.getOpposite(), FluidHelper.getStack(stack, amount), doFill);
}
if (amount <= 0)
{
break;
}
}
return amount;
}
return 0;
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side, EnumTools tool)
{
return String.format("%.2f/%.2f %f Done", this.wattsReceived, this.WATTS_PER_TICK, this.percentPumped);
return String.format("%.2f/%.2f %f Done", this.getEnergyStored(), this.getMaxEnergyStored(), this.percentPumped);
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return direction == wireConnection;
return direction != ForgeDirection.DOWN;
}
@Override
public boolean canTileConnect(TileEntity entity, ForgeDirection dir)
{
if (dir == this.pipeConnection.getOpposite() && entity instanceof ITankContainer)
if (dir == this.pipeConnection.getOpposite() && entity instanceof IFluidHandler)
{
return entity != null && entity instanceof IColorCoded && (((IColorCoded) entity).getColor() == ColorCode.NONE || ((IColorCoded) entity).getColor() == this.color);
}