@@ -21,6 +21,7 @@ import com.lambda.util.math.MathUtils.floorToInt
2121import com.lambda.util.math.MathUtils.sq
2222import net.minecraft.entity.Entity
2323import net.minecraft.util.math.BlockPos
24+ import net.minecraft.util.math.ChunkPos
2425import net.minecraft.util.math.Direction
2526import net.minecraft.util.math.EightWayDirection
2627import net.minecraft.util.math.Vec2f
@@ -78,6 +79,19 @@ infix operator fun Vec2f.div(other: Int): Vec2f = times(1.0 / other)
7879
7980operator fun Vec2f.unaryMinus (): Vec2f = negate()
8081
82+ /* Chunk */
83+ val ChunkPos .center: ChunkPos
84+ get() = ChunkPos (centerX, centerZ)
85+
86+ infix fun ChunkPos.dist (other : Vec3i ): Double = other dist this
87+ infix fun ChunkPos.dist (other : Vec3d ): Double = other dist this
88+ infix fun ChunkPos.dist (other : ChunkPos ): Double = sqrt((this distSq other).toDouble())
89+ infix fun ChunkPos.distCenter (other : ChunkPos ): Double = sqrt((this distSqCenter other).toDouble())
90+ infix fun ChunkPos.distSq (other : Vec3i ): Int = other distSq this
91+ infix fun ChunkPos.distSq (other : Vec3d ): Double = other distSq this
92+ infix fun ChunkPos.distSq (other : ChunkPos ): Int = (other.x - x).sq + (other.z - z).sq
93+ infix fun ChunkPos.distSqCenter (other : ChunkPos ): Int = (other.centerX - centerX).sq + (other.centerZ - centerZ).sq
94+
8195/* Vec3d */
8296fun Vec3d.approximate (other : Vec3d , precision : Double = 2.0E-4): Boolean =
8397 (subtract(other) distSq Vec3d .ZERO ) > precision.pow(2 )
@@ -100,9 +114,10 @@ operator fun Vec3d.component3() = z
100114
101115infix fun Vec3d.dist (other : Vec3d ): Double = sqrt(this distSq other)
102116infix fun Vec3d.dist (other : Vec3i ): Double = sqrt(this distSq other)
103- infix fun Vec3d.distSq (other : Vec3d ): Double = squaredDistanceTo(other)
104- infix fun Vec3d.distSq (other : Vec3i ): Double =
105- squaredDistanceTo(other.x.toDouble(), other.y.toDouble(), other.z.toDouble())
117+ infix fun Vec3d.dist (other : ChunkPos ): Double = sqrt(this distSq other)
118+ infix fun Vec3d.distSq (other : Vec3d ): Double = (other.x - x).sq + (other.y - y).sq + (other.z - z).sq
119+ infix fun Vec3d.distSq (other : Vec3i ): Double = (other.x - x).sq + (other.y - y).sq + (other.z - z).sq
120+ infix fun Vec3d.distSq (other : ChunkPos ): Double = (other.x - x).sq + (other.z - z).sq
106121
107122infix operator fun Vec3d.plus (other : Vec3d ): Vec3d = add(other)
108123infix operator fun Vec3d.plus (other : Vec3i ): Vec3d = Vec3d (x + other.x, y + other.y, z + other.z)
@@ -148,8 +163,10 @@ val Vec3i.vec3d
148163
149164infix fun Vec3i.dist (other : Vec3d ): Double = sqrt(this distSq other)
150165infix fun Vec3i.dist (other : Vec3i ): Double = sqrt((this distSq other).toDouble())
166+ infix fun Vec3i.dist (other : ChunkPos ): Double = sqrt((this distSq other).toDouble())
151167infix fun Vec3i.distSq (other : Vec3d ): Double = getSquaredDistance(other)
152168infix fun Vec3i.distSq (other : Vec3i ): Int = (x - other.x).sq + (y - other.y).sq + (z - other.z).sq
169+ infix fun Vec3i.distSq (other : ChunkPos ): Int = (other.x - x).sq + (other.z - z).sq
153170
154171infix operator fun Vec3i.plus (other : Vec3i ): Vec3i = add(other)
155172infix operator fun Vec3i.plus (other : Int ): Vec3i = add(other, other, other)
0 commit comments