From 36038932167a20b2289fc986b5c4e916cd074c7d Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 3 Aug 2016 09:32:52 +1000 Subject: [PATCH] Now if only [block] is given for replace/replacenot/replaceall, it replaces that block with your current held block. --- Commands/building/ReplaceCmd.cs | 12 +++++----- Drawing/Brushes/Brush.cs | 6 ++--- Drawing/Brushes/CheckeredBrush.cs | 2 +- Drawing/Brushes/FrequencyBrush.cs | 2 +- Drawing/Brushes/ReplaceBrush.cs | 37 +++++++++++++++++++++---------- Drawing/Brushes/SolidBrush.cs | 2 +- Drawing/Brushes/StripedBrush.cs | 2 +- 7 files changed, 39 insertions(+), 24 deletions(-) diff --git a/Commands/building/ReplaceCmd.cs b/Commands/building/ReplaceCmd.cs index df6292eda..b51ddc148 100644 --- a/Commands/building/ReplaceCmd.cs +++ b/Commands/building/ReplaceCmd.cs @@ -26,6 +26,7 @@ namespace MCGalaxy.Commands.Building { public override string type { get { return CommandTypes.Building; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } + protected virtual bool ReplaceNot { get { return false; } } public override void Use(Player p, string message) { Player.Message(p, "Place two blocks to determine the edges."); @@ -41,12 +42,11 @@ namespace MCGalaxy.Commands.Building { return DrawOp.DoDrawOp(drawOp, brush, p, marks); } - protected virtual bool ReplaceNot { get { return false; } } - public override void Help(Player p) { Player.Message(p, "%T/replace [block] [block2].. [new]"); Player.Message(p, "%HReplaces [block] with [new] between two points."); - Player.Message(p, "%H If more than one [block] is specified, they will all be replaced with [new]."); + Player.Message(p, "%H If more than one [block] is given, they are all replaced."); + Player.Message(p, "%H If only [block] is given, replaces with your held block."); } } @@ -58,7 +58,8 @@ namespace MCGalaxy.Commands.Building { public override void Help(Player p) { Player.Message(p, "%T/replacenot [block] [block2].. [new]"); Player.Message(p, "%HReplaces everything but [block] with [new] between two points."); - Player.Message(p, "%H If more than one [block] is specified, they will all be ignored."); + Player.Message(p, "%H If more than one [block] is given, they are all skipped."); + Player.Message(p, "%H If only [block] is given, replaces with your held block."); } } @@ -87,7 +88,8 @@ namespace MCGalaxy.Commands.Building { public override void Help(Player p) { Player.Message(p, "%T/replaceall [block] [block2].. [new]"); Player.Message(p, "%HReplaces [block] with [new] for the entire map."); - Player.Message(p, "%H If more than one [block] is specified, they will all be replaced with [new]."); + Player.Message(p, "%H If more than one [block] is given, they are all replaced."); + Player.Message(p, "%H If only [block] is given, replaces with your held block."); } } } diff --git a/Drawing/Brushes/Brush.cs b/Drawing/Brushes/Brush.cs index b1761b824..3488f80f9 100644 --- a/Drawing/Brushes/Brush.cs +++ b/Drawing/Brushes/Brush.cs @@ -58,10 +58,10 @@ namespace MCGalaxy.Drawing.Brushes { public struct BrushArgs { public Player Player; public string Message; - public byte Type, ExtType; // currently holding + public byte Block, ExtBlock; // currently holding - public BrushArgs(Player p, string message, byte type, byte extType) { - Player = p; Message = message; Type = type; ExtType = extType; + public BrushArgs(Player p, string message, byte block, byte extBlock) { + Player = p; Message = message; Block = block; ExtBlock = extBlock; } } } diff --git a/Drawing/Brushes/CheckeredBrush.cs b/Drawing/Brushes/CheckeredBrush.cs index 6f20f1f94..1bf303133 100644 --- a/Drawing/Brushes/CheckeredBrush.cs +++ b/Drawing/Brushes/CheckeredBrush.cs @@ -43,7 +43,7 @@ namespace MCGalaxy.Drawing.Brushes { public static Brush Process(BrushArgs args) { if (args.Message == "") - return new CheckeredBrush(args.Type, args.ExtType, 0, 0); + return new CheckeredBrush(args.Block, args.ExtBlock, 0, 0); string[] parts = args.Message.Split(' '); byte extBlock1; diff --git a/Drawing/Brushes/FrequencyBrush.cs b/Drawing/Brushes/FrequencyBrush.cs index b5a7484ac..c0518558f 100644 --- a/Drawing/Brushes/FrequencyBrush.cs +++ b/Drawing/Brushes/FrequencyBrush.cs @@ -78,7 +78,7 @@ namespace MCGalaxy.Drawing.Brushes { // No blocks given, assume first is held block if (bCount == 0) - blocks[0] = new ExtBlock(args.Type, args.ExtType); + blocks[0] = new ExtBlock(args.Block, args.ExtBlock); } public static ExtBlock[] Combine(ExtBlock[] toAffect, int[] count) { diff --git a/Drawing/Brushes/ReplaceBrush.cs b/Drawing/Brushes/ReplaceBrush.cs index 7ab634840..282e5018d 100644 --- a/Drawing/Brushes/ReplaceBrush.cs +++ b/Drawing/Brushes/ReplaceBrush.cs @@ -36,27 +36,27 @@ namespace MCGalaxy.Drawing.Brushes { public static string[] HelpString = new [] { "%TArguments: [block1] [block2].. [new]", - "%HDraws by replacing existing blocks that are in " + - "the given [blocks] with the block [new]", + "%HDraws by replacing existing blocks that are in the given [blocks] with [new]", + "%H If only [block] is given, replaces with your held block.", }; public static Brush Process(BrushArgs args) { - return ProcessReplace(args, false); + return ProcessReplace(args, false); } internal static Brush ProcessReplace(BrushArgs args, bool not) { - string[] parts = args.Message.Split(' '); - if (parts.Length < 2) { - args.Player.SendMessage("You need to provide a target block, and at least one block to replace."); return null; + string[] parts = args.Message.Split(' '); + if (args.Message == "") { + args.Player.SendMessage("You need at least one block to replace."); return null; } - ExtBlock[] toAffect = GetBlocks(args.Player, 0, parts.Length - 1, parts); + + int count = parts.Length == 1 ? 1 : parts.Length - 1; + ExtBlock[] toAffect = GetBlocks(args.Player, 0, count, parts); if (toAffect == null) return null; ExtBlock target; - int block = DrawCmd.GetBlock(args.Player, parts[parts.Length - 1], out target.Ext); - if (block == -1) return null; + if (!GetTargetBlock(args, parts, out target)) return null; - target.Block = (byte)block; if (not) return new ReplaceNotBrush(toAffect, target); return new ReplaceBrush(toAffect, target); } @@ -74,6 +74,19 @@ namespace MCGalaxy.Drawing.Brushes { return blocks; } + static bool GetTargetBlock(BrushArgs args, string[] parts, out ExtBlock target) { + if (parts.Length == 1) { + target = new ExtBlock(args.Block, args.ExtBlock); + return true; + } + + target = default(ExtBlock); + int block = DrawCmd.GetBlock(args.Player, parts[parts.Length - 1], out target.Ext); + if (block == -1) return false; + target.Block = (byte)block; + return true; + } + public override byte NextBlock(DrawOp op) { ushort x = op.Coords.X, y = op.Coords.Y, z = op.Coords.Z; byte tile = op.Level.GetTile(x, y, z), extTile = 0; @@ -106,8 +119,8 @@ namespace MCGalaxy.Drawing.Brushes { public static string[] HelpString = new [] { "%TArguments: [block1] [block2].. [new]", - "%HDraws by replacing existing blocks that not are in " + - "the given [blocks] with the block [new]", + "%HDraws by replacing existing blocks that not are in the given [blocks] with [new]", + "%H If only [block] is given, replaces with your held block.", }; public static Brush Process(BrushArgs args) { diff --git a/Drawing/Brushes/SolidBrush.cs b/Drawing/Brushes/SolidBrush.cs index c2ac290d3..2eb7c9ec2 100644 --- a/Drawing/Brushes/SolidBrush.cs +++ b/Drawing/Brushes/SolidBrush.cs @@ -41,7 +41,7 @@ namespace MCGalaxy.Drawing.Brushes { public static Brush Process(BrushArgs args) { if (args.Message == "") - return new SolidBrush(args.Type, args.ExtType); + return new SolidBrush(args.Block, args.ExtBlock); byte extBlock; int block = DrawCmd.GetBlock(args.Player, args.Message, out extBlock); if (block == -1) return null; diff --git a/Drawing/Brushes/StripedBrush.cs b/Drawing/Brushes/StripedBrush.cs index aa7f3976d..b3f7af505 100644 --- a/Drawing/Brushes/StripedBrush.cs +++ b/Drawing/Brushes/StripedBrush.cs @@ -43,7 +43,7 @@ namespace MCGalaxy.Drawing.Brushes { public static Brush Process(BrushArgs args) { if (args.Message == "") - return new StripedBrush(args.Type, args.ExtType, 0, 0); + return new StripedBrush(args.Block, args.ExtBlock, 0, 0); string[] parts = args.Message.Split(' '); byte extBlock1;