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(TileEntityRod.class, "rod");
|
||||
GameRegistry.registerTileEntity(TileEntityLTank.class, "ltank");
|
||||
// Names and lang stuff
|
||||
// Pipe Names
|
||||
for (int i = 0; i < Liquid.values().length; i++)
|
||||
{
|
||||
|
|
|
@ -1,69 +1,116 @@
|
|||
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 {
|
||||
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[] sList = {null,null,null,null,null,null};
|
||||
public TileEntity[] connectedBlocks =
|
||||
{ null, null, null, null, null, null };
|
||||
|
||||
private int count = 0;
|
||||
private int count2 = 0;
|
||||
|
||||
protected boolean firstUpdate = true;
|
||||
|
||||
@Override
|
||||
public void onDisable(int duration) {
|
||||
public void onDisable(int duration)
|
||||
{
|
||||
dCount = duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisabled() {
|
||||
if(dCount <= 0)
|
||||
public boolean isDisabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (dCount <= 0) { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
if(count++ >= 40)
|
||||
if (count++ >= 20)
|
||||
{
|
||||
count = 0;
|
||||
sList = MHelper.getSourounding(worldObj,xCoord, yCoord, zCoord);
|
||||
int bBlock = worldObj.getBlockId(xCoord, yCoord -1, zCoord);
|
||||
Liquid bellow = Liquid.getLiquidByBlock(bBlock);
|
||||
connectedBlocks = MHelper.getSourounding(worldObj, xCoord, yCoord, zCoord);
|
||||
|
||||
if(bellow != null && this.lStored <= 0)
|
||||
{
|
||||
this.type = bellow;
|
||||
}
|
||||
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);
|
||||
|
||||
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
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
|
@ -75,17 +122,18 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements ILi
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceiveFromSide(ForgeDirection side) {
|
||||
if(side != ForgeDirection.DOWN)
|
||||
public boolean canReceiveFromSide(ForgeDirection side)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (side != ForgeDirection.DOWN) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onProduceLiquid(Liquid type, int maxVol, ForgeDirection side) {
|
||||
if(type == this.type && lStored > 0)
|
||||
public int onProduceLiquid(Liquid type, int maxVol, ForgeDirection side)
|
||||
{
|
||||
if (type == this.type && lStored > 0 && maxVol > 0)
|
||||
{
|
||||
lStored -= 1;
|
||||
return 1;
|
||||
|
@ -94,53 +142,47 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements ILi
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canProduceLiquid(Liquid type, ForgeDirection side) {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
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 == Liquid.WATER)
|
||||
public int presureOutput(Liquid type, ForgeDirection side)
|
||||
{
|
||||
return 32;
|
||||
}else
|
||||
if(type == Liquid.LAVA)
|
||||
{
|
||||
return 10;
|
||||
}else
|
||||
if(type == this.type)
|
||||
{
|
||||
return 50;
|
||||
}
|
||||
if (type == this.type) { return type.defaultPresure; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProducePresure(Liquid type, ForgeDirection side) {
|
||||
if(type == this.type)
|
||||
public boolean canProducePresure(Liquid type, ForgeDirection side)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (type == this.type) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(TileEntity sender, double watts, double voltage,
|
||||
ForgeDirection side) {
|
||||
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);
|
||||
|
@ -150,7 +192,44 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements ILi
|
|||
}
|
||||
|
||||
@Override
|
||||
public double wattRequest() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,11 +47,10 @@ 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;
|
||||
|
@ -63,22 +62,25 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer, IPack
|
|||
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)
|
||||
{
|
||||
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
|
||||
{
|
||||
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
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue