namespace Minecraft.Server.FourKit; /// /// Represents a 3-dimensional position in a world. /// public class Location { internal double X { get; set; } internal double Y { get; set; } internal double Z { get; set; } internal float Yaw { get; set; } internal float Pitch { get; set; } internal World? LocationWorld { get; set; } /// /// Constructs a new Location with the given coordinates and direction. /// /// The world in which this location resides. /// The x-coordinate. /// The y-coordinate. /// The z-coordinate. /// The absolute rotation on the x-plane, in degrees. /// The absolute rotation on the y-plane, in degrees. public Location(World? world, double x, double y, double z, float yaw, float pitch) { LocationWorld = world; X = x; Y = y; Z = z; Yaw = yaw; Pitch = pitch; } /// /// Constructs a new Location with the given coordinates. /// /// The world in which this location resides. /// The x-coordinate. /// The y-coordinate. /// The z-coordinate. public Location(World? world, double x, double y, double z) : this(world, x, y, z, 0f, 0f) { } /// /// Creates a new with the given coordinates and no world. /// /// The x-coordinate. /// The y-coordinate. /// The z-coordinate. public Location(double x, double y, double z) : this(null, x, y, z, 0f, 0f) { } // use for internal internal Location() : this(null, 0, 0, 0, 0f, 0f) { } /// /// Gets the x-coordinate of this location. /// /// The x-coordinate. public double getX() => X; /// /// Sets the x-coordinate of this location. /// /// The new x-coordinate. public void setX(double x) => X = x; /// /// Gets the y-coordinate of this location. /// /// The y-coordinate. public double getY() => Y; /// /// Sets the y-coordinate of this location. /// /// The new y-coordinate. public void setY(double y) => Y = y; /// /// Gets the z-coordinate of this location. /// /// The z-coordinate. public double getZ() => Z; /// /// Sets the z-coordinate of this location. /// /// The new z-coordinate. public void setZ(double z) => Z = z; /// /// Gets the yaw of this location, measured in degrees. /// /// The yaw. public float getYaw() => Yaw; /// /// Sets the yaw of this location, measured in degrees. /// /// The new yaw. public void setYaw(float yaw) => Yaw = yaw; /// /// Gets the pitch of this location, measured in degrees. /// /// The pitch. public float getPitch() => Pitch; /// /// Sets the pitch of this location, measured in degrees. /// /// The new pitch. public void setPitch(float pitch) => Pitch = pitch; /// /// Gets the world that this location resides in. /// /// The world, or null if not set. public World? getWorld() => LocationWorld; /// /// Sets the world that this location resides in. /// /// The new world. public void setWorld(World? world) => LocationWorld = world; /// /// Gets the floored value of the X component, indicating the block that /// this location is contained with. /// /// The block X. public int getBlockX() => (int)Math.Floor(X); /// /// Gets the floored value of the Y component, indicating the block that /// this location is contained with. /// /// The block Y. public int getBlockY() => (int)Math.Floor(Y); /// /// Gets the floored value of the Z component, indicating the block that /// this location is contained with. /// /// The block Z. public int getBlockZ() => (int)Math.Floor(Z); /// /// Gets the magnitude of the location, defined as sqrt(x^2+y^2+z^2). /// /// The magnitude. public double length() => Math.Sqrt(X * X + Y * Y + Z * Z); /// /// Gets the magnitude of the location squared. /// /// The magnitude squared. public double lengthSquared() => X * X + Y * Y + Z * Z; /// /// Adds the location by another. /// /// The x-coordinate to add. /// The y-coordinate to add. /// The z-coordinate to add. /// This location, for chaining. public Location add(double x, double y, double z) { X += x; Y += y; Z += z; return this; } /// /// Adds the location by another. /// /// The location to add. /// This location, for chaining. public Location add(Location vec) { X += vec.X; Y += vec.Y; Z += vec.Z; return this; } /// public override string ToString() => $"Location(world={LocationWorld}, x={X}, y={Y}, z={Z}, yaw={Yaw}, pitch={Pitch})"; }