From 672e93ba2afe6a78f3f03fd5342b3beec85003dd Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 8 Mar 2016 18:52:36 +1100 Subject: [PATCH] Add black-and-white rainbow brush, add random rainbow brush with a seed. --- Commands/building/DrawCmd.cs | 2 +- Drawing/Brushes/Brush.cs | 3 ++- Drawing/Brushes/RainbowBrush.cs | 37 ++++++++++++++++++++++++++------- Drawing/DrawOps/DrawOp.cs | 4 ++++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/Commands/building/DrawCmd.cs b/Commands/building/DrawCmd.cs index 0c1698113..683366bcd 100644 --- a/Commands/building/DrawCmd.cs +++ b/Commands/building/DrawCmd.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Commands { for (int i = 0; i < parts.Length; i++) parts[i] = parts[i].ToLower(); CatchPos cpos = default(CatchPos); - cpos.message = message; + cpos.message = message.ToLower(); cpos.solid = message == "" ? SolidType.solid : GetType(parts[parts.Length - 1]); OnUse(p, message, parts, ref cpos); p.blockchangeObject = cpos; diff --git a/Drawing/Brushes/Brush.cs b/Drawing/Brushes/Brush.cs index 0541f7a56..161ccf81c 100644 --- a/Drawing/Brushes/Brush.cs +++ b/Drawing/Brushes/Brush.cs @@ -29,11 +29,12 @@ namespace MCGalaxy.Drawing.Brushes { public abstract byte NextExtBlock(DrawOp op); public static Dictionary> Brushes - = new Dictionary> { + = new Dictionary> { { "normal", SolidBrush.Process }, { "paste", PasteBrush.Process }, { "checkered", CheckeredBrush.Process }, { "rainbow", RainbowBrush.Process }, + { "bwrainbow", BWRainbowBrush.Process }, }; } diff --git a/Drawing/Brushes/RainbowBrush.cs b/Drawing/Brushes/RainbowBrush.cs index b87cb0bab..65e4e1374 100644 --- a/Drawing/Brushes/RainbowBrush.cs +++ b/Drawing/Brushes/RainbowBrush.cs @@ -25,11 +25,7 @@ namespace MCGalaxy.Drawing.Brushes { public sealed class RainbowBrush : Brush { public override byte NextBlock(DrawOp op) { - int dx = op.Coords.X - op.Min.X; - int dy = op.Coords.Y - op.Min.Y; - int dz = op.Coords.Z - op.Min.Z; - - int offset = (dx + dy + dz) % 13; + int offset = (op.Coords.X + op.Coords.Y + op.Coords.Z) % 13; if (offset < 0) offset += 13; return (byte)(Block.red + offset); } @@ -37,9 +33,34 @@ namespace MCGalaxy.Drawing.Brushes { public override byte NextExtBlock(DrawOp op) { return 0; } public static Brush Process(BrushArgs args) { - if (args.Message == "random") - return new RandomRainbowBrush(); - return new RainbowBrush(); // TODO: seed + if (args.Message.StartsWith("random")) { + string[] parts = args.Message.Split(' '); + int seed; + if (parts.Length > 1 && Int32.TryParse(parts[1], out seed)) + return new RandomRainbowBrush(seed); + return new RandomRainbowBrush(); + } + + if (args.Message == "bw") + return new BWRainbowBrush(); + return new RainbowBrush(); + } + } + + public sealed class BWRainbowBrush : Brush { + + static byte[] blocks = { Block.iron, Block.white, Block.lightgrey, + Block.darkgrey, Block.obsidian, Block.darkgrey, Block.lightgrey, Block.white }; + public override byte NextBlock(DrawOp op) { + int offset = (op.Coords.X + op.Coords.Y + op.Coords.Z) % 8; + if (offset < 0) offset += 8; + return blocks[offset]; + } + + public override byte NextExtBlock(DrawOp op) { return 0; } + + public static Brush Process(BrushArgs args) { + return new BWRainbowBrush(); } } diff --git a/Drawing/DrawOps/DrawOp.cs b/Drawing/DrawOps/DrawOp.cs index 6e1088ca8..bcc964125 100644 --- a/Drawing/DrawOps/DrawOp.cs +++ b/Drawing/DrawOps/DrawOp.cs @@ -41,6 +41,9 @@ namespace MCGalaxy.Drawing.Ops { /// Maximum coordinates of the bounds of this drawing command. public Vector3U16 Max; + /// Coordinates of the first point selected by the user. + public Vector3U16 Origin; + /// Coordinates of the current block being processed by the drawing command. public Vector3U16 Coords; @@ -118,6 +121,7 @@ namespace MCGalaxy.Drawing.Ops { public static bool DoDrawOp(DrawOp op, Brush brush, Player p, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) { int affected = 0; + op.Origin = new Vector3U16(x1, y1, z1); op.Min = Vector3U16.Min(x1, y1, z1, x2, y2, z2); op.Max = Vector3U16.Max(x1, y1, z1, x2, y2, z2); if (op.MinMaxCoords) {