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:
Rseifert 2012-10-07 23:58:49 -04:00
parent 5d2450a061
commit 89e5ca315b
6 changed files with 127 additions and 142 deletions

View file

@ -37,17 +37,15 @@ public class BlockPipe extends BlockContainer
super.onBlockAdded(world, x, y, z); super.onBlockAdded(world, x, y, z);
this.updateConductorTileEntity(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 //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; TileEntity returnValue = null;
if(tileEntity instanceof ILiquidConsumer) if(tileEntity instanceof ILiquidConsumer)
{ {
if(((ILiquidConsumer)tileEntity).canRecieveLiquid(type,ForgeDirection.getOrientation(side))) if(((ILiquidConsumer)tileEntity).canRecieveLiquid(type,side))
{ {
returnValue = tileEntity; returnValue = tileEntity;
} }
@ -55,7 +53,7 @@ public class BlockPipe extends BlockContainer
if (tileEntity instanceof ILiquidProducer) if (tileEntity instanceof ILiquidProducer)
{ {
if(((ILiquidProducer)tileEntity).canProduceLiquid(type,ForgeDirection.getOrientation(side))) if(((ILiquidProducer)tileEntity).canProduceLiquid(type,side))
{ {
returnValue = tileEntity; returnValue = tileEntity;
} }
@ -95,7 +93,8 @@ public class BlockPipe extends BlockContainer
{ {
TileEntityPipe conductorTileEntity = (TileEntityPipe) tileEntity; TileEntityPipe conductorTileEntity = (TileEntityPipe) tileEntity;
Liquid type = conductorTileEntity.getType(); 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);
} }
} }
} }

View file

