diff --git a/GUI/PropertyWindow/PropertyWindow.Blocks.cs b/GUI/PropertyWindow/PropertyWindow.Blocks.cs index 463c33896..5059f2fd2 100644 --- a/GUI/PropertyWindow/PropertyWindow.Blocks.cs +++ b/GUI/PropertyWindow/PropertyWindow.Blocks.cs @@ -63,7 +63,7 @@ namespace MCGalaxy.Gui { } } - BlockProps.Save("core", Block.Props, true); + BlockProps.Save("core", Block.Props, i => true); BlockPerms.Save(); Block.SetBlocks(); LoadBlocks(); diff --git a/MCGalaxy/Blocks/BlockProperties.cs b/MCGalaxy/Blocks/BlockProperties.cs index e072f2d00..cb2f7f683 100644 --- a/MCGalaxy/Blocks/BlockProperties.cs +++ b/MCGalaxy/Blocks/BlockProperties.cs @@ -77,7 +77,7 @@ namespace MCGalaxy.Blocks { } - public static void Save(string group, BlockProps[] scope, bool custom) { + public static void Save(string group, BlockProps[] scope, Predicate selector) { if (!Directory.Exists("blockprops")) Directory.CreateDirectory("blockprops"); @@ -86,11 +86,8 @@ namespace MCGalaxy.Blocks { w.WriteLine("# id : Is rails : Is tdoor : Is door : Is message block : Is portal : " + "Killed by water : Killed by lava : Kills players : death message : Animal AI type"); for (int i = 0; i < scope.Length; i++) { - if (!scope[i].Changed) continue; + if (!scope[i].Changed || !selector(i)) continue; BlockProps props = scope[i]; - - // Don't save physics blocks - if (custom && (i > Block.CpeCount && i < Block.Count)) continue; // Convert ext to raw ids int id = i >= Block.Count ? (i - Block.Count) : i; @@ -121,7 +118,7 @@ namespace MCGalaxy.Blocks { byte raw; if (!Byte.TryParse(parts[0], out raw)) { Server.s.Log("Invalid line \"" + line + "\" in " + group + " block properties"); - continue; + continue; } int idx = raw; if (custom && raw >= Block.CpeCount) idx += Block.Count; diff --git a/MCGalaxy/Blocks/ExtBlock.cs b/MCGalaxy/Blocks/ExtBlock.cs index 3a6fe6861..7031fc106 100644 --- a/MCGalaxy/Blocks/ExtBlock.cs +++ b/MCGalaxy/Blocks/ExtBlock.cs @@ -66,6 +66,12 @@ namespace MCGalaxy { return new ExtBlock(Block.custom_block, raw); } + public static ExtBlock FromIndex(int index) { + if (index < Block.Count) + return new ExtBlock((byte)index, 0); + return new ExtBlock(Block.custom_block, (byte)(index - Block.Count)); + } + /// Constructs an extended block. public static explicit operator ExtBlock(byte block) { return new ExtBlock(block, 0); } diff --git a/MCGalaxy/Commands/World/CmdBlockProperties.cs b/MCGalaxy/Commands/World/CmdBlockProperties.cs index c4d5749e6..72febb4e1 100644 --- a/MCGalaxy/Commands/World/CmdBlockProperties.cs +++ b/MCGalaxy/Commands/World/CmdBlockProperties.cs @@ -176,7 +176,7 @@ namespace MCGalaxy.Commands.World { scope[block.Index].Changed = true; if (scope == Block.Props) { - BlockProps.Save("core", scope, true); + BlockProps.Save("core", scope, i=> true); Level[] loaded = LevelInfo.Loaded.Items; foreach (Level lvl in loaded) { @@ -185,7 +185,7 @@ namespace MCGalaxy.Commands.World { } } else if (scope == BlockDefinition.GlobalProps) { Level[] loaded = LevelInfo.Loaded.Items; - BlockProps.Save("global", scope, false); + BlockProps.Save("global", scope, SelectGlobal); byte raw = block.RawID; foreach (Level lvl in loaded) { @@ -194,11 +194,22 @@ namespace MCGalaxy.Commands.World { lvl.SetBlockHandler(block); } } else { - BlockProps.Save("lvl_" + level.name, scope, false); + BlockProps.Save("lvl_" + level.name, scope, i => SelectLevel(level, i)); level.SetBlockHandler(block); } } + static bool SelectGlobal(int i) { + ExtBlock block = ExtBlock.FromIndex(i); + return !block.IsPhysicsType && BlockDefinition.GlobalDefs[block.RawID] != null; + } + + static bool SelectLevel(Level lvl, int i) { + ExtBlock block = ExtBlock.FromIndex(i); + return !block.IsPhysicsType && + lvl.CustomBlockDefs[block.RawID] != BlockDefinition.GlobalDefs[block.RawID]; + } + static string BlockName(BlockProps[] scope, Level lvl, ExtBlock block) { if (scope == Block.Props) return Block.Name(block.RawID); BlockDefinition def = null; diff --git a/MCGalaxy/Commands/building/CmdMessageBlock.cs b/MCGalaxy/Commands/building/CmdMessageBlock.cs index 7f89b337b..bbf033579 100644 --- a/MCGalaxy/Commands/building/CmdMessageBlock.cs +++ b/MCGalaxy/Commands/building/CmdMessageBlock.cs @@ -205,7 +205,7 @@ namespace MCGalaxy.Commands.Building { static void GetCoreNames(List names, Level lvl) { BlockProps[] props = lvl == null ? lvl.BlockProps : Block.Props; for (int i = Block.air; i < Block.Count; i++) { - ExtBlock block = new ExtBlock((byte)i, 0); + ExtBlock block = ExtBlock.FromIndex(i); if (block.BlockID == Block.custom_block) continue; string name = Format(block, lvl, props); diff --git a/MCGalaxy/Commands/building/CmdPortal.cs b/MCGalaxy/Commands/building/CmdPortal.cs index 362ffec49..f62abc795 100644 --- a/MCGalaxy/Commands/building/CmdPortal.cs +++ b/MCGalaxy/Commands/building/CmdPortal.cs @@ -207,7 +207,7 @@ namespace MCGalaxy.Commands.Building { static void GetCoreNames(List names, Level lvl) { BlockProps[] props = lvl == null ? lvl.BlockProps : Block.Props; for (int i = Block.air; i < Block.Count; i++) { - ExtBlock block = new ExtBlock((byte)i, 0); + ExtBlock block = ExtBlock.FromIndex(i); if (block.BlockID == Block.custom_block) continue; string name = Format(block, lvl, props); diff --git a/MCGalaxy/Levels/Level.cs b/MCGalaxy/Levels/Level.cs index 79beca082..cc8929612 100644 --- a/MCGalaxy/Levels/Level.cs +++ b/MCGalaxy/Levels/Level.cs @@ -504,9 +504,8 @@ namespace MCGalaxy { } public void SetBlockHandlers() { - for (int i = 0; i < Block.Count; i++) { - SetBlockHandler(new ExtBlock((byte)i, 0)); - SetBlockHandler(new ExtBlock(Block.custom_block, (byte)i)); + for (int i = 0; i < BlockProps.Length; i++) { + SetBlockHandler(ExtBlock.FromIndex(i)); } } @@ -515,7 +514,7 @@ namespace MCGalaxy { if (GetBlockDef(block) == null) { nonSolid = Block.Walkthrough(Block.Convert(block.BlockID)); } else { - nonSolid = CustomBlockDefs[block.BlockID].CollideType != CollideType.Solid; + nonSolid = CustomBlockDefs[block.RawID].CollideType != CollideType.Solid; } int i = block.Index;