public void TransferTo(LiquidContainer target, int amount) { if (target == null) { Logger.Error("Receiving LiquidContainer was null"); return; } if (amount == 0) { return; } if (amount < 0) { target.TransferTo(this, -amount); return; } int receiveCapacity = target.GetReceiveCapacity(); int canSend = Math.Min(Amount, amount); int toTransfer = Math.Min(canSend, receiveCapacity); SetAmount(Amount - toTransfer); target.SetAmount(target.Amount + toTransfer); }