Make /chain use DirUtils too.

This commit is contained in:
UnknownShadow200 2016-08-27 13:22:38 +10:00
parent dddf8fd5b9
commit 32259898b6
4 changed files with 18 additions and 13 deletions

View File

@ -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; }

View File

@ -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);
}

View File

@ -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;
}
}
}

View File

@ -18,7 +18,7 @@
using System;
namespace MCGalaxy {
public struct Vec3U16 : IEquatable<Vec3U16> {
public struct Vec3U16 : IEquatable<Vec3U16> {
public ushort X, Y, Z;
public static Vec3U16 Zero = new Vec3U16(0);
public static Vec3U16 MinVal = new Vec3U16(ushort.MinValue);