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;
@ -174,6 +177,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)
{ {
@ -194,21 +200,15 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
else if(dumpLeft == GasMode.DUMPING) else if(dumpLeft == GasMode.DUMPING)
{ {
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)));
}
} }
} }
@ -231,23 +231,36 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
else if(dumpRight == GasMode.DUMPING) else if(dumpRight == GasMode.DUMPING)
{ {
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;
{
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getParticlePacket(1, new ArrayList())), new Range4D(Coord4D.get(this)));
}
} }
} }
if(clientDumpLeft != dumpedLeft || clientDumpRight != dumpedRight)
{
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);
}
} }
} }
@ -417,44 +430,37 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
} }
super.handlePacketData(dataStream); super.handlePacketData(dataStream);
int type = dataStream.readInt(); if(dataStream.readBoolean())
if(type == 0)
{ {
if(dataStream.readBoolean()) fluidTank.setFluid(new FluidStack(FluidRegistry.getFluid(dataStream.readInt()), dataStream.readInt()));
{
fluidTank.setFluid(new FluidStack(FluidRegistry.getFluid(dataStream.readInt()), dataStream.readInt()));
}
else {
fluidTank.setFluid(null);
}
if(dataStream.readBoolean())
{
leftTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt()));
}
else {
leftTank.setGas(null);
}
if(dataStream.readBoolean())
{
rightTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt()));
}
else {
rightTank.setGas(null);
}
dumpLeft = GasMode.values()[dataStream.readInt()];
dumpRight = GasMode.values()[dataStream.readInt()];
isActive = dataStream.readBoolean();
clientEnergyUsed = dataStream.readDouble();
} }
else if(type == 1) else {
fluidTank.setFluid(null);
}
if(dataStream.readBoolean())
{ {
spawnParticle(dataStream.readInt()); leftTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt()));
} }
else {
leftTank.setGas(null);
}
if(dataStream.readBoolean())
{
rightTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt()));
}
else {
rightTank.setGas(null);
}
dumpLeft = GasMode.values()[dataStream.readInt()];
dumpRight = GasMode.values()[dataStream.readInt()];
clientDumpLeft = dataStream.readBoolean();
clientDumpRight = dataStream.readBoolean();
isActive = dataStream.readBoolean();
clientEnergyUsed = dataStream.readDouble();
} }
@Override @Override
@ -462,8 +468,6 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
{ {
super.getNetworkedData(data); super.getNetworkedData(data);
data.add(0);
if(fluidTank.getFluid() != null) if(fluidTank.getFluid() != null)
{ {
data.add(true); data.add(true);
@ -496,21 +500,13 @@ 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)