mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-27 15:23:12 +00:00
Copy some TiC world helpers into Mantle
This commit is contained in:
1 parent
9655463da7
commit
c6dc8a33a3
4 files changed
+117
No files matched your search
@@ -0,0 +1,45 @@
|
||||
package mantle.world
|
||||
|
||||
import java.lang.String
|
||||
|
||||
/**
|
||||
* CoordTuple
|
||||
*
|
||||
* @param x The x coordinate
|
||||
* @param y The y coordinate
|
||||
* @param z The z coordinate
|
||||
*
|
||||
* @author mDiyo, Sunstrike
|
||||
*/
|
||||
class CoordTuple(val x: Int, val y:Int, val z:Int) extends Comparable[CoordTuple] {
|
||||
|
||||
def this(posX: Double, posY: Double, posZ: Double) = this(Math.floor(posX).asInstanceOf[Int], Math.floor(posY).asInstanceOf[Int], Math.floor(posZ).asInstanceOf[Int])
|
||||
|
||||
def this(tuple: CoordTuple) = this(tuple.x, tuple.y, tuple.z)
|
||||
|
||||
def equalCoords(posX: Int, posY: Int, posZ: Int): Boolean = this.x == posX && this.y == posY && this.z == posZ
|
||||
|
||||
override def hashCode: Int = {
|
||||
val prime: Int = 31
|
||||
var result: Int = 1
|
||||
result = prime * result + x
|
||||
result = prime * result + y
|
||||
result = prime * result + z
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
override def toString: String = s"X: $x, Y: $y, Z: $z"
|
||||
|
||||
def compareTo(o: CoordTuple): Int = o match {
|
||||
case null => throw new NullPointerException("Object cannot be null")
|
||||
case _ if x < o.x => -1
|
||||
case _ if x > o.x => 1
|
||||
case _ if y < o.y => -1
|
||||
case _ if y > o.y => 1
|
||||
case _ if z < o.z => -1
|
||||
case _ if z > o.z => 1
|
||||
case _ => 0
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package mantle.world
|
||||
|
||||
/**
|
||||
* CoordTuplePair
|
||||
*
|
||||
* @param a The first CoordTuple
|
||||
* @param b The second CoordTuple
|
||||
*
|
||||
* @author mDiyo, Sunstrike
|
||||
*/
|
||||
class CoordTuplePair(val a:CoordTuple, val b:CoordTuple) {
|
||||
|
||||
def this(aX: Int, aY: Int, aZ: Int, bX: Int, bY: Int, bZ: Int) = this(new CoordTuple(aX, aY, aZ), new CoordTuple(bX, bY, bZ))
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package mantle.world
|
||||
|
||||
import java.util.Comparator
|
||||
|
||||
/**
|
||||
* CoordTupleSort
|
||||
*
|
||||
* @author mDiyo, Sunstrike
|
||||
*/
|
||||
class CoordTupleSort extends Comparator[CoordTuple] {
|
||||
|
||||
override def compare(o1: CoordTuple, o2: CoordTuple): Int = {
|
||||
if (o1.y != o2.y) return o1.y - o2.y
|
||||
if (o1.x != o2.x) return o1.x - o2.x
|
||||
if (o1.z != o2.z) return o1.z - o2.z
|
||||
0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package mantle.world
|
||||
|
||||
import java.lang.String
|
||||
|
||||
/**
|
||||
* DimensionCoordPair
|
||||
*
|
||||
* @param dim The dimension ID
|
||||
* @param x The x coordinate
|
||||
* @param z The z coordinate
|
||||
*
|
||||
* @author mDiyo, Sunstrike
|
||||
*/
|
||||
class DimensionCoordPair(val dim: Int, val x:Int, val z:Int) {
|
||||
|
||||
def this(tuple: DimensionCoordPair) = this(tuple.dim, tuple.x, tuple.z)
|
||||
|
||||
def equalCoords(dim: Int, posX: Int, posZ: Int): Boolean = this.dim == dim && this.x == posX && this.z == posZ
|
||||
|
||||
override def hashCode: Int = {
|
||||
val prime: Int = 31
|
||||
var result: Int = 1
|
||||
result = prime * result + dim
|
||||
result = prime * result + x
|
||||
result = prime * result + z
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
override def equals(obj: scala.Any): Boolean = obj match {
|
||||
case a:DimensionCoordPair => equalCoords(a.dim, a.x, a.z)
|
||||
case _ => false
|
||||
}
|
||||
|
||||
override def toString: String = s"Dim: $dim, X: $x, Z: $z"
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user