Electrolytic Separators are now super server friendly

This commit is contained in:
aidancbrady 2015-06-17 16:29:25 -04:00
parent 43b71cb8cc
commit 13f27b6732

View file

@ -77,6 +77,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
/** Type type of gas this block is dumping. */ /** Type type of gas this block is dumping. */
public GasMode dumpRight = GasMode.IDLE; public GasMode dumpRight = GasMode.IDLE;
public boolean clientDumpLeft = false;
public boolean clientDumpRight = false;
public double BASE_ENERGY_USAGE; public double BASE_ENERGY_USAGE;
public double energyPerTick; public double energyPerTick;
@ -175,6 +178,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
int dumpAmount = 8*(int)Math.pow(2, upgradeComponent.getUpgrades(Upgrade.SPEED)); int dumpAmount = 8*(int)Math.pow(2, upgradeComponent.getUpgrades(Upgrade.SPEED));
boolean dumpedLeft = false;
boolean dumpedRight = false;
if(leftTank.getGas() != null) if(leftTank.getGas() != null)
{ {
if(dumpLeft != GasMode.DUMPING) if(dumpLeft != GasMode.DUMPING)
@ -195,20 +201,14 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
{ {
leftTank.draw(dumpAmount, true); leftTank.draw(dumpAmount, true);
if(worldObj.rand.nextInt(3) == 2) dumpedLeft = true;
{
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getParticlePacket(0, new ArrayList())), new Range4D(Coord4D.get(this)));
}
} }
if(dumpLeft == GasMode.DUMPING_EXCESS && leftTank.getNeeded() < output) if(dumpLeft == GasMode.DUMPING_EXCESS && leftTank.getNeeded() < output)
{ {
leftTank.draw(output-leftTank.getNeeded(), true); leftTank.draw(output-leftTank.getNeeded(), true);
if(worldObj.rand.nextInt(3) == 2) dumpedLeft = true;
{
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getParticlePacket(0, new ArrayList())), new Range4D(Coord4D.get(this)));
}
} }
} }
@ -232,21 +232,34 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
{ {
rightTank.draw(dumpAmount, true); rightTank.draw(dumpAmount, true);
if(worldObj.rand.nextInt(3) == 2) dumpedRight = true;
{
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getParticlePacket(1, new ArrayList())), new Range4D(Coord4D.get(this)));
}
} }
if(dumpRight == GasMode.DUMPING_EXCESS && rightTank.getNeeded() < output) if(dumpRight == GasMode.DUMPING_EXCESS && rightTank.getNeeded() < output)
{ {
rightTank.draw(output-rightTank.getNeeded(), true); rightTank.draw(output-rightTank.getNeeded(), true);
if(worldObj.rand.nextInt(3) == 2) dumpedRight = true;
}
}
if(clientDumpLeft != dumpedLeft || clientDumpRight != dumpedRight)
{ {
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getParticlePacket(1, new ArrayList())), new Range4D(Coord4D.get(this))); clientDumpLeft = dumpedLeft;
clientDumpRight = dumpedRight;
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this)));
} }
} }
else {
if(clientDumpLeft)
{
spawnParticle(0);
}
if(clientDumpRight)
{
spawnParticle(1);
} }
} }
} }
@ -418,10 +431,6 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
super.handlePacketData(dataStream); super.handlePacketData(dataStream);
int type = dataStream.readInt();
if(type == 0)
{
if(dataStream.readBoolean()) if(dataStream.readBoolean())
{ {
fluidTank.setFluid(new FluidStack(FluidRegistry.getFluid(dataStream.readInt()), dataStream.readInt())); fluidTank.setFluid(new FluidStack(FluidRegistry.getFluid(dataStream.readInt()), dataStream.readInt()));
@ -448,22 +457,17 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
dumpLeft = GasMode.values()[dataStream.readInt()]; dumpLeft = GasMode.values()[dataStream.readInt()];
dumpRight = GasMode.values()[dataStream.readInt()]; dumpRight = GasMode.values()[dataStream.readInt()];
clientDumpLeft = dataStream.readBoolean();
clientDumpRight = dataStream.readBoolean();
isActive = dataStream.readBoolean(); isActive = dataStream.readBoolean();
clientEnergyUsed = dataStream.readDouble(); clientEnergyUsed = dataStream.readDouble();
} }
else if(type == 1)
{
spawnParticle(dataStream.readInt());
}
}
@Override @Override
public ArrayList getNetworkedData(ArrayList data) public ArrayList getNetworkedData(ArrayList data)
{ {
super.getNetworkedData(data); super.getNetworkedData(data);
data.add(0);
if(fluidTank.getFluid() != null) if(fluidTank.getFluid() != null)
{ {
data.add(true); data.add(true);
@ -496,22 +500,14 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
data.add(dumpLeft.ordinal()); data.add(dumpLeft.ordinal());
data.add(dumpRight.ordinal()); data.add(dumpRight.ordinal());
data.add(clientDumpLeft);
data.add(clientDumpRight);
data.add(isActive); data.add(isActive);
data.add(clientEnergyUsed); data.add(clientEnergyUsed);
return data; return data;
} }
public ArrayList getParticlePacket(int type, ArrayList data)
{
super.getNetworkedData(data);
data.add(1);
data.add(type);
return data;
}
@Override @Override
public boolean canSetFacing(int side) public boolean canSetFacing(int side)
{ {