From b8625b0a2269ca58406ec5e522ed34ab33ed89b4 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 11 Jun 2017 18:42:55 +1000 Subject: [PATCH] More fixes for recent few commits --- MCGalaxy/Blocks/BlockDefinitions.cs | 17 ++++++++++------- MCGalaxy/Blocks/BlockPerms.cs | 2 +- MCGalaxy/Blocks/BlockProperties.cs | 4 ++-- MCGalaxy/Blocks/ExtBlock.cs | 2 +- MCGalaxy/Blocks/Physics/ExtraInfoPhysics.cs | 4 ++-- MCGalaxy/Commands/CPE/CustomBlockCommand.cs | 2 +- MCGalaxy/Levels/Level.Physics.cs | 7 +++++-- MCGalaxy/Levels/Level.cs | 11 +++-------- MCGalaxy/Server/Server.cs | 1 + 9 files changed, 26 insertions(+), 24 deletions(-) diff --git a/MCGalaxy/Blocks/BlockDefinitions.cs b/MCGalaxy/Blocks/BlockDefinitions.cs index 70e8a2f50..88f9c55f8 100644 --- a/MCGalaxy/Blocks/BlockDefinitions.cs +++ b/MCGalaxy/Blocks/BlockDefinitions.cs @@ -120,10 +120,6 @@ namespace MCGalaxy { GlobalDefs[Block.air] = DefaultSet.MakeCustomBlock(Block.air); GlobalDefs[Block.air].Name = "Air fallback"; - GlobalProps = new BlockProps[Block.Count * 2]; - for (int i = 0; i < Block.Count; i++) - GlobalProps[i] = Block.Props[i]; - try { if (File.Exists(GlobalPath)) { File.Copy(GlobalPath, GlobalBackupPath, true); @@ -132,14 +128,21 @@ namespace MCGalaxy { Server.ErrorLog(ex); } - Save(true, null); - BlockProps.Load("global", BlockDefinition.GlobalProps, true); - + Save(true, null); // As the BlockDefinition instances in levels will now be different // to the instances in GlobalDefs, we need to update them. if (oldDefs != null) UpdateLoadedLevels(oldDefs); } + public static void LoadGlobalProps() { + GlobalProps = new BlockProps[Block.Count * 2]; + for (int i = 0; i < Block.Count; i++) { + GlobalProps[i] = Block.Props[i]; + GlobalProps[i + Block.Count] = new BlockProps((byte)i); + } + BlockProps.Load("global", GlobalProps, true); + } + static void UpdateLoadedLevels(BlockDefinition[] oldGlobalDefs) { Level[] loaded = LevelInfo.Loaded.Items; foreach (Level lvl in loaded) { diff --git a/MCGalaxy/Blocks/BlockPerms.cs b/MCGalaxy/Blocks/BlockPerms.cs index 3706b1feb..7b58da8d0 100644 --- a/MCGalaxy/Blocks/BlockPerms.cs +++ b/MCGalaxy/Blocks/BlockPerms.cs @@ -48,7 +48,7 @@ namespace MCGalaxy.Blocks { return perms; } - public static BlockPerms[] List = new BlockPerms[256]; + public static BlockPerms[] List = new BlockPerms[Block.Count]; /// Returns whether the given rank can modify the given block. diff --git a/MCGalaxy/Blocks/BlockProperties.cs b/MCGalaxy/Blocks/BlockProperties.cs index 04fe2c5c6..e072f2d00 100644 --- a/MCGalaxy/Blocks/BlockProperties.cs +++ b/MCGalaxy/Blocks/BlockProperties.cs @@ -92,7 +92,7 @@ namespace MCGalaxy.Blocks { // 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 - 256) : i; + int id = i >= Block.Count ? (i - Block.Count) : i; string deathMsg = props.DeathMessage == null ? "" : props.DeathMessage.Replace(":", "\\;"); w.WriteLine(id + ":" + props.IsRails + ":" + props.IsTDoor + ":" + props.IsDoor + ":" @@ -124,7 +124,7 @@ namespace MCGalaxy.Blocks { continue; } int idx = raw; - if (custom && raw >= Block.CpeCount) idx += 256; + if (custom && raw >= Block.CpeCount) idx += Block.Count; bool.TryParse(parts[1], out scope[idx].IsRails); bool.TryParse(parts[2], out scope[idx].IsTDoor); diff --git a/MCGalaxy/Blocks/ExtBlock.cs b/MCGalaxy/Blocks/ExtBlock.cs index 134ef6598..3a6fe6861 100644 --- a/MCGalaxy/Blocks/ExtBlock.cs +++ b/MCGalaxy/Blocks/ExtBlock.cs @@ -48,7 +48,7 @@ namespace MCGalaxy { public bool IsAir { get { return BlockID == Block.air; } } /// Returns the index of this block within an array. - public int Index { get { return BlockID != Block.custom_block ? BlockID : (ExtID + 256); } } + public int Index { get { return BlockID != Block.custom_block ? BlockID : (ExtID + Block.Count); } } /// Returns the raw (for client side) block ID of this block. diff --git a/MCGalaxy/Blocks/Physics/ExtraInfoPhysics.cs b/MCGalaxy/Blocks/Physics/ExtraInfoPhysics.cs index 0c5d968fc..2e75ad72b 100644 --- a/MCGalaxy/Blocks/Physics/ExtraInfoPhysics.cs +++ b/MCGalaxy/Blocks/Physics/ExtraInfoPhysics.cs @@ -30,7 +30,7 @@ namespace MCGalaxy.Blocks.Physics { if (!C.data.HasWait) return false; if (C.data.Door && C.data.Data == 0) { - int i = C.data.Value2 + (C.data.ExtBlock ? 256 : 0); + int i = C.data.Value2 + (C.data.ExtBlock ? Block.Count : 0); bool tdoor = lvl.BlockProps[i].IsTDoor; if (tdoor) DoorPhysics.tDoor(lvl, ref C); @@ -68,7 +68,7 @@ namespace MCGalaxy.Blocks.Physics { if (args.Wait) { if (C.data.Door && C.data.Data == 0) { - int i = C.data.Value2 + (C.data.ExtBlock ? 256 : 0); + int i = C.data.Value2 + (C.data.ExtBlock ? Block.Count : 0); bool tdoor = lvl.BlockProps[i].IsTDoor; if (tdoor) DoorPhysics.tDoor(lvl, ref C); diff --git a/MCGalaxy/Commands/CPE/CustomBlockCommand.cs b/MCGalaxy/Commands/CPE/CustomBlockCommand.cs index fb9d19db4..f3b5c467d 100644 --- a/MCGalaxy/Commands/CPE/CustomBlockCommand.cs +++ b/MCGalaxy/Commands/CPE/CustomBlockCommand.cs @@ -121,7 +121,7 @@ namespace MCGalaxy.Commands.CPE { AddBlock(p, dstDef, global, cmd, props); string scope = global ? "global" : "level"; - Player.Message(p, "Duplicated the {0} custom block with id \"{1}\" to \"{2}\".", scope, src, dst); + Player.Message(p, "Duplicated the {0} custom block with id \"{1}\" to \"{2}\".", scope, src.RawID, dst.RawID); } static void InfoHandler(Player p, string[] parts, bool global, string cmd) { diff --git a/MCGalaxy/Levels/Level.Physics.cs b/MCGalaxy/Levels/Level.Physics.cs index c7719f460..30cf0f705 100644 --- a/MCGalaxy/Levels/Level.Physics.cs +++ b/MCGalaxy/Levels/Level.Physics.cs @@ -154,7 +154,10 @@ namespace MCGalaxy { OnPhysicsUpdateEvent.Call(x, y, z, C.data, this); if ((C.data.Raw & mask) == 0 || extraHandler(this, ref C)) { - HandlePhysics handler = handlers[blocks[C.b]]; + int idx = blocks[C.b]; + if (idx == Block.custom_block) idx = Block.Count + GetExtTileNoCheck(x, y, z); + + HandlePhysics handler = handlers[idx]; if (handler != null) { handler(this, ref C); } else if ((C.data.Raw & mask) == 0 || !C.data.HasWait) { @@ -246,7 +249,7 @@ namespace MCGalaxy { ExtBlock block; block.BlockID = type; block.ExtID = 0; - + // Is the Ext flag just an indicator for the block update? if (data.ExtBlock && (data.Raw & PhysicsArgs.TypeMask) == 0) { block.ExtID = block.BlockID; diff --git a/MCGalaxy/Levels/Level.cs b/MCGalaxy/Levels/Level.cs index 838549fdd..79beca082 100644 --- a/MCGalaxy/Levels/Level.cs +++ b/MCGalaxy/Levels/Level.cs @@ -76,6 +76,7 @@ namespace MCGalaxy { BlockProps = new BlockProps[Block.Count * 2]; for (int i = 0; i < BlockProps.Length; i++) BlockProps[i] = BlockDefinition.GlobalProps[i]; + SetBlockHandlers(); name = n; MapName = n.ToLower(); BlockDB = new BlockDB(this); @@ -92,7 +93,6 @@ namespace MCGalaxy { spawny = (ushort)(Height * 0.75f); spawnz = (ushort)(Length / 2); rotx = 0; roty = 0; - SetBlockHandlers(); ZoneList = new List(); VisitAccess = new LevelAccessController(this, true); @@ -405,10 +405,8 @@ namespace MCGalaxy { lvl.CustomBlockDefs[i] = defs[i]; } - for (int i = 0; i < lvl.BlockProps.Length; i++) { - lvl.BlockProps[i] = BlockDefinition.GlobalProps[i]; - } MCGalaxy.Blocks.BlockProps.Load("lvl_" + lvl.MapName, lvl.BlockProps, true); + lvl.SetBlockHandlers(); } public static bool CheckLoadOnGoto(string givenName) { @@ -513,11 +511,8 @@ namespace MCGalaxy { } public void SetBlockHandler(ExtBlock block) { - bool notCustom = !block.IsCustomType && - (block.BlockID >= Block.CpeCount || CustomBlockDefs[block.BlockID] == null); - bool nonSolid; - if (notCustom) { + if (GetBlockDef(block) == null) { nonSolid = Block.Walkthrough(Block.Convert(block.BlockID)); } else { nonSolid = CustomBlockDefs[block.BlockID].CollideType != CollideType.Solid; diff --git a/MCGalaxy/Server/Server.cs b/MCGalaxy/Server/Server.cs index c0d5db46d..bce51247d 100644 --- a/MCGalaxy/Server/Server.cs +++ b/MCGalaxy/Server/Server.cs @@ -195,6 +195,7 @@ namespace MCGalaxy { Command.InitAll(); CommandPerms.Load(); Block.SetBlocks(); + BlockDefinition.LoadGlobalProps(); Awards.Load(); Economy.Load(); WarpList.Global.Load(null);