From 36ec4f5d31cb64f132876509b17fbaf83b9bcf25 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 21 Aug 2016 00:28:24 +1000 Subject: [PATCH] Fix error when undoing ancient MCForge .undo files. With this commit, fixes #204. --- Player/Undo/UndoFormatText.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Player/Undo/UndoFormatText.cs b/Player/Undo/UndoFormatText.cs index f207ccb3f..b6ae146eb 100644 --- a/Player/Undo/UndoFormatText.cs +++ b/Player/Undo/UndoFormatText.cs @@ -43,22 +43,23 @@ namespace MCGalaxy.Undo { DateTime start = args.Start; // because we have space to end of each entry, need to subtract one otherwise we'll start at a "". - for (int i = (lines.Length - 1) / 7; i >= 0; i--) { + const int items = 7; + for (int i = (lines.Length - 1) / items; i > 0; i--) { // line format: mapName x y z date oldblock newblock - string timeRaw = lines[(i * 7) - 3].Replace('&', ' '); + string timeRaw = lines[(i * items) - 3].Replace('&', ' '); pos.Time = DateTime.Parse(timeRaw, CultureInfo.InvariantCulture); if (pos.Time < start) { args.Stop = true; yield break; } - string map = lines[(i * 7) - 7]; + string map = lines[(i * items) - 7]; if (!super && !p.level.name.CaselessEq(map)) continue; pos.LevelName = map; - pos.X = Convert.ToUInt16(lines[(i * 7) - 6]); - pos.Y = Convert.ToUInt16(lines[(i * 7) - 5]); - pos.Z = Convert.ToUInt16(lines[(i * 7) - 4]); - - pos.NewBlock = Convert.ToByte(lines[(i * 7) - 1]); - pos.Block = Convert.ToByte(lines[(i * 7) - 2]); + pos.X = Convert.ToUInt16(lines[(i * items) - 6]); + pos.Y = Convert.ToUInt16(lines[(i * items) - 5]); + pos.Z = Convert.ToUInt16(lines[(i * items) - 4]); + + pos.Block = Convert.ToByte(lines[(i * items) - 2]); + pos.NewBlock = Convert.ToByte(lines[(i * items) - 1]); yield return pos; } }