diff --git a/Drawing/Brushes/Brush.cs b/Drawing/Brushes/Brush.cs index 7541f245e..0541f7a56 100644 --- a/Drawing/Brushes/Brush.cs +++ b/Drawing/Brushes/Brush.cs @@ -33,6 +33,7 @@ namespace MCGalaxy.Drawing.Brushes { { "normal", SolidBrush.Process }, { "paste", PasteBrush.Process }, { "checkered", CheckeredBrush.Process }, + { "rainbow", RainbowBrush.Process }, }; } @@ -46,20 +47,6 @@ namespace MCGalaxy.Drawing.Brushes { } } - public sealed class RainbowBrush : Brush { - byte curBlock = Block.red; - - public override byte NextBlock(DrawOp op) { - byte block = curBlock; - curBlock++; - if (curBlock > Block.darkpink) - curBlock = Block.red; - return block; - } - - public override byte NextExtBlock(DrawOp op) { return 0; } - } - public sealed class RandomBrush : Brush { readonly Random rnd = new Random(); readonly byte type, extType; @@ -75,22 +62,4 @@ namespace MCGalaxy.Drawing.Brushes { public override byte NextExtBlock(DrawOp op) { return extType; } } - - public sealed class RandomRainbowBrush : Brush { - readonly Random rnd; - - public RandomRainbowBrush() { - rnd = new Random(); - } - - public RandomRainbowBrush(int seed) { - rnd = new Random(seed); - } - - public override byte NextBlock(DrawOp op) { - return (byte)rnd.Next(Block.red, Block.darkgrey); - } - - public override byte NextExtBlock(DrawOp op) { return 0; } - } } diff --git a/Drawing/Brushes/CheckeredBrush.cs b/Drawing/Brushes/CheckeredBrush.cs index b360c8eb4..0cf130395 100644 --- a/Drawing/Brushes/CheckeredBrush.cs +++ b/Drawing/Brushes/CheckeredBrush.cs @@ -30,7 +30,7 @@ namespace MCGalaxy.Drawing.Brushes { this.type2 = type2; this.extType2 = extType2; } - public static CheckeredBrush Process(BrushArgs args) { + public static Brush Process(BrushArgs args) { if (args.Message == "") return new CheckeredBrush(args.Type, args.ExtType, 0, 0); string[] parts = args.Message.Split(' '); diff --git a/Drawing/Brushes/PasteBrush.cs b/Drawing/Brushes/PasteBrush.cs index ff1daff55..1f7577593 100644 --- a/Drawing/Brushes/PasteBrush.cs +++ b/Drawing/Brushes/PasteBrush.cs @@ -29,7 +29,7 @@ namespace MCGalaxy.Drawing.Brushes { this.state = state; } - public static PasteBrush Process(BrushArgs args) { + public static Brush Process(BrushArgs args) { if (args.Player.CopyBuffer == null) { args.Player.SendMessage("You haven't copied anything yet."); return null; diff --git a/Drawing/Brushes/RainbowBrush.cs b/Drawing/Brushes/RainbowBrush.cs new file mode 100644 index 000000000..b87cb0bab --- /dev/null +++ b/Drawing/Brushes/RainbowBrush.cs @@ -0,0 +1,63 @@ +/* + Copyright 2015 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using System.Collections.Generic; +using MCGalaxy.Commands; +using MCGalaxy.Drawing.Ops; + +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; + if (offset < 0) offset += 13; + return (byte)(Block.red + offset); + } + + 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 + } + } + + public sealed class RandomRainbowBrush : Brush { + readonly Random rnd; + + public RandomRainbowBrush() { + rnd = new Random(); + } + + public RandomRainbowBrush(int seed) { + rnd = new Random(seed); + } + + public override byte NextBlock(DrawOp op) { + return (byte)rnd.Next(Block.red, Block.darkgrey); + } + + public override byte NextExtBlock(DrawOp op) { return 0; } + } +} diff --git a/Drawing/Brushes/SolidBrush.cs b/Drawing/Brushes/SolidBrush.cs index d6589b67c..69e3d0d73 100644 --- a/Drawing/Brushes/SolidBrush.cs +++ b/Drawing/Brushes/SolidBrush.cs @@ -30,7 +30,7 @@ namespace MCGalaxy.Drawing.Brushes { this.extType = extType; } - public static SolidBrush Process(BrushArgs args) { + public static Brush Process(BrushArgs args) { if (args.Message == "") return new SolidBrush(args.Type, args.ExtType); byte extType; diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index b91c05143..0e84c5e2b 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -395,6 +395,7 @@ +