From 2848d8f89c3d045150a73d291afbf648a11c17f4 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 19 May 2016 21:58:27 +1000 Subject: [PATCH] Make /torus work like fcraft's one (Thanks SkinnyGamer), closes #133. --- Commands/building/CmdSphere.cs | 13 +++++++------ Commands/building/CmdTorus.cs | 21 ++++++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Commands/building/CmdSphere.cs b/Commands/building/CmdSphere.cs index b4f3447d9..ae2d99cf7 100644 --- a/Commands/building/CmdSphere.cs +++ b/Commands/building/CmdSphere.cs @@ -42,11 +42,6 @@ namespace MCGalaxy.Commands { RevertAndClearState(p, x, y, z); CatchPos cpos = (CatchPos)p.blockchangeObject; GetRealBlock(type, extType, p, ref cpos); - - int dx = cpos.x - x, dy = cpos.y - y, dz = cpos.z - z; - int radius = (int)Math.Sqrt(dx * dx + dy * dy + dz * dz); - Vec3S32[] marks = { new Vec3S32(cpos.x - radius, cpos.y - radius, cpos.z - radius), - new Vec3S32(cpos.x + radius, cpos.y + radius, cpos.z + radius) }; DrawOp op = null; Func constructor = null; @@ -62,6 +57,11 @@ namespace MCGalaxy.Commands { int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1; Brush brush = GetBrush(p, cpos, brushOffset, constructor); if (brush == null) return; + + int dx = cpos.x - x, dy = cpos.y - y, dz = cpos.z - z; + int R = (int)Math.Sqrt(dx * dx + dy * dy + dz * dz); + Vec3S32[] marks = { new Vec3S32(cpos.x - R, cpos.y - R, cpos.z - R), + new Vec3S32(cpos.x + R, cpos.y + R, cpos.z + R) }; if (!DrawOp.DoDrawOp(op, brush, p, marks)) return; @@ -71,7 +71,8 @@ namespace MCGalaxy.Commands { public override void Help(Player p) { Player.Message(p, "%T/sphere [brush args] "); - Player.Message(p, "%HCreates a sphere, using the first point as the centre, and the second point as the radius."); + Player.Message(p, "%HCreates a sphere, with the first point as the centre, " + + "and second being the radius."); Player.Message(p, " %HFor help about brushes, type %T/help brush%H."); Player.Message(p, " %HModes: &fsolid/hollow"); } diff --git a/Commands/building/CmdTorus.cs b/Commands/building/CmdTorus.cs index 549cbd6ab..0c9faed36 100644 --- a/Commands/building/CmdTorus.cs +++ b/Commands/building/CmdTorus.cs @@ -26,33 +26,40 @@ namespace MCGalaxy.Commands { public override string name { get { return "torus"; } } public override string shortcut { get { return "tor"; } } + public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("donut"), new CommandAlias("bagel") }; } } + protected override string PlaceMessage { get { return "Place a block for the centre, then another for the radius."; } } + protected override void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { RevertAndClearState(p, x, y, z); CatchPos cpos = (CatchPos)p.blockchangeObject; GetRealBlock(type, extType, p, ref cpos); + DrawOp drawOp = new TorusDrawOp(); Brush brush = GetBrush(p, cpos, 0); if (brush == null) return; + + int dx = cpos.x - x, dy = cpos.y - y, dz = cpos.z - z; + int horR = (int)Math.Sqrt(dx * dx + dz * dz), verR = Math.Abs(dy); + Vec3S32[] marks = { new Vec3S32(cpos.x - horR, cpos.y - verR, cpos.z - horR), + new Vec3S32(cpos.x + horR, cpos.y + verR, cpos.z + horR) }; - if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z)) + if (!DrawOp.DoDrawOp(drawOp, brush, p, marks)) return; if (p.staticCommands) p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); } - protected override DrawMode ParseMode(string msg) { - return DrawMode.normal; - } + protected override DrawMode ParseMode(string msg) { return DrawMode.normal; } public override void Help(Player p) { Player.Message(p, "%T/torus [brush args]"); - Player.Message(p, "%HDraws a torus(circular tube) between two points."); + Player.Message(p, "%HDraws a torus(circular tube), with the first point as the centre, " + + "and second being the radius."); Player.Message(p, " %HFor help about brushes, type %T/help brush%H."); - Player.Message(p, " %HNote: radius of tube itself is calculated based on " + - "vertical difference between the two corners."); + Player.Message(p, " %HNote: radius of the tube itself is the vertical difference between the two points."); } } }