Skip to content

Commit 7602ca7

Browse files
committed
Update for parity with 1.18.2
1 parent 4b8c401 commit 7602ca7

File tree

10 files changed

+591
-54
lines changed

10 files changed

+591
-54
lines changed

changelog.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
Fixes
2-
- Removed the thorns in my side (getRoll, getPitch, getYaw)
3-
- Welcome to Quaternion to Euler conversions (added the following methods)
4-
- getEulerAnglesXYZ
5-
- getEulerAnglesYXZ
6-
- getEulerAnglesZXY
7-
- getEulerAnglesZYX
1+
# Changes
2+
- Removed the `getEulerAngles***` methods in favor of a `quaternion` Lua library in-game
3+
- Added `quaternion` Lua library as an in-game API
4+
- Changed the `physics_tick` event to `physics_ticks` and updated how it works
5+
- `physics_ticks` now saves up previous ticks of data THEN, on game tick, send out the event with the queued physics data
6+
- Updated config documentation
7+
- Added `ship` help page in-game
8+
- Added new methods to both Ship and Extended Ship API that take vectors

common/src/main/kotlin/io/github/techtastic/cc_vs/apis/ExtendedShipAPI.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import dan200.computercraft.core.apis.IAPIEnvironment
77
import io.github.techtastic.cc_vs.PlatformUtils
88
import io.github.techtastic.cc_vs.ship.PhysTickEventHandler
99
import io.github.techtastic.cc_vs.ship.QueuedForcesApplier
10+
import io.github.techtastic.cc_vs.util.CCVSUtils.toVector
1011
import net.minecraft.server.level.ServerLevel
1112
import org.joml.Quaterniond
1213
import org.joml.Quaterniondc
@@ -30,31 +31,69 @@ class ExtendedShipAPI(private val api: IAPIEnvironment, ship: ServerShip, level:
3031
this.control.applyInvariantForce(Vector3d(xForce, yForce, zForce))
3132
}
3233

34+
@LuaFunction
35+
fun applyInvariantForce(force: Map<*,*>) {
36+
val newVec = force.toVector()
37+
applyInvariantForce(newVec.x(), newVec.y(), newVec.z())
38+
}
39+
3340
@LuaFunction
3441
fun applyInvariantTorque(xTorque: Double, yTorque: Double, zTorque: Double) {
3542
this.control.applyInvariantTorque(Vector3d(xTorque, yTorque, zTorque))
3643
}
3744

45+
@LuaFunction
46+
fun applyInvariantTorque(torque: Map<*,*>) {
47+
val newVec = torque.toVector()
48+
applyInvariantForce(newVec.x(), newVec.y(), newVec.z())
49+
}
50+
3851
@LuaFunction
3952
fun applyInvariantForceToPos(xForce: Double, yForce: Double, zForce: Double, xPos: Double, yPos: Double, zPos: Double) {
4053
this.control.applyInvariantForceToPos(Vector3d(xForce, yForce, zForce), Vector3d(xPos, yPos, zPos))
4154
}
4255

56+
@LuaFunction
57+
fun applyInvariantForceToPos(force: Map<*,*>, pos: Map<*,*>) {
58+
val newForce = force.toVector()
59+
val newPos = pos.toVector()
60+
applyInvariantForceToPos(newForce.x(), newForce.y(), newForce.z(), newPos.x(), newPos.y(), newPos.z())
61+
}
62+
4363
@LuaFunction
4464
fun applyRotDependentForce(xForce: Double, yForce: Double, zForce: Double) {
4565
this.control.applyRotDependentForce(Vector3d(xForce, yForce, zForce))
4666
}
4767

68+
@LuaFunction
69+
fun applyRotDependentForce(force: Map<*,*>) {
70+
val newVec = force.toVector()
71+
applyRotDependentForce(newVec.x(), newVec.y(), newVec.z())
72+
}
73+
4874
@LuaFunction
4975
fun applyRotDependentTorque(xTorque: Double, yTorque: Double, zTorque: Double) {
5076
this.control.applyRotDependentTorque(Vector3d(xTorque, yTorque, zTorque))
5177
}
5278

