From e838c6d47d9b0a4485128f72fab90b4fe7ad3fdc Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 30 Mar 2016 16:23:19 +1100 Subject: [PATCH] Fix /mark for sure this time with negative coordinates. --- Commands/building/CmdMark.cs | 6 ++---- util/Vectors.cs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Commands/building/CmdMark.cs b/Commands/building/CmdMark.cs index 653c1ae5d..296c07015 100644 --- a/Commands/building/CmdMark.cs +++ b/Commands/building/CmdMark.cs @@ -29,10 +29,8 @@ namespace MCGalaxy.Commands public override void Use(Player p, string message) { if (p == null) { MessageInGameOnly(p); return; } - int x = (ushort)(p.pos[0] / 32); - int y = (ushort)((p.pos[1] / 32) - 1); - int z = (ushort)(p.pos[2] / 32); - Command.all.Find("click").Use(p, x + " " + y + " " + z); + Vec3U16 P = Vec3U16.ClampPosToBounds(p.pos[0], (ushort)(p.pos[1] - 32), p.pos[2], p.level); + Command.all.Find("click").Use(p, (P.X / 32) + " " + (P.Y / 32) + " " + (P.Z / 32)); } public override void Help(Player p) { diff --git a/util/Vectors.cs b/util/Vectors.cs index e0337e52a..ab8ae381d 100644 --- a/util/Vectors.cs +++ b/util/Vectors.cs @@ -76,6 +76,7 @@ namespace MCGalaxy { return new Vec3U16(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y), Math.Min(a.Z, b.Z)); } + /// Clamps the given block coordinates to inside the map. public static Vec3U16 ClampToBounds(ushort x, ushort y, ushort z, Level lvl) { Vec3U16 P = new Vec3U16(x, y, z); if (P.X >= 32768) P.X = 0; @@ -88,6 +89,19 @@ namespace MCGalaxy { return P; } + /// Clamps the given player position coordinates to inside the map. + public static Vec3U16 ClampPosToBounds(ushort x, ushort y, ushort z, Level lvl) { + Vec3U16 P = new Vec3U16(x, y, z); + if (P.X >= 32768) P.X = 0; + if (P.Y >= 32768) P.Y = 0; + if (P.Z >= 32768) P.Z = 0; + + if (P.X >= lvl.Width * 32) P.X = (ushort)(32 * lvl.Width - 32); + if (P.Y >= lvl.Height * 32) P.Y = (ushort)(32 * lvl.Height - 32); + if (P.Z >= lvl.Length * 32) P.Z = (ushort)(32 * lvl.Length - 32); + return P; + } + public static bool operator == (Vec3U16 a, Vec3U16 b) { return a.X == b.X && a.Y == b.Y && a.Z == b.Z; }