Fixed split energy calculations, fixed gas rendering

This commit is contained in:
Aidan Brady 2013-12-17 22:37:21 -05:00
parent 4d84386b8e
commit 31d9275c7a
2 changed files with 42 additions and 7 deletions

View file

@ -97,21 +97,22 @@ public class PacketTransmitterUpdate implements IMekanismPacket
Gas gasType = GasRegistry.getGas(dataStream.readInt());
int amount = dataStream.readInt();
GasStack stack = null;
didGasTransfer = dataStream.readBoolean();
if(gasType != null)
{
stack = new GasStack(gasType, amount);
}
if(tileEntity != null)
{
if(gasType != null)
{
((ITransmitter<GasNetwork>)tileEntity).getTransmitterNetwork().gasStored = new GasStack(gasType, amount);
}
else {
if(((ITransmitter<GasNetwork>)tileEntity).getTransmitterNetwork().gasStored != null)
{
((ITransmitter<GasNetwork>)tileEntity).getTransmitterNetwork().gasStored.amount = amount;
}
((ITransmitter<GasNetwork>)tileEntity).getTransmitterNetwork().refGas = gasType;
}
((ITransmitter<GasNetwork>)tileEntity).getTransmitterNetwork().gasStored = stack;
((ITransmitter<GasNetwork>)tileEntity).getTransmitterNetwork().didTransfer = didGasTransfer;
}
}

View file

@ -211,6 +211,40 @@ public class ListUtils
ret[i] = (int)Math.round(val*percent[i]);
}
int newTotal = 0;
for(int i : ret) newTotal += i;
int diff = val-newTotal;
if(diff != val)
{
for(int i = 0; i < ret.length; i++)
{
int num = ret[i];
if(diff < 0 && num == 0)
{
continue;
}
if(diff > 0)
{
ret[i]++;
diff--;
}
else if(diff < 0)
{
ret[i]--;
diff++;
}
if(diff == 0)
{
return ret;
}
}
}
return ret;
}