From 75108aac21c1c4cee185dfab2c228f1120626d03 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 27 Jun 2016 14:40:53 +1000 Subject: [PATCH] And make even more commands use selection methods. if (BlockChange != null) no longer adds an entry to the BlockDB. --- Commands/building/CmdCopy.cs | 80 +++++++++++--------------- Commands/building/CmdCuboid.cs | 2 +- Commands/building/CmdDraw.cs | 2 +- Commands/building/CmdDrill.cs | 47 ++++++--------- Commands/building/CmdFill.cs | 2 +- Commands/building/CmdLine.cs | 2 +- Commands/building/CmdPaste.cs | 37 +++++------- Commands/building/CmdPyramid.cs | 12 ++-- Commands/building/CmdReplaceBrush.cs | 1 - Commands/building/CmdRestartPhysics.cs | 52 ++++++----------- Commands/building/CmdSphere.cs | 2 +- Commands/building/CmdSpheroid.cs | 2 +- Commands/building/CmdTorus.cs | 2 +- Commands/building/CmdTree.cs | 30 ++++------ Commands/building/CmdTriangle.cs | 2 +- Commands/building/CmdWrite.cs | 1 - Commands/building/DrawCmd.cs | 5 -- Player/Player.Fields.cs | 3 +- Player/Player.Handlers.cs | 13 +---- Player/Player.cs | 1 + 20 files changed, 114 insertions(+), 184 deletions(-) diff --git a/Commands/building/CmdCopy.cs b/Commands/building/CmdCopy.cs index 02baf83e6..bfe9c81f2 100644 --- a/Commands/building/CmdCopy.cs +++ b/Commands/building/CmdCopy.cs @@ -74,45 +74,34 @@ namespace MCGalaxy.Commands.Building { } void HandleOther(Player p, string opt, string[] parts, int allowoffset) { - CatchPos cpos = default(CatchPos); - p.copyoffset[0] = 0; p.copyoffset[1] = 0; p.copyoffset[2] = 0; - cpos.allowoffset = allowoffset; + CopyArgs cArgs = default(CopyArgs); + p.copyoffset = default(Vec3S32); + cArgs.allowoffset = allowoffset; if (opt == "cut") { - cpos.type = 1; + cArgs.type = 1; } else if (opt == "air") { - cpos.type = 2; + cArgs.type = 2; } else if (!String.IsNullOrEmpty(opt)) { Help(p); return; } - p.blockchangeObject = cpos; Player.Message(p, "Place two blocks to determine the edges."); - p.ClearBlockchange(); - p.Blockchange += PlacedMark1; + p.MakeSelection(2, cArgs, DoCopy); } - void PlacedMark1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { - RevertAndClearState(p, x, y, z); - CatchPos bp = (CatchPos)p.blockchangeObject; - p.copystart[0] = x; p.copystart[1] = y; p.copystart[2] = z; - - bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp; - p.Blockchange += PlacedMark2; - } - - void PlacedMark2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { - RevertAndClearState(p, x, y, z); - CatchPos cpos = (CatchPos)p.blockchangeObject; - ushort minX = (ushort)Math.Min(x, cpos.x), maxX = (ushort)Math.Max(x, cpos.x); - ushort minY = (ushort)Math.Min(y, cpos.y), maxY = (ushort)Math.Max(y, cpos.y); - ushort minZ = (ushort)Math.Min(z, cpos.z), maxZ = (ushort)Math.Max(z, cpos.z); + bool DoCopy(Player p, Vec3S32[] m, object state, byte type, byte extType) { + p.copystart = m[0]; + CopyArgs cArgs = (CopyArgs)state; + ushort minX = (ushort)Math.Min(m[0].X, m[1].X), maxX = (ushort)Math.Max(m[0].X, m[1].X); + ushort minY = (ushort)Math.Min(m[0].Y, m[1].Y), maxY = (ushort)Math.Max(m[0].Y, m[1].Y); + ushort minZ = (ushort)Math.Min(m[0].Z, m[1].Z), maxZ = (ushort)Math.Max(m[0].Z, m[1].Z); - CopyState state = new CopyState(minX, minY, minZ, maxX - minX + 1, + CopyState cState = new CopyState(minX, minY, minZ, maxX - minX + 1, maxY - minY + 1, maxZ - minZ + 1); - state.SetOrigin(cpos.x, cpos.y, cpos.z); - int index = 0; state.UsedBlocks = 0; - state.PasteAir = cpos.type == 2; + cState.SetOrigin(m[0].X, m[0].Y, m[0].Z); + int index = 0; cState.UsedBlocks = 0; + cState.PasteAir = cArgs.type == 2; for (ushort yy = minY; yy <= maxY; ++yy) for (ushort zz = minZ; zz <= maxZ; ++zz) @@ -123,22 +112,22 @@ namespace MCGalaxy.Commands.Building { if (b == Block.custom_block) extB = p.level.GetExtTile(xx, yy, zz); - if (b != Block.air || state.PasteAir) - state.UsedBlocks++; - state.Blocks[index] = b; - state.ExtBlocks[index] = extB; + if (b != Block.air || cState.PasteAir) + cState.UsedBlocks++; + cState.Blocks[index] = b; + cState.ExtBlocks[index] = extB; index++; } - if (state.UsedBlocks > p.group.maxBlocks) { + if (cState.UsedBlocks > p.group.maxBlocks) { Player.Message(p, "You tried to copy {0} blocks. You cannot copy more than {1} blocks.", - state.UsedBlocks, p.group.maxBlocks); - state.Blocks = null; state.ExtBlocks = null; state = null; - return; + cState.UsedBlocks, p.group.maxBlocks); + cState.Blocks = null; cState.ExtBlocks = null; cState = null; + return false; } - p.CopyBuffer = state; - if (cpos.type == 1) { + p.CopyBuffer = cState; + if (cArgs.type == 1) { DrawOp op = new CuboidDrawOp(); Brush brush = new SolidBrush(Block.air, 0); Vec3S32[] marks = { new Vec3S32(minX, minY, minZ), new Vec3S32(maxX, maxY, maxZ) }; @@ -146,21 +135,20 @@ namespace MCGalaxy.Commands.Building { } string format = "Copied &a{0} %Sblocks." + - (state.PasteAir ? "" : " To also copy air blocks, use %T/copy air"); - Player.Message(p, format, state.UsedBlocks); - if (cpos.allowoffset != -1) { + (cState.PasteAir ? "" : " To also copy air blocks, use %T/copy air"); + Player.Message(p, format, cState.UsedBlocks); + if (cArgs.allowoffset != -1) { Player.Message(p, "Place a block to determine where to paste from"); p.Blockchange += Blockchange3; } + return false; } void Blockchange3(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { RevertAndClearState(p, x, y, z); - CatchPos cpos = (CatchPos)p.blockchangeObject; - - p.copyoffset[0] = (p.copystart[0] - x); - p.copyoffset[1] = (p.copystart[1] - y); - p.copyoffset[2] = (p.copystart[2] - z); + p.copyoffset.X = p.copystart.X - x; + p.copyoffset.Y = p.copystart.Y - y; + p.copyoffset.Z = p.copystart.Z - z; } void SaveCopy(Player p, string file) { @@ -206,7 +194,7 @@ namespace MCGalaxy.Commands.Building { Player.Message(p, "Loaded copy as " + file); } - struct CatchPos { public ushort x, y, z; public int type; public int allowoffset; } + struct CopyArgs { public int type, allowoffset; } public override void Help(Player p) { Player.Message(p, "/copy - Copies the blocks in an area."); diff --git a/Commands/building/CmdCuboid.cs b/Commands/building/CmdCuboid.cs index 39f78647a..69ae1b337 100644 --- a/Commands/building/CmdCuboid.cs +++ b/Commands/building/CmdCuboid.cs @@ -32,7 +32,7 @@ namespace MCGalaxy.Commands.Building { protected override bool DoDraw(Player p, Vec3S32[] marks, object state, byte type, byte extType) { DrawArgs cpos = (DrawArgs)state; - GetRealBlock(type, extType, p, ref cpos); + cpos.type = type; cpos.extType = extType; DrawOp op = null; Func constructor = null; diff --git a/Commands/building/CmdDraw.cs b/Commands/building/CmdDraw.cs index 0f1c2a527..19e6b96de 100644 --- a/Commands/building/CmdDraw.cs +++ b/Commands/building/CmdDraw.cs @@ -44,7 +44,7 @@ namespace MCGalaxy.Commands.Building { protected override bool DoDraw(Player p, Vec3S32[] m, object state, byte type, byte extType) { DrawArgs cpos = (DrawArgs)state; - GetRealBlock(type, extType, p, ref cpos); + cpos.type = type; cpos.extType = extType; AdvDrawOp op = null; switch (cpos.mode) { case DrawMode.cone: diff --git a/Commands/building/CmdDrill.cs b/Commands/building/CmdDrill.cs index 9ec6d5e89..4079b5eae 100644 --- a/Commands/building/CmdDrill.cs +++ b/Commands/building/CmdDrill.cs @@ -18,7 +18,7 @@ using System.Collections.Generic; namespace MCGalaxy.Commands.Building { - public sealed class CmdDrill : Command { + public sealed class CmdDrill : Command { public override string name { get { return "drill"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Building; } } @@ -26,39 +26,31 @@ namespace MCGalaxy.Commands.Building { public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override void Use(Player p, string message) { - CatchPos cpos = default(CatchPos); - cpos.dist = 20; - - if (message != "" && !int.TryParse(message, out cpos.dist)) { - Help(p); return; - } - - p.blockchangeObject = cpos; + int dist = 20; + if (message != "" && !int.TryParse(message, out dist)) { Help(p); return; } Player.Message(p, "Destroy the block you wish to drill."); - p.ClearBlockchange(); - p.Blockchange += Blockchange1; + p.MakeSelection(1, dist, DoDrill); } - void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { - if (!p.staticCommands) p.ClearBlockchange(); - CatchPos cpos = (CatchPos)p.blockchangeObject; + bool DoDrill(Player p, Vec3S32[] marks, object state, byte type, byte extType) { + ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z; type = p.level.GetTile(x, y, z); extType = 0; - if (type == Block.custom_block) extType = p.level.GetExtTile(x, y, z); - p.RevertBlock(x, y, z); + if (type == Block.custom_block) + extType = p.level.GetExtTile(x, y, z); + int dist = (int)state; - int diffX = 0, diffZ = 0; - - if (p.rot[0] <= 32 || p.rot[0] >= 224) { diffZ = -1; } - else if (p.rot[0] <= 96) { diffX = 1; } - else if (p.rot[0] <= 160) { diffZ = 1; } - else diffX = -1; + int dx = 0, dz = 0; + if (p.rot[0] <= 32 || p.rot[0] >= 224) { dz = -1; } + else if (p.rot[0] <= 96) { dx = 1; } + else if (p.rot[0] <= 160) { dz = 1; } + else dx = -1; List buffer = new List(); int depth = 0; Level lvl = p.level; - if (diffX != 0) { - for (ushort xx = x; depth < cpos.dist; xx += (ushort)diffX) + if (dx != 0) { + for (ushort xx = x; depth < dist; xx += (ushort)dx) { for (ushort yy = (ushort)(y - 1); yy <= (ushort)(y + 1); yy++) for (ushort zz = (ushort)(z - 1); zz <= (ushort)(z + 1); zz++) @@ -68,7 +60,7 @@ namespace MCGalaxy.Commands.Building { depth++; } } else { - for (ushort zz = z; depth < cpos.dist; zz += (ushort)diffZ) + for (ushort zz = z; depth < dist; zz += (ushort)dz) { for (ushort yy = (ushort)(y - 1); yy <= (ushort)(y + 1); yy++) for (ushort xx = (ushort)(x - 1); xx <= (ushort)(x + 1); xx++) @@ -82,7 +74,7 @@ namespace MCGalaxy.Commands.Building { if (buffer.Count > p.group.maxBlocks) { Player.Message(p, "You tried to drill " + buffer.Count + " blocks."); Player.Message(p, "You cannot drill more than " + p.group.maxBlocks + "."); - return; + return false; } foreach (int index in buffer) { @@ -95,9 +87,8 @@ namespace MCGalaxy.Commands.Building { if (sameBlock) p.level.UpdateBlock(p, x, y, z, Block.air, 0); } Player.Message(p, "Drilled " + buffer.Count + " blocks."); + return true; } - - struct CatchPos { public int dist; } public override void Help(Player p) { Player.Message(p, "%T/drill [distance]"); diff --git a/Commands/building/CmdFill.cs b/Commands/building/CmdFill.cs index 9ffe50f90..36b6b4c6d 100644 --- a/Commands/building/CmdFill.cs +++ b/Commands/building/CmdFill.cs @@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.Building { if (oldType == Block.custom_block) oldExtType = p.level.GetExtTile(x, y, z); - GetRealBlock(type, extType, p, ref cpos); + cpos.type = type; cpos.extType = extType; if (!Block.canPlace(p, oldType) && !Block.BuildIn(oldType)) { Player.Message(p, "Cannot fill with that."); return false; } diff --git a/Commands/building/CmdLine.cs b/Commands/building/CmdLine.cs index b00496d3a..02b4573ab 100644 --- a/Commands/building/CmdLine.cs +++ b/Commands/building/CmdLine.cs @@ -54,7 +54,7 @@ namespace MCGalaxy.Commands.Building { protected override bool DoDraw(Player p, Vec3S32[] m, object state, byte type, byte extType) { DrawArgs cpos = (DrawArgs)state; - GetRealBlock(type, extType, p, ref cpos); + cpos.type = type; cpos.extType = extType; if (cpos.mode == DrawMode.straight) { int dx = Math.Abs(m[0].X - m[1].X), dy = Math.Abs(m[0].Y - m[1].Y), dz = Math.Abs(m[0].Z - m[1].Z); diff --git a/Commands/building/CmdPaste.cs b/Commands/building/CmdPaste.cs index 2d07679fd..ca3871bfa 100644 --- a/Commands/building/CmdPaste.cs +++ b/Commands/building/CmdPaste.cs @@ -28,49 +28,38 @@ namespace MCGalaxy.Commands.Building { public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } public override CommandAlias[] Aliases { - get { return new[] { new CommandAlias("pn", "not") }; } + get { return new[] { new CommandAlias("pastenot", "not"), new CommandAlias("pn", "not") }; } } public override void Use(Player p, string message) { if (p.CopyBuffer == null) { Player.Message(p, "You haven't copied anything yet"); return; } - - CatchPos cpos = default(CatchPos); - cpos.message = message; - p.blockchangeObject = cpos; Player.Message(p, "Place a block in the corner of where you want to paste."); - p.ClearBlockchange(); - p.Blockchange += PlacedOrigin; + p.MakeSelection(1, message, DoPaste); } - void PlacedOrigin(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { - CatchPos cpos = (CatchPos)p.blockchangeObject; - RevertAndClearState(p, x, y, z); - int x1 = p.copyoffset[0] + x, y1 = p.copyoffset[1] + y, z1 = p.copyoffset[2] + z; - CopyState state = p.CopyBuffer; - if (state.X != state.OriginX) x1 -= (state.Width - 1); - if (state.Y != state.OriginY) y1 -= (state.Height - 1); - if (state.Z != state.OriginZ) z1 -= (state.Length - 1); + bool DoPaste(Player p, Vec3S32[] m, object state, byte type, byte extType) { + string message = (string)state; + m[0] += p.copyoffset; + CopyState cState = p.CopyBuffer; + if (cState.X != cState.OriginX) m[0].X -= (cState.Width - 1); + if (cState.Y != cState.OriginY) m[0].Y -= (cState.Height - 1); + if (cState.Z != cState.OriginZ) m[0].Z -= (cState.Length - 1); DrawOp op; - if (cpos.message == "") { + if (message == "") { op = new SimplePasteDrawOp(); ((SimplePasteDrawOp)op).CopyState = p.CopyBuffer; } else { op = new PasteDrawOp(); ((PasteDrawOp)op).CopyState = p.CopyBuffer; - string[] args = cpos.message.Split(' '); + string[] args = message.Split(' '); if (args[0].CaselessEq("not")) ((PasteDrawOp)op).Exclude = ReplaceBrush.GetBlocks(p, 1, args.Length, args); else ((PasteDrawOp)op).Include = ReplaceBrush.GetBlocks(p, 0, args.Length, args); } - Vec3S32[] marks = { new Vec3S32(x1, y1, z1) }; - if (!DrawOp.DoDrawOp(op, null, p, marks)) - return; - if (p.staticCommands) p.Blockchange += PlacedOrigin; - } - - struct CatchPos { public string message; } + return DrawOp.DoDrawOp(op, null, p, m); + } public override void Help(Player p) { Player.Message(p, "/paste - Pastes the stored copy."); diff --git a/Commands/building/CmdPyramid.cs b/Commands/building/CmdPyramid.cs index fa809358e..7edaacc6a 100644 --- a/Commands/building/CmdPyramid.cs +++ b/Commands/building/CmdPyramid.cs @@ -27,8 +27,8 @@ namespace MCGalaxy.Commands.Building { protected override bool DoDraw(Player p, Vec3S32[] marks, object state, byte type, byte extType) { DrawArgs cpos = (DrawArgs)state; - GetRealBlock(type, extType, p, ref cpos); - DrawOp drawOp = null; + cpos.type = type; cpos.extType = extType; + DrawOp op = null; int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1; Brush brush = GetBrush(p, cpos, brushOffset); if (brush == null) return false; @@ -40,13 +40,13 @@ namespace MCGalaxy.Commands.Building { switch (cpos.mode) { case DrawMode.solid: case DrawMode.normal: - drawOp = new PyramidSolidDrawOp(); break; + op = new PyramidSolidDrawOp(); break; case DrawMode.hollow: - drawOp = new PyramidHollowDrawOp(); break; + op = new PyramidHollowDrawOp(); break; case DrawMode.reverse: - drawOp = new PyramidReverseDrawOp(); break; + op = new PyramidReverseDrawOp(); break; } - return DrawOp.DoDrawOp(drawOp, brush, p, marks); + return DrawOp.DoDrawOp(op, brush, p, marks); } protected override DrawMode ParseMode(string msg) { diff --git a/Commands/building/CmdReplaceBrush.cs b/Commands/building/CmdReplaceBrush.cs index 9375cfc80..cb2438dcd 100644 --- a/Commands/building/CmdReplaceBrush.cs +++ b/Commands/building/CmdReplaceBrush.cs @@ -41,7 +41,6 @@ namespace MCGalaxy.Commands.Building { } bool DoReplace(Player p, Vec3S32[] marks, object state, byte type, byte extType) { - type = type < 128 ? p.bindings[type] : type; string[] parts = ((string)state).SplitSpaces(3); if (parts.Length < 2) { Help(p); return false; } diff --git a/Commands/building/CmdRestartPhysics.cs b/Commands/building/CmdRestartPhysics.cs index 76cb835ba..950b6979c 100644 --- a/Commands/building/CmdRestartPhysics.cs +++ b/Commands/building/CmdRestartPhysics.cs @@ -29,37 +29,34 @@ namespace MCGalaxy.Commands.Building { public CmdRestartPhysics() { } public override void Use(Player p, string message) { - CatchPos cpos = default(CatchPos); + PhysicsArgs extraInfo = default(PhysicsArgs); message = message.ToLower(); - if (message != "" && !ParseArgs(p, message, ref cpos)) return; + if (message != "" && !ParseArgs(p, message, ref extraInfo)) return; - p.blockchangeObject = cpos; Player.Message(p, "Place two blocks to determine the edges."); - p.ClearBlockchange(); - p.Blockchange += PlacedMark1; + p.MakeSelection(2, extraInfo, DoRestart); } - bool ParseArgs(Player p, string message, ref CatchPos cpos) { + bool ParseArgs(Player p, string message, ref PhysicsArgs extraInfo) { string[] parts = message.Split(' '); if (parts.Length % 2 == 1) { Player.Message(p, "Number of parameters must be even"); Help(p); return false; - } - PhysicsArgs args = default(PhysicsArgs); + } byte type = 0, value = 0; if (parts.Length >= 2) { if (!Parse(p, parts[0], parts[1], ref type, ref value)) return false; - args.Type1 = type; args.Value1 = value; + extraInfo.Type1 = type; extraInfo.Value1 = value; } if (parts.Length >= 4) { if (!Parse(p, parts[2], parts[3], ref type, ref value)) return false; - args.Type2 = type; args.Value2 = value; + extraInfo.Type2 = type; extraInfo.Value2 = value; } if (parts.Length >= 6) { Player.Message(p, "You can only use up to two types of physics."); return false; } - cpos.extraInfo = args; return true; + return true; } bool Parse(Player p, string name, string arg, ref byte type, ref byte value) { @@ -90,47 +87,36 @@ namespace MCGalaxy.Commands.Building { return false; } - void PlacedMark1(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 += PlacedMark2; - } - - void PlacedMark2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { - RevertAndClearState(p, x, y, z); - CatchPos cpos = (CatchPos)p.blockchangeObject; + bool DoRestart(Player p, Vec3S32[] m, object state, byte type, byte extType) { + PhysicsArgs extraInfo = (PhysicsArgs)state; List buffer = new List(); - for (ushort yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy) - for (ushort zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz) - for (ushort xx = Math.Min(cpos.x, x); xx <= Math.Max(cpos.x, x); ++xx) + for (int y = Math.Min(m[0].Y, m[1].Y); y <= Math.Max(m[0].Y, m[1].Y); y++) + for (int z = Math.Min(m[0].Z, m[1].Z); z <= Math.Max(m[0].Z, m[1].Z); z++) + for (int x = Math.Min(m[0].X, m[1].X); x <= Math.Max(m[0].X, m[1].X); x++) { - int index = p.level.PosToInt(xx, yy, zz); + int index = p.level.PosToInt((ushort)x, (ushort)y, (ushort)z); if (index >= 0 && p.level.blocks[index] != Block.air) buffer.Add(index); } - if (cpos.extraInfo.Raw == 0) { + if (extraInfo.Raw == 0) { if (buffer.Count > Server.rpNormLimit) { Player.Message(p, "Cannot restart more than " + Server.rpNormLimit + " blocks."); Player.Message(p, "Tried to restart " + buffer.Count + " blocks."); - return; + return false; } } else if (buffer.Count > Server.rpLimit) { Player.Message(p, "Tried to add physics to " + buffer.Count + " blocks."); Player.Message(p, "Cannot add physics to more than " + Server.rpLimit + " blocks."); - return; + return false; } foreach (int index in buffer) - p.level.AddCheck(index, true, cpos.extraInfo); + p.level.AddCheck(index, true, extraInfo); Player.Message(p, "Activated " + buffer.Count + " blocks."); - if (p.staticCommands) - p.Blockchange += PlacedMark1; + return true; } - - struct CatchPos { public ushort x, y, z; public PhysicsArgs extraInfo; } public override void Help(Player p) { Player.Message(p, "/restartphysics ([type] [num]) ([type2] [num2]) - Restarts every physics block in an area"); diff --git a/Commands/building/CmdSphere.cs b/Commands/building/CmdSphere.cs index a7d71ef41..3692095d1 100644 --- a/Commands/building/CmdSphere.cs +++ b/Commands/building/CmdSphere.cs @@ -37,7 +37,7 @@ namespace MCGalaxy.Commands.Building { protected override bool DoDraw(Player p, Vec3S32[] m, object state, byte type, byte extType) { DrawArgs cpos = (DrawArgs)state; - GetRealBlock(type, extType, p, ref cpos); + cpos.type = type; cpos.extType = extType; DrawOp op = null; Func constructor = null; diff --git a/Commands/building/CmdSpheroid.cs b/Commands/building/CmdSpheroid.cs index 78e7c6a27..d445ef03a 100644 --- a/Commands/building/CmdSpheroid.cs +++ b/Commands/building/CmdSpheroid.cs @@ -29,7 +29,7 @@ namespace MCGalaxy.Commands.Building { protected override bool DoDraw(Player p, Vec3S32[] marks, object state, byte type, byte extType) { DrawArgs cpos = (DrawArgs)state; - GetRealBlock(type, extType, p, ref cpos); + cpos.type = type; cpos.extType = extType; DrawOp op = null; int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1; Brush brush = GetBrush(p, cpos, brushOffset); diff --git a/Commands/building/CmdTorus.cs b/Commands/building/CmdTorus.cs index 65adbad73..20f6ed977 100644 --- a/Commands/building/CmdTorus.cs +++ b/Commands/building/CmdTorus.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.Building { protected override bool DoDraw(Player p, Vec3S32[] m, object state, byte type, byte extType) { DrawArgs cpos = (DrawArgs)state; - GetRealBlock(type, extType, p, ref cpos); + cpos.type = type; cpos.extType = extType; DrawOp drawOp = new TorusDrawOp(); Brush brush = GetBrush(p, cpos, 0); diff --git a/Commands/building/CmdTree.cs b/Commands/building/CmdTree.cs index 00ed90cf0..6bec9aa3c 100644 --- a/Commands/building/CmdTree.cs +++ b/Commands/building/CmdTree.cs @@ -44,20 +44,15 @@ namespace MCGalaxy.Commands.Building { default: brushMsg = message; break; } - CatchPos cpos = default(CatchPos); - cpos.mode = mode; - cpos.brushMsg = brushMsg; - p.ClearBlockchange(); - p.blockchangeObject = cpos; - p.Blockchange += PlacedBase; + DrawArgs dArgs = default(DrawArgs); + dArgs.mode = mode; + dArgs.brushMsg = brushMsg; Player.Message(p, "Select where you wish your tree to grow"); + p.MakeSelection(1, dArgs, DoTree); } - void PlacedBase(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { - RevertAndClearState(p, x, y, z); - CatchPos cpos = (CatchPos)p.blockchangeObject; - type = type < 128 ? p.bindings[type] : type; - + bool DoTree(Player p, Vec3S32[] marks, object state, byte type, byte extType) { + DrawArgs cpos = (DrawArgs)state; TreeDrawOp op = new TreeDrawOp(); op.Type = cpos.mode; op.random = p.random; @@ -65,17 +60,12 @@ namespace MCGalaxy.Commands.Building { if (cpos.brushMsg != "") { if (!p.group.CanExecute("brush")) { - Player.Message(p, "You cannot use /brush, so therefore cannot use /tree with a brush."); return; + Player.Message(p, "You cannot use /brush, so therefore cannot use /tree with a brush."); return false; } brush = ParseBrush(cpos.brushMsg, p, type, extType); - if (brush == null) return; + if (brush == null) return false; } - - Vec3S32[] marks = { new Vec3S32(x, y, z) }; - if (!DrawOp.DoDrawOp(op, brush, p, marks)) - return; - if (p.staticCommands) - p.Blockchange += PlacedBase; + return DrawOp.DoDrawOp(op, brush, p, marks); } static Brush ParseBrush(string brushMsg, Player p, byte type, byte extType) { @@ -92,7 +82,7 @@ namespace MCGalaxy.Commands.Building { return Brush.Brushes[brushName](args); } - struct CatchPos { public int mode; public string brushMsg; } + struct DrawArgs { public int mode; public string brushMsg; } public override void Help(Player p) { Player.Message(p, "%T/tree [type] %H- Draws a tree."); diff --git a/Commands/building/CmdTriangle.cs b/Commands/building/CmdTriangle.cs index 9ba1d847d..b2ba0477d 100644 --- a/Commands/building/CmdTriangle.cs +++ b/Commands/building/CmdTriangle.cs @@ -30,7 +30,7 @@ namespace MCGalaxy.Commands.Building { protected override bool DoDraw(Player p, Vec3S32[] marks, object state, byte type, byte extType) { DrawArgs cpos = (DrawArgs)state; - GetRealBlock(type, extType, p, ref cpos); + cpos.type = type; cpos.extType = extType; Brush brush = GetBrush(p, cpos, 0, null); if (brush == null) return false; diff --git a/Commands/building/CmdWrite.cs b/Commands/building/CmdWrite.cs index 4c68e78bd..d5d7536ba 100644 --- a/Commands/building/CmdWrite.cs +++ b/Commands/building/CmdWrite.cs @@ -49,7 +49,6 @@ namespace MCGalaxy.Commands.Building { } bool DoWrite(Player p, Vec3S32[] marks, object state, byte type, byte extType) { - type = type < 128 ? p.bindings[type] : type; WriteArgs wArgs = (WriteArgs)state; if (marks[0].X == marks[1].X && marks[0].Z == marks[1].Z) { Player.Message(p, "No direction was selected"); return false; diff --git a/Commands/building/DrawCmd.cs b/Commands/building/DrawCmd.cs index e45f8f8fb..c2986abcb 100644 --- a/Commands/building/DrawCmd.cs +++ b/Commands/building/DrawCmd.cs @@ -87,11 +87,6 @@ namespace MCGalaxy.Commands.Building { return constructor(args); } - protected static void GetRealBlock(byte type, byte extType, Player p, ref DrawArgs cpos) { - cpos.type = type < 128 ? p.bindings[type] : type; - cpos.extType = extType; - } - protected struct DrawArgs { public DrawMode mode; public byte type, extType; diff --git a/Player/Player.Fields.cs b/Player/Player.Fields.cs index ce8fc044d..ef7116b98 100644 --- a/Player/Player.Fields.cs +++ b/Player/Player.Fields.cs @@ -207,8 +207,7 @@ namespace MCGalaxy { //Copy public CopyState CopyBuffer; - public int[] copyoffset = new int[3] { 0, 0, 0 }; - public ushort[] copystart = new ushort[3] { 0, 0, 0 }; + public Vec3S32 copyoffset, copystart; // GlobalBlock internal int gbStep = 0, gbTargetId = 0; diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs index bc160c66c..0e4eb94be 100644 --- a/Player/Player.Handlers.cs +++ b/Player/Player.Handlers.cs @@ -81,17 +81,10 @@ namespace MCGalaxy { bP.SetData(type, extType, false); lastClick.X = x; lastClick.Y = y; lastClick.Z = z; - if ( Blockchange != null ) { - if ( Blockchange.Method.ToString().IndexOf("AboutBlockchange") == -1 && !level.IsMuseum ) { - bP.flags |= 1; - if (level.UseBlockDB) - level.blockCache.Add(bP); - } - - Blockchange(this, x, y, z, type, extType); - return; + if (Blockchange != null) { + Blockchange(this, x, y, z, type, extType); return; } - if ( PlayerBlockChange != null ) + if (PlayerBlockChange != null) PlayerBlockChange(this, x, y, z, type, extType); OnBlockChangeEvent.Call(this, x, y, z, type, extType); if ( cancelBlock ) { cancelBlock = false; return; } diff --git a/Player/Player.cs b/Player/Player.cs index 171cac01f..1d8180db5 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -606,6 +606,7 @@ Next: continue; if (selIndex != selMarks.Length) return; Blockchange = null; + type = type < 128 ? p.bindings[type] : type; bool canRepeat = selCallback(this, selMarks, selState, type, extType); if (canRepeat && staticCommands) MakeSelection(selIndex, selState, selCallback);