From 31d9275c7a99efb9842b33e93c03c4026d1c3633 Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Tue, 17 Dec 2013 22:37:21 -0500 Subject: [PATCH] Fixed split energy calculations, fixed gas rendering --- .../network/PacketTransmitterUpdate.java | 15 ++++---- common/mekanism/common/util/ListUtils.java | 34 +++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/common/mekanism/common/network/PacketTransmitterUpdate.java b/common/mekanism/common/network/PacketTransmitterUpdate.java index a31f5f067..2f9d393f7 100644 --- a/common/mekanism/common/network/PacketTransmitterUpdate.java +++ b/common/mekanism/common/network/PacketTransmitterUpdate.java @@ -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)tileEntity).getTransmitterNetwork().gasStored = new GasStack(gasType, amount); - } - else { - if(((ITransmitter)tileEntity).getTransmitterNetwork().gasStored != null) - { - ((ITransmitter)tileEntity).getTransmitterNetwork().gasStored.amount = amount; - } + ((ITransmitter)tileEntity).getTransmitterNetwork().refGas = gasType; } + ((ITransmitter)tileEntity).getTransmitterNetwork().gasStored = stack; ((ITransmitter)tileEntity).getTransmitterNetwork().didTransfer = didGasTransfer; } } diff --git a/common/mekanism/common/util/ListUtils.java b/common/mekanism/common/util/ListUtils.java index 68efd47b3..c50e5784d 100644 --- a/common/mekanism/common/util/ListUtils.java +++ b/common/mekanism/common/util/ListUtils.java @@ -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; }