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:
parent
28f62284a0
commit
e70f8c52c9
3 changed files with 231 additions and 150 deletions
|
@ -104,7 +104,6 @@ public class BasicUtilitiesMain extends DummyModContainer
|
||||||
GameRegistry.registerTileEntity(TileEntityPump.class, "pump");
|
GameRegistry.registerTileEntity(TileEntityPump.class, "pump");
|
||||||
GameRegistry.registerTileEntity(TileEntityRod.class, "rod");
|
GameRegistry.registerTileEntity(TileEntityRod.class, "rod");
|
||||||
GameRegistry.registerTileEntity(TileEntityLTank.class, "ltank");
|
GameRegistry.registerTileEntity(TileEntityLTank.class, "ltank");
|
||||||
// Names and lang stuff
|
|
||||||
// Pipe Names
|
// Pipe Names
|
||||||
for (int i = 0; i < Liquid.values().length; i++)
|
for (int i = 0; i < Liquid.values().length; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,91 +1,139 @@
|
||||||
package dark.BasicUtilities.machines;
|
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.minecraft.src.TileEntity;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import universalelectricity.core.Vector3;
|
import universalelectricity.core.Vector3;
|
||||||
import universalelectricity.implement.IElectricityReceiver;
|
import universalelectricity.implement.IElectricityReceiver;
|
||||||
import universalelectricity.prefab.TileEntityElectricityReceiver;
|
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.ILiquidProducer;
|
||||||
import dark.BasicUtilities.api.Liquid;
|
import dark.BasicUtilities.api.Liquid;
|
||||||
import dark.BasicUtilities.api.MHelper;
|
import dark.BasicUtilities.api.MHelper;
|
||||||
|
|
||||||
public class TileEntityPump extends TileEntityElectricityReceiver implements ILiquidProducer,IElectricityReceiver {
|
public class TileEntityPump extends TileEntityElectricityReceiver implements ILiquidProducer, IElectricityReceiver, IPacketReceiver
|
||||||
|
{
|
||||||
int dCount = 0;
|
int dCount = 0;
|
||||||
float eStored = 0;
|
float eStored = 0;
|
||||||
float eMax = 2000;
|
float eMax = 2000;
|
||||||
int lStored = 0;
|
int lStored = 0;
|
||||||
int wMax = 10;
|
int wMax = 10;
|
||||||
public Liquid type = Liquid.DEFUALT;
|
public Liquid type = Liquid.DEFUALT;
|
||||||
public TileEntity[] sList = {null,null,null,null,null,null};
|
public TileEntity[] connectedBlocks =
|
||||||
|
{ null, null, null, null, null, null };
|
||||||
|
|
||||||
private int count = 0;
|
private int count = 0;
|
||||||
|
private int count2 = 0;
|
||||||
|
|
||||||
|
protected boolean firstUpdate = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable(int duration) {
|
public void onDisable(int duration)
|
||||||
|
{
|
||||||
dCount = duration;
|
dCount = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDisabled() {
|
public boolean isDisabled()
|
||||||
if(dCount <= 0)
|
|
||||||
{
|
{
|
||||||
return false;
|
if (dCount <= 0) { return false; }
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity()
|
||||||
|
{
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
if(count++ >= 40)
|
if (count++ >= 20)
|
||||||
{
|
{
|
||||||
count = 0;
|
count = 0;
|
||||||
sList = MHelper.getSourounding(worldObj,xCoord, yCoord, zCoord);
|
connectedBlocks = MHelper.getSourounding(worldObj, xCoord, yCoord, zCoord);
|
||||||
int bBlock = worldObj.getBlockId(xCoord, yCoord -1, 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);
|
Liquid bellow = Liquid.getLiquidByBlock(bBlock);
|
||||||
|
|
||||||
if(bellow != null && this.lStored <= 0)
|
if (bellow != null && this.lStored <= 0) // TODO correct for full
|
||||||
|
// pump
|
||||||
{
|
{
|
||||||
this.type = bellow;
|
this.type = bellow;
|
||||||
}
|
}
|
||||||
eStored+=200; //TODO remove after testing
|
count2 = 0;
|
||||||
if(!worldObj.isRemote)
|
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)
|
||||||
{
|
{
|
||||||
if(bBlock == type.Still && this.eStored >= 200 && this.lStored < this.wMax)
|
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;
|
eStored -= 200;
|
||||||
lStored += 1;
|
lStored += 1;
|
||||||
worldObj.setBlockAndMetadataWithNotify(xCoord, yCoord-1, zCoord, 0, 0);
|
worldObj.setBlockAndMetadataWithNotify(xCoord, yCoord - 1, zCoord, 0, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Used to find the farthest source from the center location
|
* Used to find the farthest source from the center location
|
||||||
* @param loc - center of search bounds
|
*
|
||||||
* @param maxRange - max search range
|
* @param loc
|
||||||
* @param liquid - liquid being searched for, if has no block registered to it returns null
|
* - 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)
|
public Vector3 findDistanceSource(Vector3 loc, int maxRange, Liquid liquid)
|
||||||
{
|
{
|
||||||
//TODO create a way to scan the outer bounds
|
// TODO create a way to scan the outer bounds
|
||||||
//looking for a source of x liquid
|
// looking for a source of x liquid
|
||||||
if(liquid.Still != 0 && liquid.Still != -1)
|
if (liquid.Still != 0 && liquid.Still != -1)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canReceiveFromSide(ForgeDirection side) {
|
public boolean canReceiveFromSide(ForgeDirection side)
|
||||||
if(side != ForgeDirection.DOWN)
|
|
||||||
{
|
{
|
||||||
return true;
|
if (side != ForgeDirection.DOWN) { return true; }
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onProduceLiquid(Liquid type, int maxVol, ForgeDirection side) {
|
public int onProduceLiquid(Liquid type, int maxVol, ForgeDirection side)
|
||||||
if(type == this.type && lStored > 0)
|
{
|
||||||
|
if (type == this.type && lStored > 0 && maxVol > 0)
|
||||||
{
|
{
|
||||||
lStored -= 1;
|
lStored -= 1;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -94,53 +142,47 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements ILi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canProduceLiquid(Liquid type, ForgeDirection side) {
|
public boolean canProduceLiquid(Liquid type, ForgeDirection side)
|
||||||
|
{
|
||||||
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
|
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
|
||||||
int facing = 0;
|
int facing = 0;
|
||||||
switch(meta)
|
switch (meta)
|
||||||
{
|
{
|
||||||
case 0: facing = 2;break;
|
case 0:
|
||||||
case 1: facing = 5;break;
|
facing = 2;
|
||||||
case 2: facing = 3;break;
|
break;
|
||||||
case 3: facing = 4;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())
|
if (type == this.type && side != ForgeDirection.DOWN && side != ForgeDirection.UP && side != ForgeDirection.getOrientation(facing).getOpposite()) { return true; }
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int presureOutput(Liquid type, ForgeDirection side) {
|
public int presureOutput(Liquid type, ForgeDirection side)
|
||||||
if(type == Liquid.WATER)
|
|
||||||
{
|
{
|
||||||
return 32;
|
if (type == this.type) { return type.defaultPresure; }
|
||||||
}else
|
|
||||||
if(type == Liquid.LAVA)
|
|
||||||
{
|
|
||||||
return 10;
|
|
||||||
}else
|
|
||||||
if(type == this.type)
|
|
||||||
{
|
|
||||||
return 50;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canProducePresure(Liquid type, ForgeDirection side) {
|
public boolean canProducePresure(Liquid type, ForgeDirection side)
|
||||||
if(type == this.type)
|
|
||||||
{
|
{
|
||||||
return true;
|
if (type == this.type) { return true; }
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(TileEntity sender, double watts, double voltage,
|
public void onReceive(TileEntity sender, double watts, double voltage, ForgeDirection side)
|
||||||
ForgeDirection side) {
|
{
|
||||||
if (wattRequest() > 0 && canConnect(side))
|
if (wattRequest() > 0 && canConnect(side))
|
||||||
{
|
{
|
||||||
float rejectedElectricity = (float) Math.max((this.eStored + watts) - this.eMax, 0.0);
|
float rejectedElectricity = (float) Math.max((this.eStored + watts) - this.eMax, 0.0);
|
||||||
|
@ -150,7 +192,44 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements ILi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double wattRequest() {
|
public double wattRequest()
|
||||||
return Math.max(eMax - eStored,0);
|
{
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,38 +47,40 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer, IPack
|
||||||
{
|
{
|
||||||
count = 0;
|
count = 0;
|
||||||
this.connectedBlocks = MHelper.getSourounding(worldObj, xCoord, yCoord, zCoord);
|
this.connectedBlocks = MHelper.getSourounding(worldObj, xCoord, yCoord, zCoord);
|
||||||
this.presure = this.updatePressure();
|
this.updatePressure();
|
||||||
|
|
||||||
if (!worldObj.isRemote)
|
if (!worldObj.isRemote)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (firstUpdate || count2++ >= 5)
|
if (firstUpdate || count2++ >= 5)
|
||||||
{
|
{
|
||||||
count2 = 0;
|
count2 = 0;
|
||||||
firstUpdate = false;
|
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);
|
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++)
|
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);
|
int vol = ((ILiquidProducer) connectedBlocks[i]).onProduceLiquid(this.type, this.capacity - this.liquidStored, dir);
|
||||||
this.liquidStored = Math.min(this.liquidStored + vol,
|
this.liquidStored = Math.min(this.liquidStored + vol,
|
||||||
this.capacity);
|
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)
|
if (connectedBlocks[i] instanceof TileEntityPipe)
|
||||||
|
{
|
||||||
|
if (((TileEntityPipe) connectedBlocks[i]).presure < this.presure)
|
||||||
{
|
{
|
||||||
this.liquidStored--;
|
this.liquidStored--;
|
||||||
int vol = ((ILiquidConsumer) connectedBlocks[i]).onReceiveLiquid(this.type, Math.max(this.liquidStored, 1), dir);
|
int vol = ((ILiquidConsumer) connectedBlocks[i]).onReceiveLiquid(this.type, Math.max(this.liquidStored, 1), dir);
|
||||||
this.liquidStored += vol;
|
this.liquidStored += vol;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.liquidStored = ((ILiquidConsumer) connectedBlocks[i]).onReceiveLiquid(this.type, this.liquidStored, dir);
|
this.liquidStored = ((ILiquidConsumer) connectedBlocks[i]).onReceiveLiquid(this.type, this.liquidStored, dir);
|
||||||
|
@ -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
|
* to it
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int updatePressure()
|
public void updatePressure()
|
||||||
{
|
{
|
||||||
int highestPressure = 0;
|
int highestPressure = 0;
|
||||||
this.connectedUnits = 0;
|
this.connectedUnits = 0;
|
||||||
|
this.presure = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++)
|
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))
|
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++;
|
this.connectedUnits++;
|
||||||
if (((ILiquidProducer) connectedBlocks[i]).canProducePresure(this.type, dir) && ((ILiquidProducer) connectedBlocks[i]).presureOutput(this.type, dir) > highestPressure)
|
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
|
else
|
||||||
|
@ -128,7 +131,7 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer, IPack
|
||||||
connectedBlocks[i] = null;
|
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);
|
int rejectedVolume = Math.max((this.getStoredLiquid(type) + vol) - this.capacity, 0);
|
||||||
this.liquidStored = Math.min(Math.max((liquidStored + vol - rejectedVolume), 0), this.capacity);
|
this.liquidStored = Math.min(Math.max((liquidStored + vol - rejectedVolume), 0), this.capacity);
|
||||||
return rejectedVolume;
|
return Math.abs(rejectedVolume);
|
||||||
}
|
}
|
||||||
return vol;
|
return vol;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue