Skip to content

Commit 23da91d

Browse files
committed
Backporting 1.20.1
1 parent ade5742 commit 23da91d

File tree

17 files changed

+346
-552
lines changed

17 files changed

+346
-552
lines changed

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ out/
77
.gradle/
88
output/
99
bin/
10-
libs/
1110

1211
.classpath
1312
.project
@@ -16,4 +15,10 @@ classes/
1615
.metadata
1716
.vscode
1817
.settings
19-
*.launch
18+
*.launch
19+
20+
quaternion.lua
21+
matrix.lua
22+
quaternion.txt
23+
matrix.txt
24+
pid.lua

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "libs/advanced_math"]
2+
path = libs/advanced_math
3+
url = https://github.com/TechTastic/Advanced-Math

changelog.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
# 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
2+
### Ship API
3+
- Made `getOmega`, `getScale`, `getShipyardPosition`, `getVelocity`, `getWorldspacePosition`, and `transformPositionToWorld` output proper `vector`s with correct metatable
4+
- Made `getQuaternion` output a proper `quaternion` with correct metatable
5+
- Made `getTransformationMatrix` output a proper `matrix` with correct metatable
6+
- Made `getConstraints` output use proper `vector`s and `quaternion`s where applicable
7+
- Re-added `getEulerAnglesZYX"`, `getEulerAnglesZXY`, `getEulerAnglesYXZ`, `getEulerAnglesXYZ`, `getRoll`, `getYaw`, `getPitch`, and `getRotationMatrix` ***only*** so they throw a more useful error redirecting to the new methods.
8+
- Updated Ship API help page
9+
- Iproved `physics_ticks` event output
10+
- Moved `physics_ticks` event to Ship API
11+
- Added `pullPhysicsTicks` to utilize `physics_ticks` with proper `vector` and `quaternion` support
12+
### Quaternion API
13+
- Moved to [CC: Advanced Math Library](https://github.com/TechTastic/Advanced-Math)
14+
### Extended Ship API
15+
- Moved `physics_ticks` event to Ship API
16+
### New APIs
17+
- [CC: Advanced Math Library](https://github.com/TechTastic/Advanced-Math) created and included to handle pure Lua math including `quaternion` and `matrix` APIs, as well as a new `pid` module

common/build.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ dependencies {
2828
modImplementation("curse.maven:forge-config-api-547434:3943250")
2929
}
3030

31+
tasks.register('updateSubmodules', Exec) {
32+
commandLine 'git', 'submodule', 'update', '--recursive', '--remote'
33+
}
34+
35+
tasks.register('copyMathLibrary', Copy) {
36+
dependsOn('updateSubmodules')
37+
from '../libs/advanced_math/datapack/data/computercraft/lua/rom/'
38+
into 'src/main/resources/data/computercraft/lua/rom/'
39+
include '**/*.lua'
40+
include '*/*.txt'
41+
}
42+
processResources.dependsOn('copyMathLibrary')
43+
44+
tasks.named("sourcesJar") {
45+
dependsOn("copyMathLibrary")
46+
}
47+
3148
publishing {
3249
publications {
3350
mavenCommon(MavenPublication) {

common/src/main/kotlin/io/github/techtastic/cc_vs/CCVSMod.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package io.github.techtastic.cc_vs
22

3+
import io.github.techtastic.cc_vs.ship.PhysTickEventHandler
4+
import org.valkyrienskies.core.impl.hooks.VSEvents
5+
36
object CCVSMod {
47
const val MOD_ID = "cc_vs"
58

69
@JvmStatic
710
fun init() {
11+
VSEvents.shipLoadEvent.on { huh -> huh.ship.setAttachment(PhysTickEventHandler::class.java, null) }
812
}
913

1014
@JvmStatic

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

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,28 @@ package io.github.techtastic.cc_vs.apis
33
import dan200.computercraft.api.lua.IArguments
44
import dan200.computercraft.api.lua.LuaException
55
import dan200.computercraft.api.lua.LuaFunction
6-
import dan200.computercraft.core.apis.IAPIEnvironment
76
import io.github.techtastic.cc_vs.PlatformUtils
8-
import io.github.techtastic.cc_vs.ship.PhysTickEventHandler
97
import io.github.techtastic.cc_vs.ship.QueuedForcesApplier
108
import io.github.techtastic.cc_vs.util.CCVSUtils.toVector
9+
import net.minecraft.core.BlockPos
1110
import net.minecraft.server.level.ServerLevel
12-
import org.checkerframework.common.reflection.qual.NewInstance
1311
import org.joml.Quaterniond
1412
import org.joml.Quaterniondc
1513
import org.joml.Vector3d
1614
import org.joml.Vector3dc
17-
import org.valkyrienskies.core.api.ships.ServerShip
1815
import org.valkyrienskies.core.impl.game.ShipTeleportDataImpl
1916
import org.valkyrienskies.mod.common.shipObjectWorld
2017
import org.valkyrienskies.mod.common.vsCore
2118

22-
class ExtendedShipAPI(private val api: IAPIEnvironment, ship: ServerShip, level: ServerLevel) : ShipAPI(ship, level) {
23-
var control: QueuedForcesApplier = QueuedForcesApplier.getOrCreateControl(this.ship)
24-
25-
init {
26-
if (PlatformUtils.exposePhysTick())
27-
PhysTickEventHandler.getOrCreateControl(this.ship).addComputer(api.computerID)
28-
}
29-
19+
class ExtendedShipAPI(level: ServerLevel, pos: BlockPos) : ShipAPI(level, pos) {
3020
@LuaFunction
3121
fun applyInvariantForce(args: IArguments) {
3222
val newForce =
3323
if (args.count() == 1)
3424
args.getTable(0).toVector()
3525
else
3626
Vector3d(args.getDouble(0), args.getDouble(1), args.getDouble(2))
37-
this.control.applyInvariantForce(newForce)
27+
QueuedForcesApplier.getOrCreateControl(getShip()).applyInvariantForce(newForce)
3828
}
3929

4030
@LuaFunction
@@ -44,7 +34,7 @@ class ExtendedShipAPI(private val api: IAPIEnvironment, ship: ServerShip, level:
4434
args.getTable(0).toVector()
4535
else
4636
Vector3d(args.getDouble(0), args.getDouble(1), args.getDouble(2))
47-
this.control.applyInvariantTorque(newTorque)
37+
QueuedForcesApplier.getOrCreateControl(getShip()).applyInvariantTorque(newTorque)
4838
}
4939

5040
@LuaFunction
@@ -57,7 +47,7 @@ class ExtendedShipAPI(private val api: IAPIEnvironment, ship: ServerShip, level:
5747
Vector3d(args.getDouble(0), args.getDouble(1), args.getDouble(2)),
5848
Vector3d(args.getDouble(3), args.getDouble(4), args.getDouble(5))
5949
)
60-
this.control.applyInvariantForceToPos(newForce, newPos)
50+
QueuedForcesApplier.getOrCreateControl(getShip()).applyInvariantForceToPos(newForce, newPos)
6151
}
6252

6353
@LuaFunction
@@ -67,7 +57,7 @@ class ExtendedShipAPI(private val api: IAPIEnvironment, ship: ServerShip, level:
6757
args.getTable(0).toVector()
6858
else
6959
Vector3d(args.getDouble(0), args.getDouble(1), args.getDouble(2))
70-
this.control.applyRotDependentForce(newForce)
60+
QueuedForcesApplier.getOrCreateControl(getShip()).applyRotDependentForce(newForce)
7161
}
7262

7363
@LuaFunction
@@ -77,7 +67,7 @@ class ExtendedShipAPI(private val api: IAPIEnvironment, ship: ServerShip, level:
7767
args.getTable(0).toVector()
7868
else
7969
Vector3d(args.getDouble(0), args.getDouble(1), args.getDouble(2))
80-
this.control.applyRotDependentTorque(newTorque)
70+
QueuedForcesApplier.getOrCreateControl(getShip()).applyRotDependentTorque(newTorque)
8171
}
8272

8373
@LuaFunction
@@ -90,17 +80,17 @@ class ExtendedShipAPI(private val api: IAPIEnvironment, ship: ServerShip, level:
9080
Vector3d(args.getDouble(0), args.getDouble(1), args.getDouble(2)),
9181
Vector3d(args.getDouble(3), args.getDouble(4), args.getDouble(5))
9282
)
93-
this.control.applyRotDependentForceToPos(newForce, newPos)
83+
QueuedForcesApplier.getOrCreateControl(getShip()).applyRotDependentForceToPos(newForce, newPos)
9484
}
9585

9686
@LuaFunction
9787
fun setStatic(b: Boolean) {
98-
this.control.setStatic(b)
88+
QueuedForcesApplier.getOrCreateControl(getShip()).setStatic(b)
9989
}
10090

10191
@LuaFunction
10292
fun setScale(scale: Double) {
103-
vsCore.scaleShip(level.shipObjectWorld, ship, scale)
93+
vsCore.scaleShip(level.shipObjectWorld, getShip(), scale)
10494
}
10595

10696
@LuaFunction
@@ -110,36 +100,36 @@ class ExtendedShipAPI(private val api: IAPIEnvironment, ship: ServerShip, level:
110100

111101
val input = args.getTable(0)
112102

113-
var pos = this.ship.transform.positionInWorld
103+
var pos = getShip().transform.positionInWorld
114104
if (input.containsKey("pos"))
115105
pos = getVectorFromTable(input, "pos")
116106

117-
var rot = this.ship.transform.shipToWorldRotation
107+
var rot = getShip().transform.shipToWorldRotation
118108
if (input.containsKey("rot"))
119109
rot = getQuaternionFromTable(input).normalize(Quaterniond())
120110

121-
var vel = this.ship.velocity
111+
var vel = getShip().velocity
122112
if (input.containsKey("vel"))
123113
vel = getVectorFromTable(input, "vel")
124114

125-
var omega = this.ship.omega
115+
var omega = getShip().omega
126116
if (input.containsKey("omega"))
127117
omega = getVectorFromTable(input, "omega")
128118

129119
var dimension: String? = null
130120
if (input.containsKey("dimension"))
131121
dimension = (input["dimension"] ?: throwMalformedSectionError("dimension")) as String
132122

133-
var scale = this.ship.transform.shipToWorldScaling.x()
123+
var scale = getShip().transform.shipToWorldScaling.x()
134124
if (input.containsKey("scale"))
135125
scale = (input["scale"] ?: throwMalformedSectionError("scale")) as Double
136126

137127
val teleportData = ShipTeleportDataImpl(pos, rot, vel, omega, dimension, scale)
138128

139129
println("Rot: ${teleportData.newRot}\n")
140130

141-
//vsCore.teleportShip(this.level.shipObjectWorld, this.ship, teleportData)
142-
this.level.shipObjectWorld.teleportShip(this.ship, teleportData)
131+
//vsCore.teleportShip(this.level.shipObjectWorld, getShip(), teleportData)
132+
level.shipObjectWorld.teleportShip(getShip(), teleportData)
143133
}
144134

145135
private fun getVectorFromTable(input: Map<*, *>, section: String): Vector3dc {

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

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,54 @@ package io.github.techtastic.cc_vs.apis
22

33
import dan200.computercraft.api.lua.LuaFunction
44
import io.github.techtastic.cc_vs.util.CCVSUtils.toLua
5+
import org.valkyrienskies.core.api.VSBeta
6+
import org.valkyrienskies.core.api.ships.ShipForcesInducer
7+
import org.valkyrienskies.core.impl.game.ships.PhysInertia
58
import org.valkyrienskies.core.impl.game.ships.PhysShipImpl
69

7-
class LuaPhysShip(private val physShip: PhysShipImpl) {
10+
data class LuaPhysShip(
11+
private val buoyantFactor: Double,
12+
private val static: Boolean,
13+
private val fluidDrag: Boolean,
14+
private val inertia: Map<String, Any>,
15+
private val poseVel: Map<String, Map<String, Double>>,
16+
private val forceInducers: List<String>
17+
) {
18+
@OptIn(VSBeta::class)
19+
constructor(physShip: PhysShipImpl): this(
20+
physShip.buoyantFactor, physShip.isStatic, physShip.doFluidDrag,
21+
physShip.inertia.let { inertia ->
22+
mapOf(
23+
Pair("momentOfInertiaTensor", inertia.momentOfInertiaTensor.toLua()),
24+
Pair("mass", inertia.shipMass)
25+
)
26+
},
27+
physShip.poseVel.let { poseVel ->
28+
mapOf(
29+
Pair("vel", poseVel.vel.toLua()),
30+
Pair("omega", poseVel.omega.toLua()),
31+
Pair("pos", poseVel.pos.toLua()),
32+
Pair("rot", poseVel.rot.toLua())
33+
)
34+
},
35+
physShip.forceInducers.map(ShipForcesInducer::toString)
36+
)
837

938
@LuaFunction
10-
fun getBuoyantFactor() = this.physShip.buoyantFactor
39+
fun getBuoyantFactor() = this.buoyantFactor
1140

1241
@LuaFunction
13-
fun isStatic() = this.physShip.isStatic
42+
fun isStatic() = this.static
1443

1544
@LuaFunction
16-
fun doFluidDrag() = this.physShip.doFluidDrag
45+
fun doFluidDrag() = this.fluidDrag
1746

1847
@LuaFunction
19-
fun getInertia(): Map<String, Any> {
20-
val inertia = this.physShip.inertia
21-
return mapOf(
22-
Pair("momentOfInertiaTensor", inertia.momentOfInertiaTensor.toLua()),
23-
Pair("mass", inertia.shipMass)
24-
)
25-
}
48+
fun getInertia() = this.inertia
2649

2750
@LuaFunction
28-
fun getPoseVel(): Map<String, Map<String, Double>> {
29-
val poseVel = this.physShip.poseVel
30-
return mapOf(
31-
Pair("vel", poseVel.vel.toLua()),
32-
Pair("omega", poseVel.omega.toLua()),
33-
Pair("pos", poseVel.pos.toLua()),
34-
Pair("rot", poseVel.rot.toLua())
35-
)
36-
}
51+
fun getPoseVel() = this.poseVel
3752

3853
@LuaFunction
39-
fun getForcesInducers(): List<String> {
40-
val inducers = this.physShip.forceInducers
41-
42-
val list = mutableListOf<String>()
43-
inducers.forEach {
44-
list.add(it.toString())
45-
}
46-
47-
return list
48-
}
54+
fun getForcesInducers() = this.forceInducers
4955
}

0 commit comments

Comments
 (0)