From 3fc5bb1b75c6af47e6fd2de133074b528a743e50 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 9 Mar 2016 11:44:52 +1100 Subject: [PATCH] Fix brush arguments being incorrectly treated as draw modes in some cases. --- Commands/building/CmdCuboid.cs | 39 ++++++++++++++------------ Commands/building/CmdFill.cs | 31 +++++++++++---------- Commands/building/CmdLine.cs | 47 +++++++++++++++++++------------- Commands/building/CmdPyramid.cs | 21 ++++++++------ Commands/building/CmdSpheroid.cs | 21 ++++++++------ Commands/building/CmdTorus.cs | 4 +-- Commands/building/DrawCmd.cs | 23 +++++++++------- 7 files changed, 104 insertions(+), 82 deletions(-) diff --git a/Commands/building/CmdCuboid.cs b/Commands/building/CmdCuboid.cs index cc74904cf..0898d3cfe 100644 --- a/Commands/building/CmdCuboid.cs +++ b/Commands/building/CmdCuboid.cs @@ -34,23 +34,25 @@ namespace MCGalaxy.Commands DrawOp drawOp = null; Brush brush = null; - switch (cpos.solid) { - case SolidType.solid: + switch (cpos.mode) { + case DrawMode.solid: + case DrawMode.normal: drawOp = new CuboidDrawOp(); break; - case SolidType.hollow: + case DrawMode.hollow: drawOp = new CuboidHollowsDrawOp(); break; - case SolidType.walls: + case DrawMode.walls: drawOp = new CuboidWallsDrawOp(); break; - case SolidType.holes: + case DrawMode.holes: drawOp = new CuboidHolesDrawOp(); break; - case SolidType.wire: + case DrawMode.wire: drawOp = new CuboidWireframeDrawOp(); break; - case SolidType.random: + case DrawMode.random: drawOp = new CuboidDrawOp(); brush = new RandomBrush(cpos.type, cpos.extType); break; } - if (brush == null) brush = GetBrush(p, cpos, 1); + int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1; + if (brush == null) brush = GetBrush(p, cpos, brushOffset); if (brush == null) return; if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z)) return; @@ -58,19 +60,20 @@ namespace MCGalaxy.Commands p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); } - protected override SolidType GetType(string msg) { - if (msg == "hollow") return SolidType.hollow; - else if (msg == "walls") return SolidType.walls; - else if (msg == "holes") return SolidType.holes; - else if (msg == "wire") return SolidType.wire; - else if (msg == "random") return SolidType.random; - return SolidType.solid; + protected override DrawMode ParseMode(string msg) { + if (msg == "solid") return DrawMode.solid; + else if (msg == "hollow") return DrawMode.hollow; + else if (msg == "walls") return DrawMode.walls; + else if (msg == "holes") return DrawMode.holes; + else if (msg == "wire") return DrawMode.wire; + else if (msg == "random") return DrawMode.random; + return DrawMode.normal; } public override void Help(Player p) { - Player.SendMessage(p, "%T/cuboid [block type] "); - Player.SendMessage(p, " %HCreates a cuboid between two points."); - Player.SendMessage(p, " %HMode can be: solid/hollow/walls/holes/wire/random"); + Player.SendMessage(p, "%T/cuboid [block type] "); + Player.SendMessage(p, " %HCreates a cuboid between two points."); + Player.SendMessage(p, " %HMode can be: solid/hollow/walls/holes/wire/random"); } } } diff --git a/Commands/building/CmdFill.cs b/Commands/building/CmdFill.cs index 04f9295b8..21f756a77 100644 --- a/Commands/building/CmdFill.cs +++ b/Commands/building/CmdFill.cs @@ -28,13 +28,13 @@ namespace MCGalaxy.Commands { public override string shortcut { get { return "f"; } } public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } - protected override SolidType GetType(string msg) { - if (msg == "up") return SolidType.up; - else if (msg == "down") return SolidType.down; - else if (msg == "layer") return SolidType.layer; - else if (msg == "vertical_x") return SolidType.verticalX; - else if (msg == "vertical_z") return SolidType.verticalZ; - return SolidType.solid; + protected override DrawMode ParseMode(string msg) { + if (msg == "up") return DrawMode.up; + else if (msg == "down") return DrawMode.down; + else if (msg == "layer") return DrawMode.layer; + else if (msg == "vertical_x") return DrawMode.verticalX; + else if (msg == "vertical_z") return DrawMode.verticalZ; + return DrawMode.normal; } protected override string PlaceMessage { @@ -62,19 +62,20 @@ namespace MCGalaxy.Commands { SparseBitSet bits = new SparseBitSet(p.level.Width, p.level.Height, p.level.Length); List buffer = new List(), origins = new List(); - FloodFill(p, x, y, z, oldType, oldExtType, cpos.solid, bits, buffer, origins, 0); + FloodFill(p, x, y, z, oldType, oldExtType, cpos.mode, bits, buffer, origins, 0); int totalFill = origins.Count; for (int i = 0; i < totalFill; i++) { int pos = origins[i]; p.level.IntToPos(pos, out x, out y, out z); - FloodFill(p, x, y, z, oldType, oldExtType, cpos.solid, bits, buffer, origins, 0); + FloodFill(p, x, y, z, oldType, oldExtType, cpos.mode, bits, buffer, origins, 0); totalFill = origins.Count; } FillDrawOp drawOp = new FillDrawOp(); drawOp.Positions = buffer; - Brush brush = GetBrush(p, cpos, 1); + int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1; + Brush brush = GetBrush(p, cpos, brushOffset); if (brush == null) return; if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, cpos.x, cpos.y, cpos.z)) return; @@ -87,7 +88,7 @@ namespace MCGalaxy.Commands { protected override void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { } - void FloodFill(Player p, ushort x, ushort y, ushort z, byte oldType, byte oldExtType, SolidType fillType, + void FloodFill(Player p, ushort x, ushort y, ushort z, byte oldType, byte oldExtType, DrawMode fillType, SparseBitSet bits, List buffer, List origins, int depth) { if (bits.Get(x, y, z)) return; int index = p.level.PosToInt(x, y, z); @@ -95,26 +96,26 @@ namespace MCGalaxy.Commands { bits.Set(x, y, z, true); buffer.Add(index); - if (fillType != SolidType.verticalX) { // x + if (fillType != DrawMode.verticalX) { // x if (CheckTile(p, (ushort)(x + 1), y, z, oldType, oldExtType)) FloodFill(p, (ushort)(x + 1), y, z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1); if (CheckTile(p, (ushort)(x - 1), y, z, oldType, oldExtType)) FloodFill(p, (ushort)(x - 1), y, z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1); } - if (fillType != SolidType.verticalZ) { // z + if (fillType != DrawMode.verticalZ) { // z if (CheckTile(p, x, y, (ushort)(z + 1), oldType, oldExtType)) FloodFill(p, x, y, (ushort)(z + 1), oldType, oldExtType, fillType, bits, buffer, origins, depth + 1); if (CheckTile(p, x, y, (ushort)(z - 1), oldType, oldExtType)) FloodFill(p, x, y, (ushort)(z - 1), oldType, oldExtType, fillType, bits, buffer, origins, depth + 1); } - if (!(fillType == SolidType.down || fillType == SolidType.layer)) { // y up + if (!(fillType == DrawMode.down || fillType == DrawMode.layer)) { // y up if (CheckTile(p, x, (ushort)(y + 1), z, oldType, oldExtType)) FloodFill(p, x, (ushort)(y + 1), z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1); } - if (!(fillType == SolidType.up || fillType == SolidType.layer)) { // y down + if (!(fillType == DrawMode.up || fillType == DrawMode.layer)) { // y down if (CheckTile(p, x, (ushort)(y - 1), z, oldType, oldExtType)) FloodFill(p, x, (ushort)(y - 1), z, oldType, oldExtType, fillType, bits, buffer, origins, depth + 1); } diff --git a/Commands/building/CmdLine.cs b/Commands/building/CmdLine.cs index 8e30a32cc..cf12ad514 100644 --- a/Commands/building/CmdLine.cs +++ b/Commands/building/CmdLine.cs @@ -28,23 +28,30 @@ namespace MCGalaxy.Commands { public override string name { get { return "line"; } } public override string shortcut { get { return "l"; } } - protected override SolidType GetType(string msg) { - if (msg == "walls") return SolidType.walls; - else if (msg == "straight") return SolidType.straight; - return SolidType.solid; + protected override DrawMode ParseMode(string msg) { + if (msg == "normal") return DrawMode.solid; + else if (msg == "walls") return DrawMode.walls; + else if (msg == "straight") return DrawMode.straight; + return DrawMode.normal; } protected override void OnUse(Player p, string msg, string[] parts, ref CatchPos cpos) { - if (parts.Length >= 2) { - string arg = parts[parts.Length - 1]; - ushort len; - if (!ushort.TryParse(arg, out len)) { - if (arg == "walls" || arg == "straight" || arg == "normal") return; - Player.SendMessage(p, msg + " is not valid length, assuming maximum length allowed."); - } else { - cpos.data = len; - } - } + if (parts.Length < 2 || cpos.mode == DrawMode.normal) return; + string arg = parts[parts.Length - 1]; + ushort len; + if (ushort.TryParse(arg, out len)) + cpos.data = len; + } + + protected override DrawMode GetMode(string message, string[] parts) { + if (message == "") return DrawMode.normal; + DrawMode mode = ParseMode(parts[parts.Length - 1]); + if (mode != DrawMode.normal) return mode; + + // May be in the format + ushort len; + if (!ushort.TryParse(parts[parts.Length - 1], out len)) return DrawMode.normal; + return ParseMode(parts[parts.Length - 2]); } protected override void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { @@ -52,7 +59,7 @@ namespace MCGalaxy.Commands { CatchPos cpos = (CatchPos)p.blockchangeObject; GetRealBlock(type, extType, p, ref cpos); - if (cpos.solid == SolidType.straight) { + if (cpos.mode == DrawMode.straight) { int dx = Math.Abs(cpos.x - x); int dy = Math.Abs(cpos.y - y); int dz = Math.Abs(cpos.z - z); @@ -67,10 +74,12 @@ namespace MCGalaxy.Commands { } LineDrawOp drawOp = new LineDrawOp(); - drawOp.WallsMode = cpos.solid == SolidType.walls; - if (cpos.data != null) - drawOp.MaxLength = (ushort)cpos.data; - Brush brush = GetBrush(p, cpos, cpos.data == null ? 1 : 2); + drawOp.WallsMode = cpos.mode == DrawMode.walls; + int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1; + if (cpos.data != null) { + drawOp.MaxLength = (ushort)cpos.data; brushOffset++; + } + Brush brush = GetBrush(p, cpos, brushOffset); if (brush == null) return; if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z)) diff --git a/Commands/building/CmdPyramid.cs b/Commands/building/CmdPyramid.cs index 456caa8d5..c1f128f10 100644 --- a/Commands/building/CmdPyramid.cs +++ b/Commands/building/CmdPyramid.cs @@ -32,7 +32,8 @@ namespace MCGalaxy.Commands CatchPos cpos = (CatchPos)p.blockchangeObject; GetRealBlock(type, extType, p, ref cpos); DrawOp drawOp = null; - Brush brush = GetBrush(p, cpos, 1); + int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1; + Brush brush = GetBrush(p, cpos, brushOffset); if (brush == null) return; if (y != cpos.y) { @@ -40,12 +41,13 @@ namespace MCGalaxy.Commands return; } - switch (cpos.solid) { - case SolidType.solid: + switch (cpos.mode) { + case DrawMode.solid: + case DrawMode.normal: drawOp = new PyramidSolidDrawOp(); break; - case SolidType.hollow: + case DrawMode.hollow: drawOp = new PyramidHollowDrawOp(); break; - case SolidType.reverse: + case DrawMode.reverse: drawOp = new PyramidReverseDrawOp(); break; } @@ -55,10 +57,11 @@ namespace MCGalaxy.Commands p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); } - protected override SolidType GetType(string msg) { - if (msg == "hollow") return SolidType.hollow; - else if (msg == "reverse") return SolidType.reverse; - return SolidType.solid; + protected override DrawMode ParseMode(string msg) { + if (msg == "solid") return DrawMode.solid; + else if (msg == "hollow") return DrawMode.hollow; + else if (msg == "reverse") return DrawMode.reverse; + return DrawMode.normal; } public override void Help(Player p) { diff --git a/Commands/building/CmdSpheroid.cs b/Commands/building/CmdSpheroid.cs index 40f87e246..cf4fda063 100644 --- a/Commands/building/CmdSpheroid.cs +++ b/Commands/building/CmdSpheroid.cs @@ -32,15 +32,17 @@ namespace MCGalaxy.Commands { CatchPos cpos = (CatchPos)p.blockchangeObject; GetRealBlock(type, extType, p, ref cpos); DrawOp drawOp = null; - Brush brush = GetBrush(p, cpos, 1); + int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1; + Brush brush = GetBrush(p, cpos, brushOffset); if (brush == null) return; - switch (cpos.solid) { - case SolidType.solid: + switch (cpos.mode) { + case DrawMode.solid: + case DrawMode.normal: drawOp = new EllipsoidDrawOp(); break; - case SolidType.hollow: + case DrawMode.hollow: drawOp = new EllipsoidHollowDrawOp(); break; - case SolidType.vertical: + case DrawMode.vertical: drawOp = new CylinderDrawOp(); break; } @@ -50,10 +52,11 @@ namespace MCGalaxy.Commands { p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); } - protected override SolidType GetType(string msg) { - if (msg == "hollow") return SolidType.hollow; - else if (msg == "vertical") return SolidType.vertical; - return SolidType.solid; + protected override DrawMode ParseMode(string msg) { + if (msg == "solid") return DrawMode.solid; + else if (msg == "hollow") return DrawMode.hollow; + else if (msg == "vertical") return DrawMode.vertical; + return DrawMode.normal; } public override void Help(Player p) { diff --git a/Commands/building/CmdTorus.cs b/Commands/building/CmdTorus.cs index 707844631..5c1604abc 100644 --- a/Commands/building/CmdTorus.cs +++ b/Commands/building/CmdTorus.cs @@ -41,8 +41,8 @@ namespace MCGalaxy.Commands { p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); } - protected override SolidType GetType(string msg) { - return SolidType.solid; + protected override DrawMode ParseMode(string msg) { + return DrawMode.normal; } public override void Help(Player p) { diff --git a/Commands/building/DrawCmd.cs b/Commands/building/DrawCmd.cs index 683366bcd..7a7e61bcb 100644 --- a/Commands/building/DrawCmd.cs +++ b/Commands/building/DrawCmd.cs @@ -27,12 +27,11 @@ namespace MCGalaxy.Commands { public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } public override void Use(Player p, string message) { + message = message.ToLower(); string[] parts = message.Split(' '); - for (int i = 0; i < parts.Length; i++) - parts[i] = parts[i].ToLower(); CatchPos cpos = default(CatchPos); - cpos.message = message.ToLower(); - cpos.solid = message == "" ? SolidType.solid : GetType(parts[parts.Length - 1]); + cpos.message = message; + cpos.mode = GetMode(message, parts); OnUse(p, message, parts, ref cpos); p.blockchangeObject = cpos; @@ -58,10 +57,14 @@ namespace MCGalaxy.Commands { protected abstract void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType); - protected abstract SolidType GetType(string msg); + protected abstract DrawMode ParseMode(string mode); protected virtual void OnUse(Player p, string msg, string[] parts, ref CatchPos cpos) { } + protected virtual DrawMode GetMode(string message, string[] parts) { + return message == "" ? DrawMode.normal : ParseMode(parts[parts.Length - 1]); + } + internal static byte GetBlock(Player p, string msg, out byte extType, bool checkPlacePerm = true) { byte type = Block.Byte(msg); extType = 0; @@ -84,10 +87,10 @@ namespace MCGalaxy.Commands { } protected static Brush GetBrush(Player p, CatchPos cpos, int usedFromEnd) { - int end = cpos.message.Length - 1; + int end = cpos.message.Length; string brushMsg = ""; for (int i = 0; i < usedFromEnd; i++) { - end = cpos.message.LastIndexOf(' ', end); + end = cpos.message.LastIndexOf(' ', end - 1); if (end == -1) break; } @@ -103,15 +106,15 @@ namespace MCGalaxy.Commands { } protected struct CatchPos { - public SolidType solid; + public DrawMode mode; public byte type, extType; public ushort x, y, z; public object data; public string message; } - protected enum SolidType { - solid, hollow, walls, + protected enum DrawMode { + normal, solid, hollow, walls, holes, wire, random, vertical, reverse, straight, up, down, layer, verticalX, verticalZ,