@ -44,7 +44,7 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer,IPacke
{ {
this.connectedBlocks[side.ordinal()] = tileEntity; this.connectedBlocks[side.ordinal()] = tileEntity;
} }
} }else
if(tileEntity instanceof ILiquidProducer) if(tileEntity instanceof ILiquidProducer)
{ {
if(((ILiquidProducer)tileEntity).canProduceLiquid(this.type, side)) if(((ILiquidProducer)tileEntity).canProduceLiquid(this.type, side))
@ -72,110 +72,113 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer,IPacke
} }
@Override @Override
public void updateEntity() public void updateEntity()
{ {
if(++count >= 5 && !this.worldObj.isRemote) if(++count >= 10 || firstUpdate)
{count = 0; {count = 0;firstUpdate = false;
//update connections
BlockPipe.updateConductorTileEntity(this.worldObj, this.xCoord, this.yCoord, this.zCoord); BlockPipe.updateConductorTileEntity(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
//send packet with liquid type data if(!this.worldObj.isRemote){
Packet packet = PacketManager.getPacket("Pipes",this, new Object[]{this.type.ordinal()}); //update connections
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40);
//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 connectedUnits = 0; int pipes = 1;
int pipes = 1; int producers = 0;
int producers = 0; int averageVolume = this.liquidStored;
int averageVolume = this.liquidStored; int aProducerPressure = 0;
int aProducerPressure = 0;
for(int i = 0; i < 6; i++)
for(int i = 0; i < 6; i++) {
{ if(connectedBlocks[i] instanceof ILiquidConsumer || connectedBlocks[i] instanceof ILiquidProducer)
if(connectedBlocks[i] instanceof ILiquidConsumer || connectedBlocks[i] instanceof ILiquidProducer)
{
connectedUnits ++;
if(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)); if(((ILiquidProducer)connectedBlocks[i]).canProducePresure(this.type, ForgeDirection.getOrientation(i)))
producers++; {
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) //turn average collection into actual average pipe volume
{ averageVolume = Math.max(averageVolume/pipes,0);
pipes ++; //sets the pressure of the pipe to the producer pressure or to the highest pipe pressure -1
//add pipes volume to average collection value if(producers > 0)
averageVolume += ((TileEntityPipe)connectedBlocks[i]).liquidStored; {
//get the current pipes pressure aProducerPressure = Math.max(aProducerPressure/producers,0);
int pPressure = ((TileEntityPipe)connectedBlocks[i]).presure ; this.presure = aProducerPressure;
if(pPressure > hPressure)
{
this.hPressure = pPressure;
}
}
} }
} else
//turn average collection into actual average pipe volume if(connectedUnits > 0)
averageVolume = Math.max(averageVolume/pipes,0); {
//sets the pressure of the pipe to the producer pressure or to the highest pipe pressure -1 this.presure = hPressure - 1;
if(producers > 0) }else
{ {
aProducerPressure = Math.max(aProducerPressure/producers,0); this.presure = 1;
this.presure = aProducerPressure; }
} //only trade liquid if there is more than one thing connect and its pressure is higher than 1
else if(connectedUnits > 0 && this.presure > 0)
if(connectedUnits > 0) {
{ for(byte i = 0; i < 6; i++)
this.presure = hPressure - 1; {
}else if(connectedBlocks[i] != null)
{ {
this.presure = 1; //Spread the liquid among the different blocks
} if(connectedBlocks[i] instanceof ILiquidConsumer && this.liquidStored > 0)
//only trade liquid if there is more than one thing connect and its pressure is higher than 1 {
if(connectedUnits > 0 && this.presure > 0) if(((ILiquidConsumer)connectedBlocks[i]).canRecieveLiquid(this.type,ForgeDirection.getOrientation(i)))
{
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)
{ {
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; 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 }
{ if(connectedBlocks[i] instanceof ILiquidProducer && this.liquidStored < this.getLiquidCapacity(type))
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)))
{ {
int gainedVolume = ((ILiquidProducer)connectedBlocks[i]).onProduceLiquid(this.type,this.capacity-this.liquidStored, ForgeDirection.getOrientation(i)); if(((ILiquidProducer)connectedBlocks[i]).canProduceLiquid(this.type,ForgeDirection.getOrientation(i)))
this.onReceiveLiquid(this.type, gainedVolume, 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));
}
} }
} }
} }
} }
}
}
} }
} }
/** /**

View file

@ -52,7 +52,8 @@ public class TileEntityRod extends TileEntity implements IPacketReceiver,IMechan
this.pos = ((IMechanical)bb).getAnimationPos(); this.pos = ((IMechanical)bb).getAnimationPos();
} }
if(!worldObj.isRemote) if(!worldObj.isRemote)
{ {
if(ff instanceof IMechanical) if(ff instanceof IMechanical)
{ {
if(((IMechanical) ff).canInputSide(backDir)) if(((IMechanical) ff).canInputSide(backDir))
@ -62,17 +63,13 @@ public class TileEntityRod extends TileEntity implements IPacketReceiver,IMechan
} }
if(bb instanceof IMechanical) if(bb instanceof IMechanical)
{ {
if(((IMechanical) bb).getForce() <= 0)
{
this.force = 0;
}
if(((IMechanical) bb).canOutputSide(frontDir)) if(((IMechanical) bb).canOutputSide(frontDir))
{ {
this.force = ((IMechanical) bb).getForce(); this.force = ((IMechanical) bb).getForce();
} }
}else }else
{ {
this.force = 0; this.force -=Math.max(force/10, 0);
} }
aForce = Math.max(force - 10,0); aForce = Math.max(force - 10,0);
Packet packet = PacketManager.getPacket(SteamPowerMain.channel,this, new Object[]{force,aForce}); Packet packet = PacketManager.getPacket(SteamPowerMain.channel,this, new Object[]{force,aForce});

View file

@ -34,27 +34,29 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements ILi
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
sList = TradeHelper.getSourounding(this); if(count++ >= 20)
int bBlock = worldObj.getBlockId(xCoord, yCoord -1, zCoord);
Liquid bellow = Liquid.getLiquidByBlock(bBlock);
if(bellow != null && this.lStored <= 0)
{ {
this.type = bellow; count = 0;
} sList = TradeHelper.getSourounding(this);
if(!worldObj.isRemote) int bBlock = worldObj.getBlockId(xCoord, yCoord -1, zCoord);
{ Liquid bellow = Liquid.getLiquidByBlock(bBlock);
count++;
if(bellow != null && this.lStored <= 0)
if(bBlock == type.Still && this.eStored > 200 && this.lStored < this.wMax && count>=20)
{ {
eStored -= 200; this.type = bellow;
lStored += 1;
worldObj.setBlockAndMetadataWithNotify(xCoord, yCoord-1, zCoord, 0, 0);
count = 0;
} }
}
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 @Override

View file

@ -86,7 +86,7 @@ public class TileEntityMachine extends TileEntity implements IInventory, ISided
{ {
super.updateEntity(); super.updateEntity();
if(count ++ >= 10 && !worldObj.isRemote) if(count ++ >= 20 && !worldObj.isRemote)
{count = 0; {count = 0;
Packet packet = PacketManager.getPacket(SteamPowerMain.channel,this, getSendData()); Packet packet = PacketManager.getPacket(SteamPowerMain.channel,this, getSendData());
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40); PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40);

View file

@ -36,22 +36,6 @@ public class RenderPipe extends TileEntitySpecialRenderer
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F); GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
GL11.glScalef(1.0F, -1F, -1F); 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) if(size == 6)
{ {
switch(type.ordinal()) switch(type.ordinal())
@ -64,10 +48,10 @@ public class RenderPipe extends TileEntitySpecialRenderer
} }
if(tileEntity.connectedBlocks[0] != null) SixPipe.renderBottom(); if(tileEntity.connectedBlocks[0] != null) SixPipe.renderBottom();
if(tileEntity.connectedBlocks[1] != null) SixPipe.renderTop(); if(tileEntity.connectedBlocks[1] != null) SixPipe.renderTop();
if(tileEntity.connectedBlocks[2] != null) SixPipe.renderFront(); if(tileEntity.connectedBlocks[3] != null) SixPipe.renderFront();
if(tileEntity.connectedBlocks[3] != null) SixPipe.renderBack(); if(tileEntity.connectedBlocks[2] != null) SixPipe.renderBack();
if(tileEntity.connectedBlocks[4] != null) SixPipe.renderRight(); if(tileEntity.connectedBlocks[5] != null) SixPipe.renderRight();
if(tileEntity.connectedBlocks[5] != null) SixPipe.renderLeft(); if(tileEntity.connectedBlocks[4] != null) SixPipe.renderLeft();
SixPipe.renderMiddle(); SixPipe.renderMiddle();
} }
GL11.glPopMatrix(); GL11.glPopMatrix();