diff --git a/src/common/basicpipes/conductors/BlockPipe.java b/src/common/basicpipes/conductors/BlockPipe.java index 499a01da..92131416 100644 --- a/src/common/basicpipes/conductors/BlockPipe.java +++ b/src/common/basicpipes/conductors/BlockPipe.java @@ -84,17 +84,13 @@ public class BlockPipe extends BlockContainer } public static void updateConductorTileEntity(World world, int x, int y, int z) { - for(int i = 0; i < 6; i++) { - //Update the tile entity on neighboring blocks TileEntity tileEntity = world.getBlockTileEntity(x, y, z); if(tileEntity instanceof TileEntityPipe) { - TileEntityPipe conductorTileEntity = (TileEntityPipe) tileEntity; - Liquid type = conductorTileEntity.getType(); - ForgeDirection side = ForgeDirection.getOrientation(i); - conductorTileEntity.addConnection(getLiquidUnit(world, x, y, z, side, type), side); + ((TileEntityPipe) tileEntity).addConnection(getLiquidUnit(world, x, y, z, + ForgeDirection.getOrientation(i), ((TileEntityPipe) tileEntity).getType()), ForgeDirection.getOrientation(i)); } } } @@ -107,6 +103,7 @@ public class BlockPipe extends BlockContainer @Override public void breakBlock(World world, int x, int y, int z,int par5, int par6) { + super.breakBlock(world, x, y, z, par5, par6); TileEntity ent = world.getBlockTileEntity(x, y, z); Random furnaceRand = new Random(); if(ent instanceof TileEntityPipe) diff --git a/src/common/basicpipes/conductors/ItemGuage.java b/src/common/basicpipes/conductors/ItemGuage.java index a1f56831..35902ad0 100644 --- a/src/common/basicpipes/conductors/ItemGuage.java +++ b/src/common/basicpipes/conductors/ItemGuage.java @@ -66,7 +66,9 @@ public class ItemGuage extends Item print = typeName +" " + steam +" @ "+pressure+"PSI"; - player.addChatMessage(print); + player.sendChatToPlayer(print); + player.sendChatToPlayer("hPre: "+pipeEntity.hPressure+" hPPre:"+pipeEntity.hPProducer); + player.sendChatToPlayer("cUnits: "+pipeEntity.connectedUnits); return true; } if(blockEntity instanceof IMechanical) @@ -78,7 +80,7 @@ public class ItemGuage extends Item print = " " + steam +"N "+pressure*45+"degrees"; - player.addChatMessage(print); + player.sendChatToPlayer(print); return true; } } diff --git a/src/common/basicpipes/conductors/TileEntityPipe.java b/src/common/basicpipes/conductors/TileEntityPipe.java index bcad3012..7703c118 100644 --- a/src/common/basicpipes/conductors/TileEntityPipe.java +++ b/src/common/basicpipes/conductors/TileEntityPipe.java @@ -16,20 +16,20 @@ import basicpipes.pipes.api.Liquid; import com.google.common.io.ByteArrayDataInput; public class TileEntityPipe extends TileEntity implements ILiquidConsumer,IPacketReceiver { - //The amount stored in the conductor - protected int liquidStored = 0; - //the current set type of the pipe 0-5 protected Liquid type = Liquid.DEFUALT; - //The maximum amount of electricity this conductor can take + public int capacity = 2; - public int hPressure = this.presure; private int count = 0; - private boolean intiUpdate = true; - //Stores information on all connected blocks around this tile entity - public TileEntity[] connectedBlocks = {null, null, null, null, null, null}; - //Checks if this is the first the tile entity updates - protected boolean firstUpdate = true; public int presure = 0; + public int connectedUnits = 0; + public int hPressure = 0; + public int hPProducer = 0; + protected int liquidStored = 0; + + private boolean intiUpdate = true; + protected boolean firstUpdate = true; + + public TileEntity[] connectedBlocks = {null, null, null, null, null, null}; /** * This function adds a connection between this pipe and other blocks * @param tileEntity - Must be either a producer, consumer or a conductor @@ -44,15 +44,19 @@ 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)) { - this.connectedBlocks[side.ordinal()] = tileEntity; + this.connectedBlocks[side.ordinal()] = tileEntity; } } } + public int getPressure() + { + return this.presure; + } /** * onRecieveLiquid is called whenever a something sends a volume to the pipe (which is this block). * @param vols - The amount of vol source is trying to give to this pipe @@ -73,72 +77,64 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer,IPacke @Override public void updateEntity() { - if(++count >= 10 || firstUpdate) - {count = 0;firstUpdate = false; + if(++count >= 5) + { + this.connectedUnits = 0; + this.hPressure = 0; + this.hPProducer = 0; + + count = 0; BlockPipe.updateConductorTileEntity(this.worldObj, this.xCoord, this.yCoord, this.zCoord); - 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; - + if(!this.worldObj.isRemote) + { + if(firstUpdate) + { firstUpdate = false; + Packet packet = PacketManager.getPacket("Pipes",this, new Object[]{this.type.ordinal()}); + PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 60); + } for(int i = 0; i < 6; i++) { - if(connectedBlocks[i] instanceof ILiquidConsumer || connectedBlocks[i] instanceof ILiquidProducer) + if(connectedBlocks[i] instanceof ILiquidProducer) { - connectedUnits ++; - if(connectedBlocks[i] instanceof ILiquidProducer) - { - if(((ILiquidProducer)connectedBlocks[i]).canProducePresure(this.type, ForgeDirection.getOrientation(i))) + + if(((ILiquidProducer)connectedBlocks[i]).canProducePresure(this.type, ForgeDirection.getOrientation(i))) + {++this.connectedUnits; + if(((ILiquidProducer)connectedBlocks[i]).presureOutput(this.type,ForgeDirection.getOrientation(i)) > hPProducer) { - 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; + hPProducer = ((ILiquidProducer)connectedBlocks[i]).presureOutput(this.type,ForgeDirection.getOrientation(i)); } } + } + if(connectedBlocks[i] instanceof TileEntityPipe) + { + ++this.connectedUnits; + if(((TileEntityPipe)connectedBlocks[i]).presure > hPressure) + { + hPressure = ((TileEntityPipe)connectedBlocks[i]).getPressure(); + } } - } - //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 + + }//end of pressure update + + this.presure = 0; if(connectedUnits > 0) { - this.presure = hPressure - 1; + if(hPProducer > 0) + { + this.presure = hPProducer; + }else + { + this.presure = Math.max(hPressure - 1,0); + } }else { - this.presure = 1; + this.presure = 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(this.connectedUnits > 0 && this.presure > 0 && this.liquidStored > 0) { - for(byte i = 0; i < 6; i++) + for(int i = 0; i < 6; i++) { if(connectedBlocks[i] != null) { @@ -175,9 +171,9 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer,IPacke } } } - } + }//end of liquid trader - } + }//end of !worldObj.isRemote } } diff --git a/src/common/basicpipes/conductors/TileEntityRod.java b/src/common/basicpipes/conductors/TileEntityRod.java index e660de2a..451903d4 100644 --- a/src/common/basicpipes/conductors/TileEntityRod.java +++ b/src/common/basicpipes/conductors/TileEntityRod.java @@ -18,6 +18,7 @@ public class TileEntityRod extends TileEntity implements IPacketReceiver,IMechan public int pos = 0; private int force = 0; + private int pForce = 0; public int aForce = 0; public int forceMax = 1000; private int tickCount = 0; @@ -72,8 +73,12 @@ public class TileEntityRod extends TileEntity implements IPacketReceiver,IMechan this.force -=Math.max(force/10, 0); } aForce = Math.max(force - 10,0); - Packet packet = PacketManager.getPacket(SteamPowerMain.channel,this, new Object[]{force,aForce}); - PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40); + if(this.force != this.pForce) + { + Packet packet = PacketManager.getPacket(SteamPowerMain.channel,this, new Object[]{force}); + PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40); + } + this.pForce = this.force; } } } @@ -113,7 +118,6 @@ public class TileEntityRod extends TileEntity implements IPacketReceiver,IMechan try { this.force = dataStream.readInt(); - this.aForce = dataStream.readInt(); }catch(Exception e) { e.printStackTrace(); diff --git a/src/common/steampower/TileEntityMachine.java b/src/common/steampower/TileEntityMachine.java index 651d1409..bb825a75 100644 --- a/src/common/steampower/TileEntityMachine.java +++ b/src/common/steampower/TileEntityMachine.java @@ -82,11 +82,15 @@ public class TileEntityMachine extends TileEntity implements IInventory, ISided { return new Object[]{}; } + public boolean needUpdate() + { + return false; + } public void updateEntity() { super.updateEntity(); - if(count ++ >= 20 && !worldObj.isRemote) + if(count ++ >= 10 && !worldObj.isRemote && needUpdate()) {count = 0; Packet packet = PacketManager.getPacket(SteamPowerMain.channel,this, getSendData()); PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40); diff --git a/src/common/steampower/boiler/TileEntityBoiler.java b/src/common/steampower/boiler/TileEntityBoiler.java index 125a22e9..bb22ac7a 100644 --- a/src/common/steampower/boiler/TileEntityBoiler.java +++ b/src/common/steampower/boiler/TileEntityBoiler.java @@ -32,8 +32,6 @@ public class TileEntityBoiler extends TileEntityMachine implements IPacketReceiv /** The number of ticks that the boiler will keep burning */ public int RunTime = 0; - /** The ammount of energy stored before being add to run Timer */ - public int energyStore = 0; /** The ammount of water stored */ public int waterStored = 0; /** The ammount of steam stored */ @@ -53,13 +51,16 @@ public class TileEntityBoiler extends TileEntityMachine implements IPacketReceiv int steamMax = 140; public boolean isBeingHeated = false; private Random random = new Random(); + private int pWater = 0; + private int pSteam = 0; + private int pHullH = 0; public String getInvName() { return "container.boiler"; } public Object[] getSendData() { - return new Object[]{(int)RunTime,(int)energyStore,(int)waterStored, + return new Object[]{(int)RunTime,(int)waterStored, (int)steamStored,(int)heatStored,(int)hullHeat,(int)heatTick}; } @@ -71,7 +72,6 @@ public class TileEntityBoiler extends TileEntityMachine implements IPacketReceiv { RunTime = dataStream.readInt(); - energyStore = dataStream.readInt(); waterStored = dataStream.readInt(); steamStored = dataStream.readInt(); heatStored = dataStream.readInt(); @@ -91,7 +91,6 @@ public class TileEntityBoiler extends TileEntityMachine implements IPacketReceiv { super.readFromNBT(par1NBTTagCompound); this.RunTime = par1NBTTagCompound.getShort("BurnTime"); - this.energyStore = par1NBTTagCompound.getInteger("energyStore"); this.steamStored = par1NBTTagCompound.getInteger("steamStore"); this.heatStored = par1NBTTagCompound.getInteger("heatStore"); this.waterStored = par1NBTTagCompound.getInteger("waterStore"); @@ -105,7 +104,6 @@ public class TileEntityBoiler extends TileEntityMachine implements IPacketReceiv { super.writeToNBT(par1NBTTagCompound); par1NBTTagCompound.setShort("BurnTime", (short)this.RunTime); - par1NBTTagCompound.setInteger("energyStore", (int)this.energyStore); par1NBTTagCompound.setInteger("steamStore", (int)this.steamStored); par1NBTTagCompound.setInteger("heatStore", (int)this.heatStored); par1NBTTagCompound.setInteger("waterStore", (int)this.waterStored); @@ -115,10 +113,19 @@ public class TileEntityBoiler extends TileEntityMachine implements IPacketReceiv /** * Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner uses this to count * ticks and creates a new spawn inside its implementation. - */ + */ + public boolean needUpdate() + { + if(this.pWater != this.waterStored || this.pSteam != this.steamStored || this.pHullH != this.hullHeat) + { + return true; + } + return false; + } @Override public void updateEntity() { + super.updateEntity(); if(count++ >=20) { count = 0; @@ -183,8 +190,12 @@ public class TileEntityBoiler extends TileEntityMachine implements IPacketReceiv { heatStored += (int) Math.min((int)(random.nextDouble()*100), heatMax); } + //keeps track of what the previous measure were so packets stop sending after the machine doesn't change any + this.pWater = this.waterStored; + this.pSteam = this.steamStored; + this.pHullH = this.hullHeat; } - super.updateEntity(); + } } private void emptyBuckets() @@ -309,15 +320,7 @@ public class TileEntityBoiler extends TileEntityMachine implements IPacketReceiv public int presureOutput(Liquid type, ForgeDirection side) { if(type == Liquid.STEAM) { - if(side == ForgeDirection.UP) - { - return 100; - } - else - { - return 80; - } - + return (this.steamStored/this.steamMax)*40 +60; } return 0; } diff --git a/src/common/steampower/burner/TileEntityFireBox.java b/src/common/steampower/burner/TileEntityFireBox.java index 1a5da835..ee556fdb 100644 --- a/src/common/steampower/burner/TileEntityFireBox.java +++ b/src/common/steampower/burner/TileEntityFireBox.java @@ -40,6 +40,10 @@ public class TileEntityFireBox extends TileEntityMachine implements IPacketRecei return 5; } + public boolean needUpdate() + { + return true; + } public void updateEntity() { super.updateEntity(); diff --git a/src/common/steampower/turbine/TileEntityGen.java b/src/common/steampower/turbine/TileEntityGen.java index a0d3a24c..7e04f857 100644 --- a/src/common/steampower/turbine/TileEntityGen.java +++ b/src/common/steampower/turbine/TileEntityGen.java @@ -28,7 +28,10 @@ public class TileEntityGen extends TileEntityMachine implements IPacketReceiver, public boolean empProf = false; IConductor[] wires = {null,null,null,null,null,null}; - + public boolean needUpdate() + { + return false; + } @Override public void updateEntity() { diff --git a/src/common/steampower/turbine/TileEntitySteamPiston.java b/src/common/steampower/turbine/TileEntitySteamPiston.java index 1caf8116..74f6d286 100644 --- a/src/common/steampower/turbine/TileEntitySteamPiston.java +++ b/src/common/steampower/turbine/TileEntitySteamPiston.java @@ -41,7 +41,10 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR private ForgeDirection frontDir; public TileEntity ff; public TileEntity bb; - + private int pWater = 0; + private int pSteam = 0; + private int pForce = 0; + public int pCount = 0; public boolean running= false; @Override @@ -51,7 +54,7 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR if(tickCount++ >=10) {tickCount = 0; - ++tCount;if(tCount > 120){tCount = 0;} + //++tCount;if(tCount > 120){tCount = 0;} int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); int nMeta = 0; @@ -130,7 +133,9 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR } } - + pWater = this.water; + pSteam = this.steam; + pForce = this.force; } @@ -260,7 +265,15 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR //---------------- public Object[] getSendData() { - return new Object[]{steam,water,force,aForce,bForce,genRate,runTime}; + return new Object[]{steam,water,force,aForce,genRate,runTime}; + } + public boolean needUpdate() + { + if(this.pForce != this.force || this.pWater != this.water || this.pSteam != this.steam) + { + return true; + } + return false; } @Override public void handlePacketData(NetworkManager network,Packet250CustomPayload packet, EntityPlayer player,ByteArrayDataInput dataStream) { @@ -270,10 +283,9 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR this.water = dataStream.readInt(); this.force = dataStream.readInt(); this.aForce = dataStream.readInt(); - this.bForce = dataStream.readInt(); this.genRate= dataStream.readInt(); this.runTime = dataStream.readInt(); - //System.out.print("Packet \n"); + ++pCount; } catch(Exception e) { diff --git a/src/minecraft/steampower/GUISteamPiston.java b/src/minecraft/steampower/GUISteamPiston.java index 339e94cd..3d220089 100644 --- a/src/minecraft/steampower/GUISteamPiston.java +++ b/src/minecraft/steampower/GUISteamPiston.java @@ -61,14 +61,14 @@ import universalelectricity.electricity.ElectricInfo.ElectricUnit; displayText2 = "water" + "-" + tileEntity.water; displayText3 = "steam" + "-" + tileEntity.steam; - displayText4 = "Debug:Time" + "=" + tileEntity.tCount; - displayText5 = "Debug:bforce" + "=" + tileEntity.bForce; + displayText4 = "Db:PacketsReceived " + "=" + tileEntity.pCount; + //displayText5 = "Debug:bforce" + "=" + tileEntity.bForce; this.fontRenderer.drawString(displayText, (int)(105-displayText.length()*1), 45, 4210752); this.fontRenderer.drawString(displayText2, (int)(105-displayText.length()*1), 55, 4210752); this.fontRenderer.drawString(displayText3, (int)(105-displayText.length()*1), 65, 4210752); this.fontRenderer.drawString(displayText4, (int)(105-displayText.length()*1), 75, 4210752); - this.fontRenderer.drawString(displayText5, (int)(105-displayText.length()*1), 85, 4210752); + // this.fontRenderer.drawString(displayText5, (int)(105-displayText.length()*1), 85, 4210752); this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752); }