Skip to content

Commit

Permalink
project: Update to 1.19.4 by using Kotlin floor function
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobkmar committed Mar 14, 2023
1 parent e74956b commit ba5631d
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 40 deletions.
8 changes: 4 additions & 4 deletions buildSrc/src/main/kotlin/BuildConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ object BuildConstants {
const val majorMinecraftVersion = "1.19"

// check these values here: https://jakobk.net/mcdev
const val minecraftVersion = "1.19.3"
const val parchmentMappingsVersion = "1.19.3:2023.02.26"
const val fabricLoaderVersion = "0.14.14"
const val fabricApiVersion = "0.75.1+1.19.3"
const val minecraftVersion = "1.19.4"
const val parchmentMappingsVersion = "1.19.3:2023.03.12"
const val fabricLoaderVersion = "0.14.17"
const val fabricApiVersion = "0.75.3+1.19.4"
const val fabricLanguageKotlinVersion = "1.9.1+kotlin.1.8.10"

const val kotestVersion = "5.5.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import net.minecraft.world.phys.Vec3
import net.silkmc.silk.core.world.block.BlockInfo
import net.silkmc.silk.core.world.block.isCollidable
import kotlin.math.cos
import kotlin.math.floor
import kotlin.math.sin

val Entity.pos: Vec3 get() = position()
Expand All @@ -17,7 +18,11 @@ val Entity.blockPos: BlockPos get() = blockPosition()
* Returns the pos under the entities "feet".
*/
val Entity.posUnder: BlockPos
get() = pos.run { BlockPos(x, y - 0.05, z) }
get() {
val exactPos = pos
val posForXZ = blockPos
return BlockPos(posForXZ.x, floor(exactPos.y - 0.05).toInt(), posForXZ.z)
}

/**
* Returns a unit-vector pointing in the direction the entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,114 @@ import net.minecraft.core.Vec3i
import net.minecraft.world.phys.Vec3
import org.joml.Vector3f

operator fun Vec3.not(): Vec3 = reverse()
operator fun Vec3.not(): Vec3 =
reverse()

operator fun Vec3.plus(n: Number): Vec3 = n.toDouble().let { nDouble -> add(nDouble, nDouble, nDouble) }
operator fun Vec3.minus(n: Number): Vec3 = n.toDouble().let { nDouble -> subtract(nDouble, nDouble, nDouble) }
operator fun Vec3.times(n: Number): Vec3 = scale(n.toDouble())
operator fun Vec3.div(n: Number): Vec3 = scale(1.0 / n.toDouble())
operator fun Vec3.compareTo(n: Number) = length().compareTo(n.toDouble())
operator fun Vec3.plus(n: Number): Vec3 =
n.toDouble().let { nDouble -> add(nDouble, nDouble, nDouble) }

operator fun Vec3.plus(vec: Vec3): Vec3 = add(vec)
operator fun Vec3.minus(vec: Vec3): Vec3 = subtract(vec)
operator fun Vec3.times(vec: Vec3): Vec3 = multiply(vec)
operator fun Vec3.div(vec: Vec3): Vec3 = Vec3(x / vec.x, y / vec.y, z / vec.z)
operator fun Vec3.compareTo(vec: Vec3) = lengthSqr().compareTo(vec.lengthSqr())
operator fun Vec3.minus(n: Number): Vec3 =
n.toDouble().let { nDouble -> subtract(nDouble, nDouble, nDouble) }

operator fun Vec3.times(n: Number): Vec3 =
scale(n.toDouble())

operator fun Vec3.div(n: Number): Vec3 =
scale(1.0 / n.toDouble())

operator fun Vec3.compareTo(n: Number) =
length().compareTo(n.toDouble())

operator fun Vec3.plus(vec: Vec3): Vec3 =
add(vec)

operator fun Vec3.minus(vec: Vec3): Vec3 =
subtract(vec)

operator fun Vec3.times(vec: Vec3): Vec3 =
multiply(vec)

operator fun Vec3.div(vec: Vec3): Vec3 =
Vec3(x / vec.x, y / vec.y, z / vec.z)

operator fun Vec3.compareTo(vec: Vec3) =
lengthSqr().compareTo(vec.lengthSqr())

operator fun Vec3.component1() = x
operator fun Vec3.component2() = y
operator fun Vec3.component3() = z


operator fun Vector3f.not(): Vector3f = times(-1f)
operator fun Vector3f.not(): Vector3f =
times(-1f)

operator fun Vector3f.plus(n: Number): Vector3f =
Vector3f(this).apply { n.toFloat().let { nFloat -> add(nFloat, nFloat, nFloat) } }

operator fun Vector3f.minus(n: Number): Vector3f =
Vector3f(this).apply { n.toFloat().let { nFloat -> sub(Vector3f(nFloat, nFloat, nFloat)) } }

operator fun Vector3f.times(n: Number): Vector3f =
n.toFloat().let { nFloat -> Vector3f(x() * nFloat, y() * nFloat, z() * nFloat) }

operator fun Vector3f.div(n: Number): Vector3f =
times(1.0 / n.toDouble())

operator fun Vector3f.plus(n: Number): Vector3f = Vector3f(this).apply { n.toFloat().let { nFloat -> add(nFloat, nFloat, nFloat) } }
operator fun Vector3f.minus(n: Number): Vector3f = Vector3f(this).apply { n.toFloat().let { nFloat -> sub(Vector3f(nFloat, nFloat, nFloat)) } }
operator fun Vector3f.times(n: Number): Vector3f = n.toFloat().let { nFloat -> Vector3f(x() * nFloat, y() * nFloat, z() * nFloat) }
operator fun Vector3f.div(n: Number): Vector3f = times(1.0 / n.toDouble())
operator fun Vector3f.compareTo(n: Number) = Vec3(this).length().compareTo(n.toDouble())
operator fun Vector3f.compareTo(n: Number) =
Vec3(this).length().compareTo(n.toDouble())

operator fun Vector3f.plus(vec: Vector3f): Vector3f = Vector3f(this).apply { add(vec) }
operator fun Vector3f.minus(vec: Vector3f): Vector3f = Vector3f(this).apply { sub(vec) }
operator fun Vector3f.times(vec: Vector3f): Vector3f = Vector3f(x() * vec.x(), y() * vec.y(), z() * vec.z())
operator fun Vector3f.div(vec: Vector3f): Vector3f = Vector3f(x() / vec.x(), y() / vec.y(), z() / vec.z())
operator fun Vector3f.compareTo(vec: Vector3f) = Vec3(this).lengthSqr().compareTo(Vec3(vec).lengthSqr())
operator fun Vector3f.plus(vec: Vector3f): Vector3f =
Vector3f(this).apply { add(vec) }

operator fun Vector3f.minus(vec: Vector3f): Vector3f =
Vector3f(this).apply { sub(vec) }

operator fun Vector3f.times(vec: Vector3f): Vector3f =
Vector3f(x() * vec.x(), y() * vec.y(), z() * vec.z())

operator fun Vector3f.div(vec: Vector3f): Vector3f =
Vector3f(x() / vec.x(), y() / vec.y(), z() / vec.z())

operator fun Vector3f.compareTo(vec: Vector3f) =
Vec3(this).lengthSqr().compareTo(Vec3(vec).lengthSqr())

operator fun Vector3f.component1() = x()
operator fun Vector3f.component2() = y()
operator fun Vector3f.component3() = z()


operator fun Vec3i.not(): Vec3i = times(-1)
operator fun Vec3i.not(): Vec3i =
times(-1)

inline operator fun <reified T : Vec3i> T.plus(n: Number): T =
n.toInt().let { nInt -> offset(nInt, nInt, nInt) } as T

inline operator fun <reified T : Vec3i> T.minus(n: Number): T =
(-n.toInt()).let { nInt -> offset(nInt, nInt, nInt) } as T

operator fun Vec3i.times(n: Number): Vec3i =
multiply(n.toInt())

operator fun Vec3i.div(n: Number) =
(1.0 / n.toDouble()).let { nDouble -> Vec3i((x * nDouble).toInt(), (y * nDouble).toInt(), (z * nDouble).toInt()) }

operator fun Vec3i.compareTo(n: Number) =
Vec3(x.toDouble(), y.toDouble(), z.toDouble()).length().compareTo(n.toDouble())

inline operator fun <reified T : Vec3i> T.plus(vec: Vec3i): T =
offset(vec) as T

inline operator fun <reified T : Vec3i> T.minus(vec: Vec3i): T =
offset(!vec) as T

operator fun Vec3i.times(vec: Vec3i): Vec3i =
Vec3i(x * vec.x, y * vec.y, z * vec.z)

inline operator fun <reified T : Vec3i> T.plus(n: Number): T = n.toInt().let { nInt -> offset(nInt, nInt, nInt) } as T
inline operator fun <reified T : Vec3i> T.minus(n: Number): T = (-n.toInt()).let { nInt -> offset(nInt, nInt, nInt) } as T
operator fun Vec3i.times(n: Number): Vec3i = multiply(n.toInt())
operator fun Vec3i.div(n: Number) = (1.0 / n.toDouble()).let { nDouble -> Vec3i(x * nDouble, y * nDouble, z * nDouble) }
operator fun Vec3i.compareTo(n: Number) = Vec3(x.toDouble(), y.toDouble(), z.toDouble()).length().compareTo(n.toDouble())
operator fun Vec3i.div(vec: Vec3i): Vec3i =
Vec3i(x / vec.x, y / vec.y, z / vec.z)

inline operator fun <reified T : Vec3i> T.plus(vec: Vec3i): T = offset(vec) as T
inline operator fun <reified T : Vec3i> T.minus(vec: Vec3i): T = offset(!vec) as T
operator fun Vec3i.times(vec: Vec3i): Vec3i = Vec3i(x * vec.x, y * vec.y, z * vec.z)
operator fun Vec3i.div(vec: Vec3i): Vec3i = Vec3i(x / vec.x, y / vec.y, z / vec.z)
operator fun Vec3i.compareTo(vec: Vec3i) = Vec3(x.toDouble(), y.toDouble(), z.toDouble()).lengthSqr().compareTo(Vec3(vec.x.toDouble(), vec.y.toDouble(), vec.z.toDouble()).lengthSqr())
operator fun Vec3i.compareTo(vec: Vec3i) =
Vec3(x.toDouble(), y.toDouble(), z.toDouble()).lengthSqr().compareTo(Vec3(vec.x.toDouble(), vec.y.toDouble(), vec.z.toDouble()).lengthSqr())

operator fun Vec3i.component1() = x
operator fun Vec3i.component2() = y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import net.silkmc.silk.core.Silk
import net.silkmc.silk.core.entity.pos
import net.silkmc.silk.core.serialization.serializers.ResourceLocationSerializer
import org.joml.Vector3f
import kotlin.math.floor
import kotlin.math.roundToInt

@Deprecated(
Expand Down Expand Up @@ -64,7 +65,7 @@ data class SilkPosition(
)

val blockPos: BlockPos
get() = BlockPos(x.toInt(), y.toInt(), z.toInt())
get() = BlockPos(floor(x).toInt(), floor(y).toInt(), floor(z).toInt())
val roundedBlockPos: BlockPos
get() = BlockPos(x.roundToInt(), y.roundToInt(), z.roundToInt())
val posInChunk: PosInChunk
Expand All @@ -75,7 +76,7 @@ data class SilkPosition(
get() = SectionPos.of(blockPos)

val vec3i: Vec3i
get() = Vec3i(x, y, z)
get() = Vec3i(x.toInt(), y.toInt(), z.toInt())
val vec3f: Vector3f
get() = Vector3f(x.toFloat(), y.toFloat(), z.toFloat())
val vec3d: Vec3
Expand Down

0 comments on commit ba5631d

Please sign in to comment.