From ba5631d028fb690d6fd4826e612be1ebc36ad8a3 Mon Sep 17 00:00:00 2001 From: Jakob K Date: Wed, 15 Mar 2023 00:57:58 +0100 Subject: [PATCH] project: Update to 1.19.4 by using Kotlin floor function --- buildSrc/src/main/kotlin/BuildConstants.kt | 8 +- .../silk/core/entity/StateExtensions.kt | 7 +- .../silk/core/math/vector/VectorOperations.kt | 123 +++++++++++++----- .../silk/core/world/pos/SilkPosition.kt | 5 +- 4 files changed, 103 insertions(+), 40 deletions(-) diff --git a/buildSrc/src/main/kotlin/BuildConstants.kt b/buildSrc/src/main/kotlin/BuildConstants.kt index 895cd8b7..17c654d2 100644 --- a/buildSrc/src/main/kotlin/BuildConstants.kt +++ b/buildSrc/src/main/kotlin/BuildConstants.kt @@ -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" diff --git a/silk-core/src/main/kotlin/net/silkmc/silk/core/entity/StateExtensions.kt b/silk-core/src/main/kotlin/net/silkmc/silk/core/entity/StateExtensions.kt index 3e17a0ab..23fceff6 100644 --- a/silk-core/src/main/kotlin/net/silkmc/silk/core/entity/StateExtensions.kt +++ b/silk-core/src/main/kotlin/net/silkmc/silk/core/entity/StateExtensions.kt @@ -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() @@ -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 diff --git a/silk-core/src/main/kotlin/net/silkmc/silk/core/math/vector/VectorOperations.kt b/silk-core/src/main/kotlin/net/silkmc/silk/core/math/vector/VectorOperations.kt index a50e5235..59402763 100644 --- a/silk-core/src/main/kotlin/net/silkmc/silk/core/math/vector/VectorOperations.kt +++ b/silk-core/src/main/kotlin/net/silkmc/silk/core/math/vector/VectorOperations.kt @@ -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 T.plus(n: Number): T = + n.toInt().let { nInt -> offset(nInt, nInt, nInt) } as T + +inline operator fun 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 T.plus(vec: Vec3i): T = + offset(vec) as T + +inline operator fun 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 T.plus(n: Number): T = n.toInt().let { nInt -> offset(nInt, nInt, nInt) } as T -inline operator fun 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 T.plus(vec: Vec3i): T = offset(vec) as T -inline operator fun 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 diff --git a/silk-core/src/main/kotlin/net/silkmc/silk/core/world/pos/SilkPosition.kt b/silk-core/src/main/kotlin/net/silkmc/silk/core/world/pos/SilkPosition.kt index 8418e6c6..ed024880 100644 --- a/silk-core/src/main/kotlin/net/silkmc/silk/core/world/pos/SilkPosition.kt +++ b/silk-core/src/main/kotlin/net/silkmc/silk/core/world/pos/SilkPosition.kt @@ -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( @@ -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 @@ -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