bug fixes

fixed pipes not trading liquid to lower presure pipes
fixed a pump  issue that caused it to no have presure or connected
correctly
This commit is contained in:
Rseifert 2012-11-14 13:58:33 -05:00
parent 28f62284a0
commit e70f8c52c9
3 changed files with 231 additions and 150 deletions

View file

@ -104,7 +104,6 @@ public class BasicUtilitiesMain extends DummyModContainer
GameRegistry.registerTileEntity(TileEntityPump.class, "pump");
GameRegistry.registerTileEntity(TileEntityRod.class, "rod");
GameRegistry.registerTileEntity(TileEntityLTank.class, "ltank");
// Names and lang stuff
// Pipe Names
for (int i = 0; i < Liquid.values().length; i++)
{

View file

@ -1,156 +1,235 @@
package dark.BasicUtilities.machines;
import com.google.common.io.ByteArrayDataInput;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.INetworkManager;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.Packet;
import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.Vector3;
import universalelectricity.implement.IElectricityReceiver;
import universalelectricity.prefab.TileEntityElectricityReceiver;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.network.PacketManager;
import dark.BasicUtilities.BasicUtilitiesMain;
import dark.BasicUtilities.api.ILiquidProducer;
import dark.BasicUtilities.api.Liquid;
import dark.BasicUtilities.api.MHelper;
public class TileEntityPump extends TileEntityElectricityReceiver implements ILiquidProducer,IElectricityReceiver {
int dCount = 0;
float eStored = 0;
float eMax = 2000;
int lStored = 0;
int wMax = 10;
public Liquid type = Liquid.DEFUALT;
public TileEntity[] sList = {null,null,null,null,null,null};
private int count = 0;
@Override
public void onDisable(int duration) {
dCount = duration;
}
public class TileEntityPump extends TileEntityElectricityReceiver implements ILiquidProducer, IElectricityReceiver, IPacketReceiver
{
int dCount = 0;
float eStored = 0;
float eMax = 2000;
int lStored = 0;
int wMax = 10;
public Liquid type = Liquid.DEFUALT;
public TileEntity[] connectedBlocks =
{ null, null, null, null, null, null };
@Override
public boolean isDisabled() {
if(dCount <= 0)
{
return false;
}
return true;
}
private int count = 0;
private int count2 = 0;
@Override
public void updateEntity() {
super.updateEntity();
if(count++ >= 40)
{
count = 0;
sList = MHelper.getSourounding(worldObj,xCoord, yCoord, zCoord);
int bBlock = worldObj.getBlockId(xCoord, yCoord -1, zCoord);
Liquid bellow = Liquid.getLiquidByBlock(bBlock);
if(bellow != null && this.lStored <= 0)
{
this.type = bellow;
}
eStored+=200; //TODO remove after testing
if(!worldObj.isRemote)
{
if(bBlock == type.Still && this.eStored >= 200 && this.lStored < this.wMax)
{
eStored -= 200;
lStored += 1;
worldObj.setBlockAndMetadataWithNotify(xCoord, yCoord-1, zCoord, 0, 0);
}
}
}
}
/**
* Used to find the farthest source from the center location
* @param loc - center of search bounds
* @param maxRange - max search range
* @param liquid - liquid being searched for, if has no block registered to it returns null
*/
public Vector3 findDistanceSource(Vector3 loc, int maxRange, Liquid liquid)
{
//TODO create a way to scan the outer bounds
//looking for a source of x liquid
if(liquid.Still != 0 && liquid.Still != -1)
{
}
return null;
}
@Override
public boolean canReceiveFromSide(ForgeDirection side) {
if(side != ForgeDirection.DOWN)
{
return true;
}
return false;
}
@Override
public int onProduceLiquid(Liquid type, int maxVol, ForgeDirection side) {
if(type == this.type && lStored > 0)
{
lStored -= 1;
return 1;
}
return 0;
}
protected boolean firstUpdate = true;
@Override
public boolean canProduceLiquid(Liquid type, ForgeDirection side) {
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
int facing = 0;
switch(meta)
{
case 0: facing = 2;break;
case 1: facing = 5;break;
case 2: facing = 3;break;
case 3: facing = 4;break;
}
if(type == this.type && side != ForgeDirection.DOWN && side != ForgeDirection.UP && side != ForgeDirection.getOrientation(facing).getOpposite())
{
return true;
}
return false;
}
@Override
public void onDisable(int duration)
{
dCount = duration;
}
@Override
public int presureOutput(Liquid type, ForgeDirection side) {
if(type == Liquid.WATER)
{
return 32;
}else
if(type == Liquid.LAVA)
{
return 10;
}else
if(type == this.type)
{
return 50;
}
return 0;
}
@Override
public boolean isDisabled()
{
if (dCount <= 0) { return false; }
return true;
}
@Override
public boolean canProducePresure(Liquid type, ForgeDirection side) {
if(type == this.type)
{
return true;
}
return false;
}
@Override
public void updateEntity()
{
super.updateEntity();
if (count++ >= 20)
{
count = 0;
connectedBlocks = MHelper.getSourounding(worldObj, xCoord, yCoord, zCoord);
eStored += 200; // TODO remove after testing
if (!worldObj.isRemote)
{
if (firstUpdate || count2++ >= 5)
{
int bBlock = worldObj.getBlockId(xCoord, yCoord - 1, zCoord);
Liquid bellow = Liquid.getLiquidByBlock(bBlock);
@Override
public void onReceive(TileEntity sender, double watts, double voltage,
ForgeDirection side) {
if (wattRequest() > 0 && canConnect(side))
if (bellow != null && this.lStored <= 0) // TODO correct for full
// pump
{
this.type = bellow;
}
count2 = 0;
firstUpdate = false;
Packet packet = PacketManager.getPacket(BasicUtilitiesMain.CHANNEL, this, this.type.ordinal());
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 60);
}
this.drainBlock(new Vector3(xCoord, yCoord - 1, zCoord));
}
}
}
/**
* drains the block or in other words removes it
*
* @param loc
* @return true if the block was drained
*/
public boolean drainBlock(Vector3 loc)
{
int bBlock = worldObj.getBlockId(loc.intX(), loc.intY(), loc.intZ());
Liquid bellow = Liquid.getLiquidByBlock(bBlock);
if (bBlock == type.Still && this.eStored >= 200 && this.lStored < this.wMax)
{
eStored -= 200;
lStored += 1;
worldObj.setBlockAndMetadataWithNotify(xCoord, yCoord - 1, zCoord, 0, 0);
return true;
}
return false;
}
/**
* Used to find the farthest source from the center location
*
* @param loc
* - center of search bounds
* @param maxRange
* - max search range
* @param liquid
* - liquid being searched for, if has no block registered to it
* returns null
*/
public Vector3 findDistanceSource(Vector3 loc, int maxRange, Liquid liquid)
{
// TODO create a way to scan the outer bounds
// looking for a source of x liquid
if (liquid.Still != 0 && liquid.Still != -1)
{
}
return null;
}
@Override
public boolean canReceiveFromSide(ForgeDirection side)
{
if (side != ForgeDirection.DOWN) { return true; }
return false;
}
@Override
public int onProduceLiquid(Liquid type, int maxVol, ForgeDirection side)
{
if (type == this.type && lStored > 0 && maxVol > 0)
{
lStored -= 1;
return 1;
}
return 0;
}
@Override
public boolean canProduceLiquid(Liquid type, ForgeDirection side)
{
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
int facing = 0;
switch (meta)
{
case 0:
facing = 2;
break;
case 1:
facing = 5;
break;
case 2:
facing = 3;
break;
case 3:
facing = 4;
break;
}
if (type == this.type && side != ForgeDirection.DOWN && side != ForgeDirection.UP && side != ForgeDirection.getOrientation(facing).getOpposite()) { return true; }
return false;
}
@Override
public int presureOutput(Liquid type, ForgeDirection side)
{
if (type == this.type) { return type.defaultPresure; }
return 0;
}
@Override
public boolean canProducePresure(Liquid type, ForgeDirection side)
{
if (type == this.type) { return true; }
return false;
}
@Override
public void onReceive(TileEntity sender, double watts, double voltage, ForgeDirection side)
{
if (wattRequest() > 0 && canConnect(side))
{
float rejectedElectricity = (float) Math.max((this.eStored + watts) - this.eMax, 0.0);
this.eStored = (float) Math.max(this.eStored + watts - rejectedElectricity, 0.0);
}
}
@Override
public double wattRequest() {
return Math.max(eMax - eStored,0);
}
}
@Override
public double wattRequest()
{
return Math.max(eMax - eStored, 0);
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput data)
{
try
{
this.type = (Liquid.getLiquid(data.readInt()));
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
this.lStored = par1NBTTagCompound.getInteger("liquid");
this.type = Liquid.getLiquid(par1NBTTagCompound.getInteger("type"));
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
par1NBTTagCompound.setInteger("liquid", this.lStored);
par1NBTTagCompound.setInteger("type", this.type.ordinal());
}
}

View file

@ -47,37 +47,39 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer, IPack
{
count = 0;
this.connectedBlocks = MHelper.getSourounding(worldObj, xCoord, yCoord, zCoord);
this.presure = this.updatePressure();
this.updatePressure();
if (!worldObj.isRemote)
{
if (firstUpdate || count2++ >= 5)
{
count2 = 0;
firstUpdate = false;
Packet packet = PacketManager.getPacket(BasicUtilitiesMain.CHANNEL, this, this.type.ordinal() );
Packet packet = PacketManager.getPacket(BasicUtilitiesMain.CHANNEL, this, this.type.ordinal());
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 60);
}
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i).getOpposite();
ForgeDirection dir = ForgeDirection.getOrientation(i);
if (connectedBlocks[i] instanceof ILiquidProducer && ((ILiquidProducer) connectedBlocks[i]).canProduceLiquid(this.type, dir))
if (connectedBlocks[i] instanceof ILiquidProducer)
{
int vol = ((ILiquidProducer) connectedBlocks[i]).onProduceLiquid(this.type, this.capacity - this.liquidStored, dir);
this.liquidStored = Math.min(this.liquidStored + vol,
this.capacity);
}
if (connectedBlocks[i] instanceof ILiquidConsumer && ((ILiquidConsumer) connectedBlocks[i]).canRecieveLiquid(this.type, dir) && this.liquidStored > 0 && this.presure > 0)
if (connectedBlocks[i] instanceof ILiquidConsumer && this.liquidStored > 0 && this.presure > 0)
{
if (connectedBlocks[i] instanceof TileEntityPipe)
{
this.liquidStored--;
int vol = ((ILiquidConsumer) connectedBlocks[i]).onReceiveLiquid(this.type, Math.max(this.liquidStored, 1), dir);
this.liquidStored += vol;
if (((TileEntityPipe) connectedBlocks[i]).presure < this.presure)
{
this.liquidStored--;
int vol = ((ILiquidConsumer) connectedBlocks[i]).onReceiveLiquid(this.type, Math.max(this.liquidStored, 1), dir);
this.liquidStored += vol;
}
}
else
{
@ -90,19 +92,20 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer, IPack
}
/**
* used to cause the pipes presure to update depending on what is connected
* used to cause the pipes pressure to update depending on what is connected
* to it
*
* @return
*/
public int updatePressure()
public void updatePressure()
{
int highestPressure = 0;
this.connectedUnits = 0;
this.presure = 0;
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i).getOpposite();
ForgeDirection dir = ForgeDirection.getOrientation(i);
if (connectedBlocks[i] instanceof ILiquidConsumer && ((ILiquidConsumer) connectedBlocks[i]).canRecieveLiquid(this.type, dir))
{
@ -120,7 +123,7 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer, IPack
this.connectedUnits++;
if (((ILiquidProducer) connectedBlocks[i]).canProducePresure(this.type, dir) && ((ILiquidProducer) connectedBlocks[i]).presureOutput(this.type, dir) > highestPressure)
{
highestPressure = ((ILiquidProducer) connectedBlocks[i]).presureOutput(this.type, ForgeDirection.getOrientation(i));
highestPressure = ((ILiquidProducer) connectedBlocks[i]).presureOutput(this.type, dir);
}
}
else
@ -128,7 +131,7 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer, IPack
connectedBlocks[i] = null;
}
}
return highestPressure - 1;
this.presure = highestPressure - 1;
}
// ---------------
@ -141,7 +144,7 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer, IPack
{
int rejectedVolume = Math.max((this.getStoredLiquid(type) + vol) - this.capacity, 0);
this.liquidStored = Math.min(Math.max((liquidStored + vol - rejectedVolume), 0), this.capacity);
return rejectedVolume;
return Math.abs(rejectedVolume);
}
return vol;
}