79+
@LuaFunction
80+
fun applyRotDependentTorque(torque: Map<*,*>) {
81+
val newVec = torque.toVector()
82+
applyRotDependentTorque(newVec.x(), newVec.y(), newVec.z())
83+
}
84+
5385
@LuaFunction
5486
fun applyRotDependentForceToPos(xForce: Double, yForce: Double, zForce: Double, xPos: Double, yPos: Double, zPos: Double) {
5587
this.control.applyRotDependentForceToPos(Vector3d(xForce, yForce, zForce), Vector3d(xPos, yPos, zPos))
5688
}
5789

90+
@LuaFunction
91+
fun applyRotDependentForceToPos(force: Map<*,*>, pos: Map<*,*>) {
92+
val newForce = force.toVector()
93+
val newPos = pos.toVector()
94+
applyRotDependentForceToPos(newForce.x(), newForce.y(), newForce.z(), newPos.x(), newPos.y(), newPos.z())
95+
}
96+
5897
@LuaFunction
5998
fun setStatic(b: Boolean) {
6099
this.control.setStatic(b)

common/src/main/kotlin/io/github/techtastic/cc_vs/apis/ShipAPI.kt

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
package io.github.techtastic.cc_vs.apis
22

3+
import dan200.computercraft.api.lua.IArguments
34
import dan200.computercraft.api.lua.ILuaAPI
5+
import dan200.computercraft.api.lua.LuaException
46
import dan200.computercraft.api.lua.LuaFunction
57
import io.github.techtastic.cc_vs.mixin.ShipObjectWorldAccessor
8+
import io.github.techtastic.cc_vs.util.CCVSUtils
69
import io.github.techtastic.cc_vs.util.CCVSUtils.toLua
10+
import io.github.techtastic.cc_vs.util.CCVSUtils.toVector
711
import net.minecraft.server.level.ServerLevel
12+
import net.minecraft.world.phys.Vec3
813
import org.joml.Vector3d
914
import org.joml.Vector4d
1015
import org.joml.primitives.AABBi
1116
import org.valkyrienskies.core.api.ships.ServerShip
17+
import org.valkyrienskies.core.apigame.constraints.VSAttachmentConstraint
1218
import org.valkyrienskies.core.apigame.constraints.VSConstraintAndId
1319
import org.valkyrienskies.mod.common.shipObjectWorld
20+
import org.valkyrienskies.mod.common.util.toJOML
1421
import kotlin.math.asin
1522
import kotlin.math.atan2
1623

@@ -42,7 +49,7 @@ open class ShipAPI(val ship: ServerShip, val level: ServerLevel) : ILuaAPI {
4249
this.ship.inertiaData.momentOfInertiaTensor.toLua()
4350

4451
@LuaFunction
45-
fun getName(): String = this.ship.slug ?: "no-name"
52+
fun getSlug(): String = this.ship.slug ?: "no-name"
4653

4754
@LuaFunction
4855
fun getOmega(): Map<String, Double> =
@@ -52,22 +59,6 @@ open class ShipAPI(val ship: ServerShip, val level: ServerLevel) : ILuaAPI {
5259
fun getQuaternion(): Map<String, Double> =
5360
this.ship.transform.shipToWorldRotation.toLua()
5461

55-
@LuaFunction
56-
fun getEulerAnglesXYZ() =
57-
this.ship.transform.shipToWorldRotation.getEulerAnglesXYZ(Vector3d()).toLua()
58-
59-
@LuaFunction
60-
fun getEulerAnglesYXZ() =
61-
this.ship.transform.shipToWorldRotation.getEulerAnglesYXZ(Vector3d()).toLua()
62-
63-
@LuaFunction
64-
fun getEulerAnglesZXY() =
65-
this.ship.transform.shipToWorldRotation.getEulerAnglesZXY(Vector3d()).toLua()
66-
67-
@LuaFunction
68-
fun getEulerAnglesZYX() =
69-
this.ship.transform.shipToWorldRotation.getEulerAnglesZYX(Vector3d()).toLua()
70-
7162
@LuaFunction
7263
fun getScale(): Map<String, Double> =
7364
this.ship.transform.shipToWorldScaling.toLua()
@@ -98,11 +89,18 @@ open class ShipAPI(val ship: ServerShip, val level: ServerLevel) : ILuaAPI {
9889
fun transformPositionToWorld(x: Double, y: Double, z: Double): Map<String, Double> =
9990
this.ship.shipToWorld.transformPosition(Vector3d(x, y, z)).toLua()
10091

92+
@LuaFunction
93+
fun transformPositionToWorld(table: Map<*,*>): Map<String, Double> {
94+
val pos = table.toVector()
95+
96+
return transformPositionToWorld(pos.x(), pos.y(), pos.z())
97+
}
98+
10199
@LuaFunction
102100
fun isStatic(): Boolean = this.ship.isStatic
103101

104102
@LuaFunction
105-
fun setName(name: String) {
103+
fun setSlug(name: String) {
106104
this.ship.slug = name
107105
}
108106

common/src/main/kotlin/io/github/techtastic/cc_vs/ship/PhysTickEventHandler.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,38 @@ import io.github.techtastic.cc_vs.PlatformUtils
55
import io.github.techtastic.cc_vs.apis.LuaPhysShip
66
import org.valkyrienskies.core.api.ships.*
77
import org.valkyrienskies.core.impl.game.ships.PhysShipImpl
8+
import java.util.concurrent.ConcurrentLinkedQueue
89

9-
class PhysTickEventHandler: ShipForcesInducer {
10+
class PhysTickEventHandler: ShipForcesInducer, ServerTickListener {
1011
@JsonIgnore
1112
private val computers = mutableListOf<Int>()
13+
private val queuedData = ConcurrentLinkedQueue<LuaPhysShip>()
1214

1315
override fun applyForces(physShip: PhysShip) {
1416
if (!PlatformUtils.exposePhysTick())
1517
return
1618

17-
val physShip = physShip as PhysShipImpl
18-
19-
this.computers.removeIf { PlatformUtils.getComputerByID(it) == null }
20-
21-
this.computers.forEach {
22-
PlatformUtils.getComputerByID(it)?.queueEvent("physics_tick", arrayOf(LuaPhysShip(physShip)))
23-
}
19+
this.queuedData.add(LuaPhysShip(physShip as PhysShipImpl))
2420
}
2521

2622
fun addComputer(id: Int) {
2723
this.computers.add(id)
2824
}
2925

26+
override fun onServerTick() {
27+
this.computers.removeIf { PlatformUtils.getComputerByID(it) == null }
28+
this.computers.forEach {
29+
PlatformUtils.getComputerByID(it)?.queueEvent("physics_ticks", this.queuedData.toTypedArray())
30+
}
31+
this.queuedData.clear()
32+
}
33+
3034
companion object {
3135
fun getOrCreateControl(ship: ServerShip): PhysTickEventHandler {
32-
var control = ship.getAttachment(PhysTickEventHandler::class.java)
36+
var control = ship.getAttachment<PhysTickEventHandler>()
3337
if (control == null) {
3438
control = PhysTickEventHandler()
35-
ship.saveAttachment(PhysTickEventHandler::class.java, control)
39+
ship.saveAttachment<PhysTickEventHandler>(control)
3640
}
3741

3842
return control

common/src/main/kotlin/io/github/techtastic/cc_vs/util/CCVSUtils.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.techtastic.cc_vs.util
22

3+
import dan200.computercraft.api.lua.LuaException
34
import dan200.computercraft.shared.computer.core.ComputerFamily
45
import dan200.computercraft.shared.computer.core.ServerComputer
56
import io.github.techtastic.cc_vs.PlatformUtils
@@ -121,4 +122,11 @@ object CCVSUtils {
121122

122123
return constraint
123124
}
125+
126+
fun Map<*, *>.toVector(): Vector3dc {
127+
val posTable = this as? Map<String, Double>
128+
?: throw LuaException("Invalid Argument! Expects either a vector or a table with x, y, and z keys!")
129+
130+
return Vector3d(posTable["x"] ?: 0.0, posTable["y"] ?: 0.0, posTable["z"] ?: 0.0)
131+
}
124132
}

0 commit comments

Comments
 (0)