Skip to content

Commit 8ce2fe3

Browse files
committed
Backporting 1.20.1/main and finally putting this branch to rest
1 parent a7da94f commit 8ce2fe3

File tree

10 files changed

+263
-287
lines changed

10 files changed

+263
-287
lines changed

changelog.md

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
# Changes
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
2+
- Fixed Physics Ticks Event Handler only responding to one computer only
3+
- Fixed Ship API missing methods
4+
- Merged Extended Ship API into Ship API
5+
- New documentation via LDoc (targeting `1.20.x/main`)
6+
7+
# This version is now officially dead and archived!

common/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ loom {
66
accessWidenerPath = file("src/main/resources/cc_vs.accesswidener")
77
}
88

9+
repositories {
10+
maven {
11+
url "maven.fabricmc.net"
12+
}
13+
}
14+
915
dependencies {
1016
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
1117
// Do NOT use other classes from fabric loader
1218
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
19+
modCompileOnly "net.fabricmc.fabric-api:fabric-screen-handler-api-v1:1.0.0+045df74f45"
1320

1421
modApi "dev.architectury:architectury:${rootProject.architectury_version}"
1522

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

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

33
import io.github.techtastic.cc_vs.ship.PhysTickEventHandler
4+
import io.github.techtastic.cc_vs.ship.PhysicsTicksEventHandler
45
import org.valkyrienskies.core.impl.hooks.VSEvents
56

67
object CCVSMod {
@@ -9,6 +10,10 @@ object CCVSMod {
910
@JvmStatic
1011
fun init() {
1112
VSEvents.shipLoadEvent.on { huh -> huh.ship.setAttachment(PhysTickEventHandler::class.java, null) }
13+
14+
VSEvents.tickEndEvent.on { huh -> huh.world.loadedShips.forEach { ship ->
15+
PhysicsTicksEventHandler.getOrCreateControl(ship).resetData()
16+
} }
1217
}
1318

1419
@JvmStatic

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

Lines changed: 0 additions & 158 deletions
This file was deleted.

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

Lines changed: 120 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,30 @@ import dan200.computercraft.api.lua.ILuaAPI
55
import dan200.computercraft.api.lua.LuaException
66
import dan200.computercraft.api.lua.LuaFunction
77
import dan200.computercraft.shared.computer.blocks.TileComputer
8-
import dan200.computercraft.shared.computer.core.ServerComputer
8+
import dan200.computercraft.shared.computer.core.ComputerFamily
99
import io.github.techtastic.cc_vs.PlatformUtils
1010
import io.github.techtastic.cc_vs.mixin.ShipObjectWorldAccessor
1111
import io.github.techtastic.cc_vs.ship.PhysicsTicksEventHandler
12+
import io.github.techtastic.cc_vs.ship.QueuedForcesApplier
1213
import io.github.techtastic.cc_vs.util.CCVSUtils.toLua
1314
import io.github.techtastic.cc_vs.util.CCVSUtils.toVector
1415
import net.minecraft.core.BlockPos
1516
import net.minecraft.server.level.ServerLevel
16-
import org.joml.Vector3d
17-
import org.joml.Vector4d
17+
import org.joml.*
1818
import org.joml.primitives.AABBi
1919
import org.valkyrienskies.core.api.ships.LoadedServerShip
2020
import org.valkyrienskies.core.apigame.constraints.VSConstraintAndId
21+
import org.valkyrienskies.core.impl.game.ShipTeleportDataImpl
2122
import org.valkyrienskies.mod.common.getShipObjectManagingPos
2223
import org.valkyrienskies.mod.common.shipObjectWorld
24+
import org.valkyrienskies.mod.common.vsCore
2325

2426
open class ShipAPI(val level: ServerLevel, val pos: BlockPos) : ILuaAPI {
27+
private fun verifyAdmin() {
28+
if (PlatformUtils.isCommandOnly() && (level.getBlockEntity(pos) as? TileComputer)?.family == ComputerFamily.COMMAND)
29+
throw LuaException("This method requires a Command Computer!")
30+
}
31+
2532
override fun startup() {
2633
try {
2734
if (PlatformUtils.exposePhysTick())
@@ -34,10 +41,7 @@ open class ShipAPI(val level: ServerLevel, val pos: BlockPos) : ILuaAPI {
3441
try {
3542
if (PlatformUtils.exposePhysTick()) {
3643
val data = PhysicsTicksEventHandler.getOrCreateControl(getShip()).getData()
37-
val clazz = TileComputer::class.java
38-
val method = clazz.getMethod("getServerComputer")
39-
val obj = method.invoke(level.getBlockEntity(pos))
40-
(obj as? ServerComputer)?.queueEvent("physics_ticks", data)
44+
(level.getBlockEntity(pos) as? TileComputer)?.let { computer -> computer.serverComputer?.queueEvent("physics_ticks", data) }
4145
}
4246
} catch (_: LuaException) {}
4347
super.update()
@@ -156,4 +160,113 @@ open class ShipAPI(val level: ServerLevel, val pos: BlockPos) : ILuaAPI {
156160
accessor.constraints[id]?.let { VSConstraintAndId(id, it) }
157161
}.map { combo -> combo?.toLua() }
158162
}
163+
164+
@LuaFunction
165+
fun applyInvariantForce(forceX: Double, forceY: Double, forceZ: Double) {
166+
verifyAdmin()
167+
QueuedForcesApplier.getOrCreateControl(getShip()).applyInvariantForce(Vector3d(forceX, forceY, forceZ))
168+
}
169+
170+
@LuaFunction
171+
fun applyInvariantTorque(torqueX: Double, torqueY: Double, torqueZ: Double) {
172+
verifyAdmin()
173+
QueuedForcesApplier.getOrCreateControl(getShip()).applyInvariantTorque(Vector3d(torqueX, torqueY, torqueZ))
174+
}
175+
176+
@LuaFunction
177+
fun applyInvariantForceToPos(forceX: Double, forceY: Double, forceZ: Double, posX: Double, posY: Double, posZ: Double) {
178+
verifyAdmin()
179+
QueuedForcesApplier.getOrCreateControl(getShip()).applyInvariantForceToPos(Vector3d(forceX, forceY, forceZ), Vector3d(posX, posY, posZ))
180+
}
181+
182+
@LuaFunction
183+
fun applyRotDependentForce(forceX: Double, forceY: Double, forceZ: Double) {
184+
verifyAdmin()
185+
QueuedForcesApplier.getOrCreateControl(getShip()).applyRotDependentForce(Vector3d(forceX, forceY, forceZ))
186+
}
187+
188+
@LuaFunction
189+
fun applyRotDependentTorque(torqueX: Double, torqueY: Double, torqueZ: Double) {
190+
verifyAdmin()
191+
QueuedForcesApplier.getOrCreateControl(getShip()).applyRotDependentTorque(Vector3d(torqueX, torqueY, torqueZ))
192+
}
193+
194+
@LuaFunction
195+
fun applyRotDependentForceToPos(forceX: Double, forceY: Double, forceZ: Double, posX: Double, posY: Double, posZ: Double) {
196+
verifyAdmin()
197+
QueuedForcesApplier.getOrCreateControl(getShip()).applyRotDependentForceToPos(Vector3d(forceX, forceY, forceZ), Vector3d(posX, posY, posZ))
198+
}
199+
200+
@LuaFunction
201+
fun setStatic(b: Boolean) {
202+
QueuedForcesApplier.getOrCreateControl(getShip()).setStatic(b)
203+
}
204+
205+
@LuaFunction
206+
fun setScale(scale: Double) {
207+
vsCore.scaleShip(level.shipObjectWorld, getShip(), scale)
208+
}
209+
210+
@LuaFunction
211+
fun teleport(args: IArguments) {
212+
if (!PlatformUtils.canTeleport())
213+
throw LuaException("Teleporting is Disabled via CC: VS Config!")
214+
215+
val input = args.getTable(0)
216+
217+
var pos = getShip().transform.positionInWorld
218+
if (input.containsKey("pos"))
219+
pos = getVectorFromTable(input, "pos")
220+
221+
var rot = getShip().transform.shipToWorldRotation
222+
if (input.containsKey("rot"))
223+
rot = getQuaternionFromTable(input).normalize(Quaterniond())
224+
225+
var vel = getShip().velocity
226+
if (input.containsKey("vel"))
227+
vel = getVectorFromTable(input, "vel")
228+
229+
var omega = getShip().omega
230+
if (input.containsKey("omega"))
231+
omega = getVectorFromTable(input, "omega")
232+
233+
var dimension: String? = null
234+
if (input.containsKey("dimension"))
235+
dimension = (input["dimension"] ?: throwMalformedSectionError("dimension")) as String
236+
237+
var scale = getShip().transform.shipToWorldScaling.x()
238+
if (input.containsKey("scale"))
239+
scale = (input["scale"] ?: throwMalformedSectionError("scale")) as Double
240+
241+
val teleportData = ShipTeleportDataImpl(pos, rot, vel, omega, dimension, scale)
242+
243+
println("Rot: ${teleportData.newRot}\n")
244+
245+
//vsCore.teleportShip(this.level.shipObjectWorld, getShip(), teleportData)
246+
level.shipObjectWorld.teleportShip(getShip(), teleportData)
247+
}
248+
249+
private fun getVectorFromTable(input: Map<*, *>, section: String): Vector3dc {
250+
val table = (input[section] ?: throwMalformedSectionError(section)) as Map<*, *>
251+
return Vector3d(
252+
(table["x"] ?: throwMalformedFieldError(section, "x")) as Double,
253+
(table["y"] ?: throwMalformedFieldError(section, "y")) as Double,
254+
(table["z"] ?: throwMalformedFieldError(section, "z")) as Double
255+
)
256+
}
257+
258+
private fun getQuaternionFromTable(input: Map<*, *>): Quaterniondc {
259+
val table = (input["rot"] ?: throwMalformedSectionError("rot")) as Map<*, *>
260+
return Quaterniond(
261+
(table["x"] ?: throwMalformedFieldError("rot", "x")) as Double,
262+
(table["y"] ?: throwMalformedFieldError("rot", "y")) as Double,
263+
(table["z"] ?: throwMalformedFieldError("rot", "z")) as Double,
264+
(table["w"] ?: throwMalformedFieldError("rot", "w")) as Double
265+
)
266+
}
267+
268+
private fun throwMalformedSectionError(section: String): Nothing =
269+
throw LuaException("Malformed $section")
270+
private fun throwMalformedFieldError(section: String, field: String): Nothing =
271+
throw LuaException("Malformed $field key of $section")
159272
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ class PhysicsTicksEventHandler: ShipForcesInducer {
1919
}
2020

2121
@JsonIgnore
22-
fun getData(): Array<LuaPhysShip> {
23-
val data = this.queuedData.toTypedArray()
24-
this.queuedData.clear()
25-
return data
26-
}
22+
fun getData() = this.queuedData.toTypedArray()
23+
24+
fun resetData() = this.queuedData.clear()
2725

2826
companion object {
2927
fun getOrCreateControl(ship: ServerShip): PhysicsTicksEventHandler {

0 commit comments

Comments
 (0)