using System; using System.Collections.Generic; using System.Text; namespace Substrate { /// /// Represents the spawn point of a player or world. /// /// values are immutable. To change an existing spawn point, create a new instance with /// the new coordinate(s). Since some spawn points are optional in Minecraft, this helps safegaurd against saving a partial /// spawn point. public struct SpawnPoint : IEquatable { private readonly int _x; private readonly int _y; private readonly int _z; /// /// Gets the global X-coordinate of the spawn point (in blocks). /// public int X { get { return _x; } } /// /// Gets the global Y-coordinate of the spawn point (in blocks). /// public int Y { get { return _y; } } /// /// Gets the global Z-coordinate of the spawn point (in blocks). /// public int Z { get { return _z; } } /// /// Creates a new spawn point. /// /// The global X-coordinate of the spawn point. /// The global Y-coordinate of the spawn point. /// The global Z-coordinate of the spawn point. public SpawnPoint (int x, int y, int z) { _x = x; _y = y; _z = z; } /// /// Checks if two objects are considered equal. /// /// A to compare against. /// True if the two objects are equal; false otherwise. public bool Equals (SpawnPoint spawn) { return this._x == spawn._x && this._y == spawn._y && this._z == spawn._z; } /// /// Checks if two objects are considered equal. /// /// An to compare against. /// True if the two objects are equal; false otherwise. public override bool Equals (Object o) { if (o is SpawnPoint) { return this == (SpawnPoint)o; } else { return false; } } /// /// Returns the hash code for this instance. /// /// A hash code for this instance. public override int GetHashCode () { int hash = 23; hash = hash * 37 + _x; hash = hash * 37 + _y; hash = hash * 37 + _z; return hash; } /// /// Checks if two objects are considered equal. /// /// The first in the comparison. /// The second in the comparison. /// True if the two objects are equal; false otherwise. public static bool operator == (SpawnPoint k1, SpawnPoint k2) { return k1._x == k2._x && k1._y == k2._y && k1._z == k2._z; } /// /// Checks if two objects are considered unequal. /// /// The first in the comparison. /// The second in the comparison. /// True if the two objects are not equal; false otherwise. public static bool operator != (SpawnPoint k1, SpawnPoint k2) { return k1._x != k2._x || k1._y != k2._y || k1._z != k2._z; } /// /// Returns a string representation of the . /// /// A string representing this . public override string ToString () { return "(" + _x + ", " + _y + ", " + _z + ")"; } } }