diff --git a/Commands/building/CmdCuboid.cs b/Commands/building/CmdCuboid.cs index 0898d3cfe..1e48fa825 100644 --- a/Commands/building/CmdCuboid.cs +++ b/Commands/building/CmdCuboid.cs @@ -43,7 +43,8 @@ namespace MCGalaxy.Commands case DrawMode.walls: drawOp = new CuboidWallsDrawOp(); break; case DrawMode.holes: - drawOp = new CuboidHolesDrawOp(); break; + drawOp = new CuboidDrawOp(); + brush = new CheckeredBrush(cpos.type, cpos.extType, 0, 0); break; case DrawMode.wire: drawOp = new CuboidWireframeDrawOp(); break; case DrawMode.random: diff --git a/Commands/building/CmdPaste.cs b/Commands/building/CmdPaste.cs index 7905e5125..5b63f2f24 100644 --- a/Commands/building/CmdPaste.cs +++ b/Commands/building/CmdPaste.cs @@ -17,6 +17,7 @@ */ using System; using MCGalaxy.Drawing; +using MCGalaxy.Drawing.Brushes; using MCGalaxy.Drawing.Ops; namespace MCGalaxy.Commands { @@ -58,9 +59,9 @@ namespace MCGalaxy.Commands { ((PasteDrawOp)op).CopyState = p.CopyBuffer; string[] args = cpos.message.Split(' '); if (args[0].ToLower() == "not") - ((PasteDrawOp)op).Exclude = ReplaceCmd.GetBlocks(p, 1, args.Length, args); + ((PasteDrawOp)op).Exclude = ReplaceBrush.GetBlocks(p, 1, args.Length, args); else - ((PasteDrawOp)op).Include = ReplaceCmd.GetBlocks(p, 0, args.Length, args); + ((PasteDrawOp)op).Include = ReplaceBrush.GetBlocks(p, 0, args.Length, args); } if (!DrawOp.DoDrawOp(op, null, p, (ushort)offX, (ushort)offY, (ushort)offZ, 0, 0, 0)) diff --git a/Commands/building/CmdReplace.cs b/Commands/building/CmdReplace.cs deleted file mode 100644 index b59e36a71..000000000 --- a/Commands/building/CmdReplace.cs +++ /dev/null @@ -1,68 +0,0 @@ -/* - Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/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 MCGalaxy.Drawing.Ops; - -namespace MCGalaxy.Commands { - - public sealed class CmdReplace : ReplaceCmd { - - public override string name { get { return "replace"; } } - public override string shortcut { get { return "r"; } } - public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } - - protected override void BeginReplace(Player p, ExtBlock[] toAffect, ExtBlock target) { - CatchPos cpos = default(CatchPos); - cpos.toAffect = toAffect; - cpos.target = target; - p.blockchangeObject = cpos; - - Player.SendMessage(p, "Place two blocks to determine the edges."); - p.ClearBlockchange(); - p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); - } - - public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { - RevertAndClearState(p, x, y, z); - CatchPos bp = (CatchPos)p.blockchangeObject; - bp.x = x; bp.y = y; bp.z = z; - p.blockchangeObject = bp; - p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2); - } - - public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { - RevertAndClearState(p, x, y, z); - CatchPos cpos = (CatchPos)p.blockchangeObject; - ReplaceDrawOp drawOp = new ReplaceDrawOp(); - drawOp.ToReplace = cpos.toAffect; - drawOp.Target = cpos.target; - - if (!DrawOp.DoDrawOp(drawOp, null, p, cpos.x, cpos.y, cpos.z, x, y, z)) - return; - if (p.staticCommands) - p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); - } - - struct CatchPos { public ushort x, y, z; public ExtBlock[] toAffect; public ExtBlock target; } - - public override void Help(Player p) { - Player.SendMessage(p, "/replace [block] [block2].. [new] - replace block with new inside a selected cuboid"); - Player.SendMessage(p, "If more than one [block] is specified, they will all be replaced."); - } - } -} diff --git a/Commands/building/CmdReplaceAll.cs b/Commands/building/CmdReplaceAll.cs deleted file mode 100644 index e5f23038a..000000000 --- a/Commands/building/CmdReplaceAll.cs +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/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 MCGalaxy.Drawing.Ops; - -namespace MCGalaxy.Commands { - - public sealed class CmdReplaceAll : ReplaceCmd { - - public override string name { get { return "replaceall"; } } - public override string shortcut { get { return "ra"; } } - public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } - - protected override void BeginReplace(Player p, ExtBlock[] toAffect, ExtBlock target) { - ushort x2 = (ushort)(p.level.Width - 1); - ushort y2 = (ushort)(p.level.Height - 1); - ushort z2 = (ushort)(p.level.Length - 1); - ReplaceDrawOp drawOp = new ReplaceDrawOp(); - drawOp.ToReplace = toAffect; - drawOp.Target = target; - - if (!DrawOp.DoDrawOp(drawOp, null, p, 0, 0, 0, x2, y2, z2)) - return; - Player.SendMessage(p, "&4/replaceall finished!"); - } - - public override void Help(Player p) { - Player.SendMessage(p, "/ra [block] [block2].. [new] - Replaces all of [block] with [new] in a map"); - Player.SendMessage(p, "If more than one [block] is specified, they will all be replaced."); - } - } -} diff --git a/Commands/building/CmdReplaceNot.cs b/Commands/building/CmdReplaceNot.cs deleted file mode 100644 index 7f5ea0f4b..000000000 --- a/Commands/building/CmdReplaceNot.cs +++ /dev/null @@ -1,67 +0,0 @@ -/* - Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/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 MCGalaxy.Drawing.Ops; - -namespace MCGalaxy.Commands { - - public sealed class CmdReplaceNot : ReplaceCmd { - - public override string name { get { return "replacenot"; } } - public override string shortcut { get { return "rn"; } } - public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } - - protected override void BeginReplace(Player p, ExtBlock[] toAffect, ExtBlock target) { - CatchPos cpos = default(CatchPos); - cpos.toAffect = toAffect; - cpos.target = target; - p.blockchangeObject = cpos; - - Player.SendMessage(p, "Place two blocks to determine the edges."); - p.ClearBlockchange(); - p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); - } - - public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { - RevertAndClearState(p, x, y, z); - CatchPos bp = (CatchPos)p.blockchangeObject; - bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp; - p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2); - } - - public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { - RevertAndClearState(p, x, y, z); - CatchPos cpos = (CatchPos)p.blockchangeObject; - ReplaceNotDrawOp drawOp = new ReplaceNotDrawOp(); - drawOp.ToReplace = cpos.toAffect; - drawOp.Target = cpos.target; - - if (!DrawOp.DoDrawOp(drawOp, null, p, cpos.x, cpos.y, cpos.z, x, y, z)) - return; - if (p.staticCommands) - p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); - } - - struct CatchPos { public ushort x, y, z; public ExtBlock[] toAffect; public ExtBlock target; } - - public override void Help(Player p) { - Player.SendMessage(p, "/rn [block] [block2].. [new] - replace everything but [block] with [new] inside a selected cuboid"); - Player.SendMessage(p, "If multiple [block]s are specified they will all be ignored."); - } - } -} diff --git a/Commands/building/ReplaceCmd.cs b/Commands/building/ReplaceCmd.cs index 2e395626c..cee3f4e9d 100644 --- a/Commands/building/ReplaceCmd.cs +++ b/Commands/building/ReplaceCmd.cs @@ -1,5 +1,5 @@ -/* - Copyright 2015 MCGalaxy team +/* + Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) Dual-licensed under the Educational Community License, Version 2.0 and the GNU General Public License, Version 3 (the "Licenses"); you may @@ -16,42 +16,100 @@ permissions and limitations under the Licenses. */ using System; -using System.Collections.Generic; +using MCGalaxy.Drawing.Brushes; using MCGalaxy.Drawing.Ops; namespace MCGalaxy.Commands { - public abstract class ReplaceCmd : Command { + public class CmdReplace : Command { + public override string name { get { return "replace"; } } + public override string shortcut { get { return "r"; } } public override string type { get { return CommandTypes.Building; } } public override bool museumUsable { get { return false; } } + public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } public override void Use(Player p, string message) { - string[] parts = message.Split(' '); - for (int i = 0; i < parts.Length; i++) - parts[i] = parts[i].ToLower(); - if (parts.Length < 2) { Help(p); return; } + CatchPos cpos = default(CatchPos); + cpos.message = message.ToLower(); + p.blockchangeObject = cpos; + + Player.SendMessage(p, "Place two blocks to determine the edges."); + p.ClearBlockchange(); + p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); + } + + void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { + RevertAndClearState(p, x, y, z); + CatchPos bp = (CatchPos)p.blockchangeObject; + bp.x = x; bp.y = y; bp.z = z; + p.blockchangeObject = bp; + p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2); + } + + void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { + RevertAndClearState(p, x, y, z); + CatchPos cpos = (CatchPos)p.blockchangeObject; + BrushArgs args = new BrushArgs(p, cpos.message, type, extType); + Brush brush = ReplaceNot ? ReplaceNotBrush.Process(args) : ReplaceBrush.Process(args); + if (brush == null) return; + + DrawOp drawOp = new CuboidDrawOp(); + if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z)) + return; + if (p.staticCommands) + p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); + } + + protected virtual bool ReplaceNot { get { return false; } } + + struct CatchPos { public ushort x, y, z; public string message; } + + public override void Help(Player p) { + Player.SendMessage(p, "/replace [block] [block2].. [new] - replace block with new inside a selected cuboid"); + Player.SendMessage(p, "If more than one [block] is specified, they will all be replaced."); + } + } + + public sealed class CmdReplaceNot : CmdReplace { + + public override string name { get { return "replacenot"; } } + public override string shortcut { get { return "rn"; } } - ExtBlock[] toAffect = GetBlocks(p, 0, parts.Length - 1, parts); - ExtBlock target; - target.Type = DrawCmd.GetBlock(p, parts[parts.Length - 1], out target.ExtType); - if (target.Type == Block.Zero) return; - BeginReplace(p, toAffect, target); - } + protected override bool ReplaceNot { get { return true; } } - internal static ExtBlock[] GetBlocks(Player p, int start, int max, string[] parts) { - ExtBlock[] blocks = new ExtBlock[max - start]; - for (int j = 0; j < blocks.Length; j++) - blocks[j].Type = Block.Zero; - for (int j = 0; start < max; start++, j++ ) { - byte extType = 0; - byte type = DrawCmd.GetBlock(p, parts[start], out extType); - if (type == Block.Zero) continue; - blocks[j].Type = type; blocks[j].ExtType = extType; - } - return blocks; + public override void Help(Player p) { + Player.SendMessage(p, "/rn [block] [block2].. [new] - replace everything but [block] with [new] inside a selected cuboid"); + Player.SendMessage(p, "If multiple [block]s are specified they will all be ignored."); } + } + + public sealed class CmdReplaceAll : Command { - protected abstract void BeginReplace(Player p, ExtBlock[] toAffect, ExtBlock target); + public override string name { get { return "replaceall"; } } + public override string shortcut { get { return "ra"; } } + public override string type { get { return CommandTypes.Building; } } + public override bool museumUsable { get { return false; } } + public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } + + public override void Use(Player p, string message) { + ushort x2 = (ushort)(p.level.Width - 1); + ushort y2 = (ushort)(p.level.Height - 1); + ushort z2 = (ushort)(p.level.Length - 1); + + BrushArgs args = new BrushArgs(p, message.ToLower(), 0, 0); + Brush brush = ReplaceBrush.Process(args); + if (brush == null) return; + + DrawOp drawOp = new CuboidDrawOp(); + if (!DrawOp.DoDrawOp(drawOp, brush, p, 0, 0, 0, x2, y2, z2)) + return; + Player.SendMessage(p, "&4/replaceall finished!"); + } + + public override void Help(Player p) { + Player.SendMessage(p, "/ra [block] [block2].. [new] - Replaces all of [block] with [new] in a map"); + Player.SendMessage(p, "If more than one [block] is specified, they will all be replaced."); + } } } diff --git a/Drawing/Brushes/ReplaceBrush.cs b/Drawing/Brushes/ReplaceBrush.cs index 930d5b94e..c7cf633ef 100644 --- a/Drawing/Brushes/ReplaceBrush.cs +++ b/Drawing/Brushes/ReplaceBrush.cs @@ -84,7 +84,7 @@ namespace MCGalaxy.Drawing.Brushes { this.exclude = include; this.target = target; } - public override string Name { get { return "Replace"; } } + public override string Name { get { return "ReplaceNot"; } } public static Brush Process(BrushArgs args) { string[] parts = args.Message.Split(' '); diff --git a/Drawing/DrawOps/CuboidDrawOp.cs b/Drawing/DrawOps/CuboidDrawOp.cs index f56cd2048..2b9bcd13f 100644 --- a/Drawing/DrawOps/CuboidDrawOp.cs +++ b/Drawing/DrawOps/CuboidDrawOp.cs @@ -39,33 +39,6 @@ namespace MCGalaxy.Drawing.Ops { } } - public class CuboidHolesDrawOp : DrawOp { - - public override string Name { get { return "Cuboid Holes"; } } - - public override int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) { - return (x2 - x1 + 1) * (y2 - y1 + 1) * (z2 - z1 + 1); - } - - public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2, - ushort y2, ushort z2, Player p, Level lvl, Brush brush) { - for (ushort y = y1; y <= y2; y++) - for (ushort z = z1; z <= z2; z++) - { - int i = (y & 1) == 0 ? 0 : 1; - if ((z & 1) == 0) i++; - - for (ushort x = x1; x <= x2; x++) { - if ((i & 1) == 0) - PlaceBlock(p, lvl, x, y, z, brush); - else - PlaceBlock(p, lvl, x, y, z, Block.air, 0); - i++; - } - } - } - } - public class CuboidHollowsDrawOp : DrawOp { public override string Name { get { return "Cuboid Hollow"; } } diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index 974f61e8f..fe76a2d5c 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -127,9 +127,7 @@ - - - + @@ -141,7 +139,6 @@ -