diff --git a/Blocks/Behaviour/DeleteBehaviour.cs b/Blocks/Behaviour/DeleteBehaviour.cs index 1990c965a..d03f64c79 100644 --- a/Blocks/Behaviour/DeleteBehaviour.cs +++ b/Blocks/Behaviour/DeleteBehaviour.cs @@ -28,11 +28,7 @@ namespace MCGalaxy.BlockBehaviour { int dx = 0, dy = 0, dz = 0; p.RevertBlock(x, y, z); DirUtils.EightYaw(p.rot[0], out dx, out dz); - - if ( p.rot[1] >= 192 && p.rot[1] <= ( 192 + 32 ) ) - dy = 1; - else if ( p.rot[1] <= 64 && p.rot[1] >= 32 ) - dy = -1; + DirUtils.Pitch(p.rot[1], out dy); // Looking straight up or down if (p.rot[1] >= 192 && p.rot[1] <= 196 || p.rot[1] >= 60 && p.rot[1] <= 64) { dx = 0; dz = 0; } diff --git a/Commands/other/CmdChain.cs b/Commands/other/CmdChain.cs index dc0eb203b..c1b28b4c5 100644 --- a/Commands/other/CmdChain.cs +++ b/Commands/other/CmdChain.cs @@ -34,15 +34,14 @@ namespace MCGalaxy.Commands Player.Message(p, "You cannot build on this map!"); return; } - int yaw = p.rot[0]; Level lvl = p.level; ushort x = (ushort)(p.pos[0] / 32), y = (ushort)(p.pos[1] / 32), z = (ushort)(p.pos[2] / 32); if (x >= lvl.Width || z >= lvl.Length) { Player.Message(p, "You must be inside the map to use this command."); return; } - int dirX = (yaw > 16 && yaw <= 112) ? 1 : (yaw > 144 && yaw <= 240) ? -1 : 0; - int dirZ = (yaw > 208 || yaw < 48) ? -1 : (yaw > 80 && yaw <= 176) ? 1 : 0; + int dirX = 0, dirZ = 0; + DirUtils.EightYaw(p.rot[0], out dirX, out dirZ); DoChain(p, x, y, z, dirX, dirZ); } diff --git a/util/Math/DirUtils.cs b/util/Math/DirUtils.cs index f684650db..6a12c02e1 100644 --- a/util/Math/DirUtils.cs +++ b/util/Math/DirUtils.cs @@ -21,7 +21,7 @@ namespace MCGalaxy { public static class DirUtils { - /* How yaw works: * How pitch works: + /* How yaw works: * How pitch works: * 64 | +X * 192 | +Y * ___|___ * | * / | \ * flipped | @@ -37,7 +37,7 @@ namespace MCGalaxy { public static void EightYaw(byte yaw, out int dirX, out int dirZ) { dirX = 0; dirZ = 0; - const byte extent = 48; + const byte extent = (64 / 4) * 3; if (yaw < (0 + extent) || yaw > (256 - extent)) dirZ = -1; @@ -52,7 +52,7 @@ namespace MCGalaxy { public static void FourYaw(byte yaw, out int dirX, out int dirZ) { dirX = 0; dirZ = 0; - const byte quadrant = 32; + const byte quadrant = 64 / 2; if (yaw <= (0 + quadrant) || yaw >= (256 - quadrant)) dirZ = -1; @@ -62,6 +62,16 @@ namespace MCGalaxy { dirZ = 1; else dirX = -1; - } + } + + public static void Pitch(byte pitch, out int dirY) { + dirY = 0; + const byte quadrant = 32; + + if (pitch >= 192 && pitch <= (192 + quadrant)) + dirY = 1; + else if (pitch >= (64 - quadrant) && pitch <= 64) + dirY = -1; + } } } diff --git a/util/Math/Vectors.cs b/util/Math/Vectors.cs index edf6cb40f..b65278935 100644 --- a/util/Math/Vectors.cs +++ b/util/Math/Vectors.cs @@ -18,7 +18,7 @@ using System; namespace MCGalaxy { - public struct Vec3U16 : IEquatable { + public struct Vec3U16 : IEquatable { public ushort X, Y, Z; public static Vec3U16 Zero = new Vec3U16(0); public static Vec3U16 MinVal = new Vec3U16(ushort.MinValue);