Cleanup and more bug fixes
Trying to reduce pack load Fixed mech rod not slowing down when force = 0 Fixed Pipes render bug
This commit is contained in:
parent
5d2450a061
commit
89e5ca315b
6 changed files with 127 additions and 142 deletions
|
@ -37,17 +37,15 @@ public class BlockPipe extends BlockContainer
|
|||
super.onBlockAdded(world, x, y, z);
|
||||
this.updateConductorTileEntity(world, x, y, z);
|
||||
}
|
||||
public static TileEntity getLiquidUnit(World world, int x, int y, int z, int side,Liquid type)
|
||||
public static TileEntity getLiquidUnit(World world, int x, int y, int z, ForgeDirection side,Liquid type)
|
||||
{
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(side);
|
||||
|
||||
//Check if the designated block is a UE Unit - producer, consumer or a conductor
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ);
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x+side.offsetX, y+side.offsetY, z+side.offsetZ);
|
||||
TileEntity returnValue = null;
|
||||
|
||||
if(tileEntity instanceof ILiquidConsumer)
|
||||
{
|
||||
if(((ILiquidConsumer)tileEntity).canRecieveLiquid(type,ForgeDirection.getOrientation(side)))
|
||||
if(((ILiquidConsumer)tileEntity).canRecieveLiquid(type,side))
|
||||
{
|
||||
returnValue = tileEntity;
|
||||
}
|
||||
|
@ -55,7 +53,7 @@ public class BlockPipe extends BlockContainer
|
|||
|
||||
if (tileEntity instanceof ILiquidProducer)
|
||||
{
|
||||
if(((ILiquidProducer)tileEntity).canProduceLiquid(type,ForgeDirection.getOrientation(side)))
|
||||
if(((ILiquidProducer)tileEntity).canProduceLiquid(type,side))
|
||||
{
|
||||
returnValue = tileEntity;
|
||||
}
|
||||
|
@ -95,7 +93,8 @@ public class BlockPipe extends BlockContainer
|
|||
{
|
||||
TileEntityPipe conductorTileEntity = (TileEntityPipe) tileEntity;
|
||||
Liquid type = conductorTileEntity.getType();
|
||||
conductorTileEntity.addConnection(getLiquidUnit(world, x, y, z, i, type), ForgeDirection.getOrientation(i));
|
||||
ForgeDirection side = ForgeDirection.getOrientation(i);
|
||||
conductorTileEntity.addConnection(getLiquidUnit(world, x, y, z, side, type), side);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer,IPacke
|
|||
{
|
||||
this.connectedBlocks[side.ordinal()] = tileEntity;
|
||||
}
|
||||
}
|
||||
}else
|
||||
if(tileEntity instanceof ILiquidProducer)
|
||||
{
|
||||
if(((ILiquidProducer)tileEntity).canProduceLiquid(this.type, side))
|
||||
|
@ -72,110 +72,113 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer,IPacke
|
|||
}
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
if(++count >= 5 && !this.worldObj.isRemote)
|
||||
{count = 0;
|
||||
//update connections
|
||||
{
|
||||
if(++count >= 10 || firstUpdate)
|
||||
{count = 0;firstUpdate = false;
|
||||
BlockPipe.updateConductorTileEntity(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
||||
//send packet with liquid type data
|
||||
Packet packet = PacketManager.getPacket("Pipes",this, new Object[]{this.type.ordinal()});
|
||||
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40);
|
||||
if(!this.worldObj.isRemote){
|
||||
//update connections
|
||||
|
||||
//send packet with liquid type data
|
||||
Packet packet = PacketManager.getPacket("Pipes",this, new Object[]{this.type.ordinal()});
|
||||
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 60);
|
||||
|
||||
|
||||
|
||||
|
||||
int connectedUnits = 0;
|
||||
int pipes = 1;
|
||||
int producers = 0;
|
||||
int averageVolume = this.liquidStored;
|
||||
int aProducerPressure = 0;
|
||||
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
if(connectedBlocks[i] instanceof ILiquidConsumer || connectedBlocks[i] instanceof ILiquidProducer)
|
||||
{
|
||||
connectedUnits ++;
|
||||
if(connectedBlocks[i] instanceof ILiquidProducer)
|
||||
|
||||
int connectedUnits = 0;
|
||||
int pipes = 1;
|
||||
int producers = 0;
|
||||
int averageVolume = this.liquidStored;
|
||||
int aProducerPressure = 0;
|
||||
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
if(connectedBlocks[i] instanceof ILiquidConsumer || connectedBlocks[i] instanceof ILiquidProducer)
|
||||
{
|
||||
if(((ILiquidProducer)connectedBlocks[i]).canProducePresure(this.type, ForgeDirection.getOrientation(i)))
|
||||
connectedUnits ++;
|
||||
if(connectedBlocks[i] instanceof ILiquidProducer)
|
||||
{
|
||||
aProducerPressure += ((ILiquidProducer)connectedBlocks[i]).presureOutput(this.type,ForgeDirection.getOrientation(i));
|
||||
producers++;
|
||||
if(((ILiquidProducer)connectedBlocks[i]).canProducePresure(this.type, ForgeDirection.getOrientation(i)))
|
||||
{
|
||||
aProducerPressure += ((ILiquidProducer)connectedBlocks[i]).presureOutput(this.type,ForgeDirection.getOrientation(i));
|
||||
producers++;
|
||||
}
|
||||
}
|
||||
|
||||
if(connectedBlocks[i] instanceof TileEntityPipe)
|
||||
{
|
||||
pipes ++;
|
||||
//add pipes volume to average collection value
|
||||
averageVolume += ((TileEntityPipe)connectedBlocks[i]).liquidStored;
|
||||
//get the current pipes pressure
|
||||
int pPressure = ((TileEntityPipe)connectedBlocks[i]).presure ;
|
||||
if(pPressure > hPressure)
|
||||
{
|
||||
this.hPressure = pPressure;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(connectedBlocks[i] instanceof TileEntityPipe)
|
||||
{
|
||||
pipes ++;
|
||||
//add pipes volume to average collection value
|
||||
averageVolume += ((TileEntityPipe)connectedBlocks[i]).liquidStored;
|
||||
//get the current pipes pressure
|
||||
int pPressure = ((TileEntityPipe)connectedBlocks[i]).presure ;
|
||||
if(pPressure > hPressure)
|
||||
{
|
||||
this.hPressure = pPressure;
|
||||
}
|
||||
}
|
||||
}
|
||||
//turn average collection into actual average pipe volume
|
||||
averageVolume = Math.max(averageVolume/pipes,0);
|
||||
//sets the pressure of the pipe to the producer pressure or to the highest pipe pressure -1
|
||||
if(producers > 0)
|
||||
{
|
||||
aProducerPressure = Math.max(aProducerPressure/producers,0);
|
||||
this.presure = aProducerPressure;
|
||||
}
|
||||
}
|
||||
//turn average collection into actual average pipe volume
|
||||
averageVolume = Math.max(averageVolume/pipes,0);
|
||||
//sets the pressure of the pipe to the producer pressure or to the highest pipe pressure -1
|
||||
if(producers > 0)
|
||||
{
|
||||
aProducerPressure = Math.max(aProducerPressure/producers,0);
|
||||
this.presure = aProducerPressure;
|
||||
}
|
||||
else
|
||||
if(connectedUnits > 0)
|
||||
{
|
||||
this.presure = hPressure - 1;
|
||||
}else
|
||||
{
|
||||
this.presure = 1;
|
||||
}
|
||||
//only trade liquid if there is more than one thing connect and its pressure is higher than 1
|
||||
if(connectedUnits > 0 && this.presure > 0)
|
||||
{
|
||||
for(byte i = 0; i < 6; i++)
|
||||
{
|
||||
if(connectedBlocks[i] != null)
|
||||
{
|
||||
//Spread the liquid among the different blocks
|
||||
if(connectedBlocks[i] instanceof ILiquidConsumer && this.liquidStored > 0)
|
||||
{
|
||||
if(((ILiquidConsumer)connectedBlocks[i]).canRecieveLiquid(this.type,ForgeDirection.getOrientation(i)))
|
||||
{
|
||||
int transferVolumeAmount = 0; //amount to be moved
|
||||
ILiquidConsumer connectedConsumer = ((ILiquidConsumer)connectedBlocks[i]);
|
||||
if(connectedConsumer instanceof TileEntityPipe)
|
||||
else
|
||||
if(connectedUnits > 0)
|
||||
{
|
||||
this.presure = hPressure - 1;
|
||||
}else
|
||||
{
|
||||
this.presure = 1;
|
||||
}
|
||||
//only trade liquid if there is more than one thing connect and its pressure is higher than 1
|
||||
if(connectedUnits > 0 && this.presure > 0)
|
||||
{
|
||||
for(byte i = 0; i < 6; i++)
|
||||
{
|
||||
if(connectedBlocks[i] != null)
|
||||
{
|
||||
//Spread the liquid among the different blocks
|
||||
if(connectedBlocks[i] instanceof ILiquidConsumer && this.liquidStored > 0)
|
||||
{
|
||||
if(((ILiquidConsumer)connectedBlocks[i]).canRecieveLiquid(this.type,ForgeDirection.getOrientation(i)))
|
||||
{
|
||||
if(((TileEntityPipe)connectedBlocks[i]).presure < this.presure)
|
||||
int transferVolumeAmount = 0; //amount to be moved
|
||||
ILiquidConsumer connectedConsumer = ((ILiquidConsumer)connectedBlocks[i]);
|
||||
if(connectedConsumer instanceof TileEntityPipe)
|
||||
{
|
||||
if(((TileEntityPipe)connectedBlocks[i]).presure < this.presure)
|
||||
{
|
||||
transferVolumeAmount = this.liquidStored;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
transferVolumeAmount = this.liquidStored;
|
||||
}
|
||||
}
|
||||
|
||||
int rejectedVolume = connectedConsumer.onReceiveLiquid(this.type,transferVolumeAmount, ForgeDirection.getOrientation(i));
|
||||
this.liquidStored = Math.max(Math.min(this.liquidStored - transferVolumeAmount + rejectedVolume, this.capacity), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
transferVolumeAmount = this.liquidStored;
|
||||
}
|
||||
|
||||
int rejectedVolume = connectedConsumer.onReceiveLiquid(this.type,transferVolumeAmount, ForgeDirection.getOrientation(i));
|
||||
this.liquidStored = Math.max(Math.min(this.liquidStored - transferVolumeAmount + rejectedVolume, this.capacity), 0);
|
||||
}
|
||||
}
|
||||
if(connectedBlocks[i] instanceof ILiquidProducer && this.liquidStored < this.getLiquidCapacity(type))
|
||||
{
|
||||
if(((ILiquidProducer)connectedBlocks[i]).canProduceLiquid(this.type,ForgeDirection.getOrientation(i)))
|
||||
}
|
||||
if(connectedBlocks[i] instanceof ILiquidProducer && this.liquidStored < this.getLiquidCapacity(type))
|
||||
{
|
||||
int gainedVolume = ((ILiquidProducer)connectedBlocks[i]).onProduceLiquid(this.type,this.capacity-this.liquidStored, ForgeDirection.getOrientation(i));
|
||||
this.onReceiveLiquid(this.type, gainedVolume, ForgeDirection.getOrientation(i));
|
||||
if(((ILiquidProducer)connectedBlocks[i]).canProduceLiquid(this.type,ForgeDirection.getOrientation(i)))
|
||||
{
|
||||
int gainedVolume = ((ILiquidProducer)connectedBlocks[i]).onProduceLiquid(this.type,this.capacity-this.liquidStored, ForgeDirection.getOrientation(i));
|
||||
this.onReceiveLiquid(this.type, gainedVolume, ForgeDirection.getOrientation(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,7 +52,8 @@ public class TileEntityRod extends TileEntity implements IPacketReceiver,IMechan
|
|||
this.pos = ((IMechanical)bb).getAnimationPos();
|
||||
}
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
{
|
||||
|
||||
if(ff instanceof IMechanical)
|
||||
{
|
||||
if(((IMechanical) ff).canInputSide(backDir))
|
||||
|
@ -62,17 +63,13 @@ public class TileEntityRod extends TileEntity implements IPacketReceiver,IMechan
|
|||
}
|
||||
if(bb instanceof IMechanical)
|
||||
{
|
||||
if(((IMechanical) bb).getForce() <= 0)
|
||||
{
|
||||
this.force = 0;
|
||||
}
|
||||
if(((IMechanical) bb).canOutputSide(frontDir))
|
||||
{
|
||||
this.force = ((IMechanical) bb).getForce();
|
||||
}
|
||||
}else
|
||||
{
|
||||
this.force = 0;
|
||||
this.force -=Math.max(force/10, 0);
|
||||
}
|
||||
aForce = Math.max(force - 10,0);
|
||||
Packet packet = PacketManager.getPacket(SteamPowerMain.channel,this, new Object[]{force,aForce});
|
||||
|
|
|
@ -34,27 +34,29 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements ILi
|
|||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
sList = TradeHelper.getSourounding(this);
|
||||
int bBlock = worldObj.getBlockId(xCoord, yCoord -1, zCoord);
|
||||
Liquid bellow = Liquid.getLiquidByBlock(bBlock);
|
||||
if(bellow != null && this.lStored <= 0)
|
||||
if(count++ >= 20)
|
||||
{
|
||||
this.type = bellow;
|
||||
}
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
count++;
|
||||
count = 0;
|
||||
sList = TradeHelper.getSourounding(this);
|
||||
int bBlock = worldObj.getBlockId(xCoord, yCoord -1, zCoord);
|
||||
Liquid bellow = Liquid.getLiquidByBlock(bBlock);
|
||||
|
||||
|
||||
if(bBlock == type.Still && this.eStored > 200 && this.lStored < this.wMax && count>=20)
|
||||
if(bellow != null && this.lStored <= 0)
|
||||
{
|
||||
eStored -= 200;
|
||||
lStored += 1;
|
||||
worldObj.setBlockAndMetadataWithNotify(xCoord, yCoord-1, zCoord, 0, 0);
|
||||
count = 0;
|
||||
this.type = bellow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -86,7 +86,7 @@ public class TileEntityMachine extends TileEntity implements IInventory, ISided
|
|||
{
|
||||
super.updateEntity();
|
||||
|
||||
if(count ++ >= 10 && !worldObj.isRemote)
|
||||
if(count ++ >= 20 && !worldObj.isRemote)
|
||||
{count = 0;
|
||||
Packet packet = PacketManager.getPacket(SteamPowerMain.channel,this, getSendData());
|
||||
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40);
|
||||
|
|
|
@ -36,22 +36,6 @@ public class RenderPipe extends TileEntitySpecialRenderer
|
|||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
|
||||
GL11.glScalef(1.0F, -1F, -1F);
|
||||
if(size == 4)
|
||||
{
|
||||
switch(type.ordinal())
|
||||
{
|
||||
case 0: bindTextureByName(BasicPipesMain.textureFile+"/pipes/SteamPipe.png");break;
|
||||
case 1: bindTextureByName(BasicPipesMain.textureFile+"/pipes/WaterPipe.png");break;
|
||||
default:bindTextureByName(BasicPipesMain.textureFile+"/pipes/DefaultPipe.png"); break;
|
||||
}
|
||||
if(tileEntity.connectedBlocks[0] != null) fourPipe.renderBottom();
|
||||
if(tileEntity.connectedBlocks[1] != null) fourPipe.renderTop();
|
||||
if(tileEntity.connectedBlocks[2] != null) fourPipe.renderFront();
|
||||
if(tileEntity.connectedBlocks[3] != null) fourPipe.renderBack();
|
||||
if(tileEntity.connectedBlocks[4] != null) fourPipe.renderRight();
|
||||
if(tileEntity.connectedBlocks[5] != null) fourPipe.renderLeft();
|
||||
fourPipe.renderMiddle();
|
||||
}
|
||||
if(size == 6)
|
||||
{
|
||||
switch(type.ordinal())
|
||||
|
@ -64,10 +48,10 @@ public class RenderPipe extends TileEntitySpecialRenderer
|
|||
}
|
||||
if(tileEntity.connectedBlocks[0] != null) SixPipe.renderBottom();
|
||||
if(tileEntity.connectedBlocks[1] != null) SixPipe.renderTop();
|
||||
if(tileEntity.connectedBlocks[2] != null) SixPipe.renderFront();
|
||||
if(tileEntity.connectedBlocks[3] != null) SixPipe.renderBack();
|
||||
if(tileEntity.connectedBlocks[4] != null) SixPipe.renderRight();
|
||||
if(tileEntity.connectedBlocks[5] != null) SixPipe.renderLeft();
|
||||
if(tileEntity.connectedBlocks[3] != null) SixPipe.renderFront();
|
||||
if(tileEntity.connectedBlocks[2] != null) SixPipe.renderBack();
|
||||
if(tileEntity.connectedBlocks[5] != null) SixPipe.renderRight();
|
||||
if(tileEntity.connectedBlocks[4] != null) SixPipe.renderLeft();
|
||||
SixPipe.renderMiddle();
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
|
|
Loading…
Reference in a new issue