-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accepted Lugia's PR to Fix Roll/Pitch/Yaw
Added LuaPhysShip and PhysTickEventHandler Removed unused import statements Version Bump
- Loading branch information
1 parent
165bfbb
commit 48b0139
Showing
17 changed files
with
187 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
common/src/main/kotlin/io/github/techtastic/cc_vs/apis/LuaPhysShip.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.github.techtastic.cc_vs.apis | ||
|
||
import dan200.computercraft.api.lua.LuaFunction | ||
import io.github.techtastic.cc_vs.util.CCVSUtils.momentToTable | ||
import io.github.techtastic.cc_vs.util.CCVSUtils.quatToTable | ||
import io.github.techtastic.cc_vs.util.CCVSUtils.vectorToTable | ||
import org.valkyrienskies.core.impl.game.ships.PhysShipImpl | ||
|
||
class LuaPhysShip(private val physShip: PhysShipImpl) { | ||
|
||
@LuaFunction | ||
fun getBuoyantFactor() = this.physShip.buoyantFactor | ||
|
||
@LuaFunction | ||
fun isStatic() = this.physShip.isStatic | ||
|
||
@LuaFunction | ||
fun doFluidDrag() = this.physShip.doFluidDrag | ||
|
||
@LuaFunction | ||
fun getInertia(): Map<String, Any> { | ||
val inertia = this.physShip.inertia | ||
return mapOf( | ||
Pair("momentOfInertiaTensor", momentToTable(inertia.momentOfInertiaTensor)), | ||
Pair("mass", inertia.shipMass) | ||
) | ||
} | ||
|
||
@LuaFunction | ||
fun getPoseVel(): Map<String, Map<String, Double>> { | ||
val poseVel = this.physShip.poseVel | ||
return mapOf( | ||
Pair("vel", vectorToTable(poseVel.vel)), | ||
Pair("omega", vectorToTable(poseVel.omega)), | ||
Pair("pos", vectorToTable(poseVel.pos)), | ||
Pair("rot", quatToTable(poseVel.rot)) | ||
) | ||
} | ||
|
||
@LuaFunction | ||
fun getForcesInducers(): List<String> { | ||
val inducers = this.physShip.forceInducers | ||
|
||
val list = mutableListOf<String>() | ||
inducers.forEach { | ||
list.add(it.toString()) | ||
} | ||
|
||
return list | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
common/src/main/kotlin/io/github/techtastic/cc_vs/ship/PhysTickEventHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.github.techtastic.cc_vs.ship | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore | ||
import io.github.techtastic.cc_vs.PlatformUtils | ||
import io.github.techtastic.cc_vs.apis.LuaPhysShip | ||
import org.valkyrienskies.core.api.ships.* | ||
import org.valkyrienskies.core.impl.game.ships.PhysShipImpl | ||
|
||
class PhysTickEventHandler: ShipForcesInducer { | ||
@JsonIgnore | ||
private val computers = mutableListOf<Int>() | ||
|
||
override fun applyForces(physShip: PhysShip) { | ||
if (!PlatformUtils.exposePhysTick()) | ||
return | ||
|
||
val physShip = physShip as PhysShipImpl | ||
|
||
this.computers.removeIf { PlatformUtils.getComputerByID(it) == null } | ||
|
||
this.computers.forEach { | ||
PlatformUtils.getComputerByID(it)?.queueEvent("physics_tick", arrayOf(LuaPhysShip(physShip))) | ||
} | ||
} | ||
|
||
fun addComputer(id: Int) { | ||
this.computers.add(id) | ||
} | ||
|
||
companion object { | ||
fun getOrCreateControl(ship: ServerShip): PhysTickEventHandler { | ||
var control = ship.getAttachment(PhysTickEventHandler::class.java) | ||
if (control == null) { | ||
control = PhysTickEventHandler() | ||
ship.saveAttachment(PhysTickEventHandler::class.java, control) | ||
} | ||
|
||
return control | ||
} | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
common/src/main/kotlin/io/github/techtastic/cc_vs/ship/QueuedForcesApplier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
forge/src/main/java/io/github/techtastic/cc_vs/forge/mixin/MixinTileComputer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
forge/src/main/java/io/github/techtastic/cc_vs/forge/mixin/MixinTileTurtle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.