From d55d4c954a3d00d1409928f7d7eb29bf3241a28e Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 7 Jan 2018 13:55:02 +1100 Subject: [PATCH] Don't error out when global block defs file is empty or has too few elements (Thanks Odd0002) --- MCGalaxy/Blocks/BlockDefinitions.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/MCGalaxy/Blocks/BlockDefinitions.cs b/MCGalaxy/Blocks/BlockDefinitions.cs index 2e1d44326..70166e0f9 100644 --- a/MCGalaxy/Blocks/BlockDefinitions.cs +++ b/MCGalaxy/Blocks/BlockDefinitions.cs @@ -73,7 +73,7 @@ namespace MCGalaxy { internal static BlockDefinition[] Load(bool global, Level lvl) { - BlockDefinition[] defs = new BlockDefinition[Block.Count]; + BlockDefinition[] defs = null; string path = global ? GlobalPath : "blockdefs/lvl_" + lvl.MapName + ".json"; try { if (File.Exists(path)) { @@ -82,7 +82,13 @@ namespace MCGalaxy { } } catch (Exception ex) { Logger.LogError(ex); - defs = new BlockDefinition[Block.Count]; + } + if (defs == null) defs = new BlockDefinition[Block.Count]; + + // File was probably manually modified - fix it up + if (defs.Length < Block.Count) { + Logger.Log(LogType.Warning, "Expected " + Block.Count + " blocks in " + path + ", but only had " + defs.Length); + Array.Resize(ref defs, Block.Count); } for (int i = 0; i < Block.Count; i++) {