diff --git a/build.gradle.kts b/build.gradle.kts index 8bf8d4a70..0c6287c20 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -107,13 +107,6 @@ dependencies { implementation(fg.deobf("mekanism:Mekanism:${mc_version}-${mekanism_version}:all")) } - - library(create("ru.dbotthepony:kvector:1.2.0", closureOf { - // avoid adding kotlin libraries as dependency twice - // since KVector depends solely on Kotlin - (this as ExternalModuleDependency).isTransitive = false - excludeKGroup.invoke(this) - } as Closure)) } configurations { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/EuclidMath.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/EuclidMath.kt index 48af8b023..441f4deb0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/EuclidMath.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/EuclidMath.kt @@ -260,3 +260,72 @@ data class MutableAngle(override var pitch: Double = 0.0, override var yaw: Doub } } } + +fun linearInterpolation(t: Double, a: Double, b: Double): Double { + if (t <= 0.0) + return a + else if (t >= 1.0) + return b + + return a + t * (b - a) +} + +fun linearInterpolation(t: Double, a: Angle, b: Angle): Angle { + return Angle( + linearInterpolation(t, a.pitch, b.pitch), + linearInterpolation(t, a.yaw, b.yaw), + linearInterpolation(t, a.roll, b.roll), + ) +} + +fun linearInterpolation(t: Double, a: Vector, b: Vector): Vector { + return Vector( + linearInterpolation(t, a.x, b.x), + linearInterpolation(t, a.y, b.y), + linearInterpolation(t, a.z, b.z), + ) +} + +fun bezierCurve(t: Double, vararg values: Angle): Angle { + when (values.size) { + 0, 1 -> throw IllegalArgumentException("Provided array has only ${values.size} entries in it") + else -> { + @Suppress("NAME_SHADOWING") val values = values.clone() as Array + + // construct prime - 1 + for (length in values.size - 2 downTo 0) { + // search prime + for (j in 0 .. length) { + val point1 = values[j] + val point2 = values[j + 1] + + values[j] = linearInterpolation(t, point1, point2) + } + } + + return values[0] + } + } +} + +fun bezierCurve(t: Double, vararg values: Vector): Vector { + when (values.size) { + 0, 1 -> throw IllegalArgumentException("Provided array has only ${values.size} entries in it") + else -> { + @Suppress("NAME_SHADOWING") val values = values.clone() as Array + + // construct prime - 1 + for (length in values.size - 2 downTo 0) { + // search prime + for (j in 0 .. length) { + val point1 = values[j] + val point2 = values[j + 1] + + values[j] = linearInterpolation(t, point1, point2) + } + } + + return values[0] + } + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/AbstractWeaponItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/AbstractWeaponItem.kt index 761f42327..0393dc894 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/AbstractWeaponItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/AbstractWeaponItem.kt @@ -20,10 +20,9 @@ import net.minecraftforge.event.TickEvent import net.minecraftforge.eventbus.api.SubscribeEvent import net.minecraftforge.fml.LogicalSide import net.minecraftforge.network.NetworkEvent -import ru.dbotthepony.kvector.util.linearInterpolation -import ru.dbotthepony.kvector.vector.Angle3f -import ru.dbotthepony.kvector.vector.ndouble.Vector3d import ru.dbotthepony.mc.otm.* +import ru.dbotthepony.mc.otm.core.* +import ru.dbotthepony.mc.otm.core.Vector import ru.dbotthepony.mc.otm.network.MatteryNetworking import java.util.* import java.util.function.Supplier @@ -145,10 +144,10 @@ abstract class AbstractWeaponItem(val tables: KClass, ra val roundsPerSecond get() = roundsPerMinute / 60 val fireCooldown get() = (1200 / roundsPerMinute).coerceAtLeast(1) - open val positionIdle get() = Vector3d(1.0, -0.5, -1.0) - open val positionIronSights get() = Vector3d(0.0, -0.23, -1.0) - open val rotIdle get() = Angle3f(PI.toFloat() / 36f, PI.toFloat() / 18f) - open val rotIronSights get() = Angle3f.ZERO + open val positionIdle get() = Vector(1.0, -0.5, -1.0) + open val positionIronSights get() = Vector(0.0, -0.23, -1.0) + open val rotIdle get() = Angle(PI / 36, PI / 18) + open val rotIronSights get() = Angle.ZERO open val primaryAutomatic = true open val secondaryAutomatic = true @@ -246,6 +245,7 @@ abstract class AbstractWeaponItem(val tables: KClass, ra event.partialTicks ) * 1.7 - 0.6, 1.0, it.ironSightsFOV ) + it.dataTable = null } } @@ -293,12 +293,12 @@ abstract class AbstractWeaponItem(val tables: KClass, ra val progress = item.ironSightsProgress(stack, event.partialTicks.toDouble()) - val (x, y, z) = Vector3d.bezier( + val (x, y, z) = bezierCurve( progress, item.positionIdle, item.positionIdle, item.positionIdle, - Vector3d(0.0, -1.0, -1.0), + Vector(0.0, -1.0, -1.0), item.positionIronSights, item.positionIronSights, item.positionIronSights, @@ -306,8 +306,8 @@ abstract class AbstractWeaponItem(val tables: KClass, ra pose.translate(x, y, z) - val (pitch, yaw, roll) = Angle3f.bezier( - progress.toFloat(), + val (pitch, yaw, roll) = bezierCurve( + progress, item.rotIdle, item.rotIdle, item.rotIdle, @@ -319,9 +319,9 @@ abstract class AbstractWeaponItem(val tables: KClass, ra item.rotIronSights, ) - pose.mulPose(Vector3f.ZP.rotation(roll)) - pose.mulPose(Vector3f.YP.rotation(yaw)) - pose.mulPose(Vector3f.XP.rotation(pitch)) + pose.mulPose(Vector3f.ZP.rotation(roll.toFloat())) + pose.mulPose(Vector3f.YP.rotation(yaw.toFloat())) + pose.mulPose(Vector3f.XP.rotation(pitch.toFloat())) itemInHandRenderer.renderItem( player, diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/PlasmaRifleItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/PlasmaRifleItem.kt index a97dfb4d9..8bb7453b5 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/PlasmaRifleItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/PlasmaRifleItem.kt @@ -3,14 +3,10 @@ package ru.dbotthepony.mc.otm.item.weapon import net.minecraft.util.Mth import net.minecraft.world.entity.Entity import net.minecraft.world.entity.player.Player -import net.minecraft.world.entity.projectile.Arrow import net.minecraft.world.item.ItemStack import net.minecraft.world.phys.Vec3 -import ru.dbotthepony.kvector.vector.Angle3f -import ru.dbotthepony.kvector.vector.ndouble.Vector3d -import ru.dbotthepony.mc.otm.core.ImpreciseFraction -import ru.dbotthepony.mc.otm.core.plus -import ru.dbotthepony.mc.otm.core.times +import ru.dbotthepony.mc.otm.core.* +import ru.dbotthepony.mc.otm.core.Vector import ru.dbotthepony.mc.otm.entity.PlasmaProjectile import ru.dbotthepony.mc.otm.position import java.util.* @@ -124,14 +120,14 @@ class VelocityCalculation( class PlasmaRifleItem : PlasmaWeaponItem(WeaponDataTable::class, ImpreciseFraction(200_000)) { override val roundsPerMinute: Int = 400 override val scopingTime: Int = 7 - override val positionIdle: Vector3d - get() = Vector3d(0.2,-0.4,-0.6) - override val positionIronSights: Vector3d - get() = Vector3d(0.0,-0.24,-1.0) - override val rotIdle: Angle3f - get() = Angle3f(0f,-0.02f,0f) - override val rotIronSights: Angle3f - get() = Angle3f(-0.02f,0f,0f) + override val positionIdle: Vector + get() = Vector(0.2,-0.4,-0.6) + override val positionIronSights: Vector + get() = Vector(0.0,-0.24,-1.0) + override val rotIdle: Angle + get() = Angle(0.0, -0.02, 0.0) + override val rotIronSights: Angle + get() = Angle(-0.02, 0.0, 0.0) override fun primaryFire(itemStack: ItemStack, player: Player, dt: WeaponDataTable): Boolean { if (!player.level.isClientSide) {