HTTPS
https://git.nageyqma.icu/nageyqma/odin_next.git
SSH
git@git.nageyqma.icu:nageyqma/odin_next.git
HTTPS 链接可直接 git clone;推送代码请使用 SSH。
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
package com.odtheking.odin.utils
import net.minecraft.world.level.ChunkPos
/**
* Immutable IVec2 (x and z) packed into a long.
*/
@JvmInline
value class IVec2 private constructor(val data: Long) {
constructor(x: Int, z: Int) : this(
(z.toLong() shl 32) or (x.toLong() and 0xFFFF_FFFFL)
)
inline val x: Int
get() = data.toInt()
inline val z: Int
get() = (data shr 32).toInt()
operator fun component1(): Int {
return x
}
operator fun component2(): Int {
return z
}
operator fun plus(rhs: Int): IVec2 {
return IVec2(x + rhs, z + rhs)
}
operator fun plus(rhs: IVec2): IVec2 {
return IVec2(x + rhs.x, z + rhs.z)
}
operator fun minus(rhs: Int): IVec2 {
return IVec2(x - rhs, z - rhs)
}
operator fun minus(rhs: IVec2): IVec2 {
return IVec2(x - rhs.x, z - rhs.z)
}
operator fun times(rhs: Int): IVec2 {
return IVec2(x * rhs, z * rhs)
}
operator fun div(rhs: Int): IVec2 {
return IVec2(x / rhs, z / rhs)
}
override fun toString(): String {
return "IVec2(x=$x, z=$z)"
}
}
fun ChunkPos.toIVec2(): IVec2 {
return IVec2(x, z)
}
val IVec2.sortKey: Int get() = x * 1000 + z