From ae9ed7ba9eaa551165e766bbabb6f25e88dc8181 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 9 Feb 2016 11:45:17 +1100 Subject: [PATCH] Old width/height/length/depth should be fields to not break old plugins (Thanks goodlyay), also fix /copy ignore to work with custom blocks and add /copy air ignore. (Thanks goodlyay) --- Commands/World/CmdRestore.cs | 10 +++--- Commands/building/CmdCopy.cs | 61 ++++++++++++++++++++++-------------- Levels/IO/ConvertDAT.cs | 5 ++- Levels/Level.cs | 24 +++++++------- 4 files changed, 58 insertions(+), 42 deletions(-) diff --git a/Commands/World/CmdRestore.cs b/Commands/World/CmdRestore.cs index 2c956664a..2a42ef964 100644 --- a/Commands/World/CmdRestore.cs +++ b/Commands/World/CmdRestore.cs @@ -79,11 +79,11 @@ namespace MCGalaxy.Commands lvl.spawnx = temp.spawnx; lvl.spawny = temp.spawny; lvl.spawnz = temp.spawnz; - - lvl.Length = temp.Length; - lvl.Width = temp.Width; - lvl.Height = temp.Height; - + + lvl.Width = temp.Width; lvl.width = temp.Width; + lvl.Height = temp.Height; lvl.depth = temp.Height; + lvl.Length = temp.Length; lvl.length = temp.Length; lvl.height = temp.Length; + lvl.blocks = temp.blocks; lvl.setPhysics(0); lvl.ClearPhysics(); diff --git a/Commands/building/CmdCopy.cs b/Commands/building/CmdCopy.cs index c28ac4d67..adb20d333 100644 --- a/Commands/building/CmdCopy.cs +++ b/Commands/building/CmdCopy.cs @@ -50,8 +50,8 @@ namespace MCGalaxy.Commands } else if (opt == "delete") { if (parts.Length != 2) { Help(p); return; } string path = "extra/savecopy/" + parts[1] + "/" + message + ".cpy"; - if (!File.Exists(path)) { - Player.SendMessage(p, "No such copy exists"); return; + if (!File.Exists(path)) { + Player.SendMessage(p, "No such copy exists"); return; } File.Delete(path); @@ -75,20 +75,17 @@ namespace MCGalaxy.Commands void HandleOther(Player p, string opt, string[] parts) { CatchPos cpos = default(CatchPos); cpos.ignoreTypes = new List(); - p.copyoffset[0] = 0; p.copyoffset[1] = 0; p.copyoffset[2] = 0; + cpos.extIgnoreTypes = new List(); + p.copyoffset[0] = 0; p.copyoffset[1] = 0; p.copyoffset[2] = 0; if (opt == "cut") { cpos.type = 1; } else if (opt == "air") { cpos.type = 2; + if (parts.Length > 1 && parts[1].ToLower() == "ignore") + GetIgnoreBlocks(cpos, p, 2, parts); } else if (opt == "ignore") { - for (int i = 1; i < parts.Length; i++ ) { - string s = parts[i]; - if (Block.Byte(s) != Block.Zero) { - cpos.ignoreTypes.Add(Block.Byte(s)); - Player.SendMessage(p, "Ignoring &b" + s); - } - } + GetIgnoreBlocks(cpos, p, 1, parts); } else if (!String.IsNullOrEmpty(opt)) { Help(p); return; } @@ -98,6 +95,19 @@ namespace MCGalaxy.Commands p.ClearBlockchange(); p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); } + + void GetIgnoreBlocks(CatchPos cpos, Player p, int i, string[] parts) { + for (; i < parts.Length; i++ ) { + byte extType = 0; + byte type = DrawCmd.GetBlock(p, parts[i], out extType); + if (type == Block.Zero) continue; + + if (type != Block.custom_block || extType == 0) + cpos.ignoreTypes.Add(type); + if (type == Block.custom_block) + cpos.extIgnoreTypes.Add(extType); + } + } void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { RevertAndClearState(p, x, y, z); @@ -117,7 +127,7 @@ namespace MCGalaxy.Commands ushort minZ = (ushort)Math.Min(z, cpos.z), maxX = (ushort)Math.Max(x, cpos.x); ushort maxY = (ushort)Math.Max(y, cpos.y), maxZ = (ushort)Math.Max(z, cpos.z); - CopyState state = new CopyState(minX, minY, minZ, maxX - minX + 1, + CopyState state = new CopyState(minX, minY, minZ, maxX - minX + 1, maxY - minY + 1, maxZ - minZ + 1); state.SetOrigin(cpos.x, cpos.y, cpos.z); int totalAir = 0, index = 0; @@ -127,15 +137,17 @@ namespace MCGalaxy.Commands for (ushort zz = minZ; zz <= maxZ; ++zz) for (ushort xx = minX; xx <= maxX; ++xx) { - byte b = p.level.GetTile(xx, yy, zz); + byte b = p.level.GetTile(xx, yy, zz), extB = 0; if (!Block.canPlace(p, b)) { index++; continue; } + if (b == Block.custom_block) + extB = p.level.GetExtTile(xx, yy, zz); + bool ignore = cpos.ignoreTypes.Contains(b) || cpos.extIgnoreTypes.Contains(extB); - if (b == Block.air && cpos.type != 2 || cpos.ignoreTypes.Contains(b)) + if (b == Block.air && cpos.type != 2 || ignore) totalAir++; - if (!cpos.ignoreTypes.Contains(b)) { + if (!ignore) { state.Blocks[index] = b; - if (b == Block.custom_block) - state.ExtBlocks[index] = p.level.GetExtTile(xx, yy, zz); + state.ExtBlocks[index] = extB; } index++; } @@ -176,8 +188,7 @@ namespace MCGalaxy.Commands void SaveCopy(Player p, string file) { if (!Player.ValidName(file)) { - Player.SendMessage(p, "Bad file name"); - return; + Player.SendMessage(p, "Bad file name"); return; } if (!Directory.Exists("extra/savecopy")) @@ -198,13 +209,12 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "Saved copy as " + file); } - void LoadCopy(Player p, string file) { + void LoadCopy(Player p, string file) { string path = "extra/savecopy/" + p.name + "/" + file; bool existsNew = File.Exists(path + ".cpb"); bool existsOld = File.Exists(path + ".cpy"); if (!existsNew && !existsOld) { - Player.SendMessage(p, "No such copy exists"); - return; + Player.SendMessage(p, "No such copy exists"); return; } path = existsNew ? path + ".cpb" : path + ".cpy"; @@ -221,10 +231,13 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "Loaded copy as " + file); } - struct CatchPos { public ushort x, y, z; public int type; public List ignoreTypes; } + struct CatchPos { + public ushort x, y, z; + public int type; + public List ignoreTypes, extIgnoreTypes; + } - public override void Help(Player p) - { + public override void Help(Player p) { Player.SendMessage(p, "/copy - Copies the blocks in an area."); Player.SendMessage(p, "/copy save - Saves what you have copied."); Player.SendMessage(p, "/copy load - Loads what you have saved."); diff --git a/Levels/IO/ConvertDAT.cs b/Levels/IO/ConvertDAT.cs index 62e207095..2a26682e7 100644 --- a/Levels/IO/ConvertDAT.cs +++ b/Levels/IO/ConvertDAT.cs @@ -108,7 +108,10 @@ namespace MCGalaxy.Levels.IO { pointer += skip; } - + lvl.width = lvl.Width; + lvl.depth = lvl.Height; + lvl.length = lvl.Length; lvl.height = lvl.Length; + lvl.spawnx = (ushort)(lvl.Width / 1.3); lvl.spawny = (ushort)(lvl.Height / 1.3); lvl.spawnz = (ushort)(lvl.Length / 1.3); diff --git a/Levels/Level.cs b/Levels/Level.cs index a5fbb8328..6468cd47c 100644 --- a/Levels/Level.cs +++ b/Levels/Level.cs @@ -102,12 +102,12 @@ namespace MCGalaxy public bool ctfmode; public int currentUndo; public ushort Width, Height, Length; - // NOTE: These are for legacy matching only, you should use upper case Width/Height/Length - // as these correctly map Y to beinh Height - [Obsolete] public ushort width { get { return Width; } } - [Obsolete] public ushort height { get { return Length; } } - [Obsolete] public ushort depth { get { return Height; } } - [Obsolete] public ushort length { get { return Length; } } + // NOTE: These are for legacy code only, you should use upper case Width/Height/Length + // as these correctly map Y to being Height + [Obsolete] public ushort width; + [Obsolete] public ushort height; + [Obsolete] public ushort depth; + [Obsolete] public ushort length; public int drown = 70; public bool edgeWater; @@ -205,12 +205,12 @@ namespace MCGalaxy Width = x; Height = y; Length = z; - if (Width < 16) - Width = 16; - if (Height < 16) - Height = 16; - if (Length < 16) - Length = 16; + if (Width < 16) Width = 16; + if (Height < 16) Height = 16; + if (Length < 16) Length = 16; + width = Width; + length = Height; + height = Length; depth = Length; CustomBlockDefs = new BlockDefinition[256]; for (int i = 0; i < CustomBlockDefs.Length; i++)