-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Weather 2 wind & storm affecting ships (#897)
* weather 2 interop * move check
- Loading branch information
Showing
6 changed files
with
111 additions
and
0 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
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
73 changes: 73 additions & 0 deletions
73
common/src/main/kotlin/org/valkyrienskies/mod/compat/Weather2Compat.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,73 @@ | ||
package org.valkyrienskies.mod.compat | ||
|
||
import net.minecraft.server.level.ServerLevel | ||
import org.joml.Vector3d | ||
import org.valkyrienskies.core.api.ships.getAttachment | ||
import org.valkyrienskies.mod.common.config.VSGameConfig | ||
import org.valkyrienskies.mod.common.shipObjectWorld | ||
import org.valkyrienskies.mod.common.util.GameTickForceApplier | ||
import org.valkyrienskies.mod.common.util.toMinecraft | ||
import weather2.ServerTickHandler | ||
import weather2.weathersystem.storm.StormObject | ||
|
||
object Weather2Compat { | ||
fun tick(level: ServerLevel) { | ||
val mgr = ServerTickHandler | ||
.getWeatherManagerFor(level.dimension()) | ||
|
||
val windMult = VSGameConfig.SERVER.Weather2.windMultiplier | ||
val windMax = VSGameConfig.SERVER.Weather2.windMaxVel | ||
val stormDampen = 1.0f - VSGameConfig.SERVER.Weather2.stormDampening | ||
val stormRange = VSGameConfig.SERVER.Weather2.stormRange | ||
|
||
val vec = Vector3d() | ||
level.shipObjectWorld.loadedShips.forEach { ship -> | ||
val forces = ship.getAttachment<GameTickForceApplier>()!! | ||
|
||
val com = ship.inertiaData.centerOfMassInShip | ||
|
||
ship.shipToWorld.transformPosition(com, vec) | ||
val pos = vec.toMinecraft() | ||
|
||
val motion = ship.velocity.toMinecraft() | ||
|
||
val mass = ship.inertiaData.mass | ||
|
||
var forcePlusMotion = mgr.windManager.applyWindForceImpl( | ||
pos, | ||
motion, | ||
mass.toFloat(), | ||
windMult, | ||
windMax | ||
) | ||
|
||
fun applyForcePlusMotion() { | ||
vec.x = forcePlusMotion.x | ||
vec.y = forcePlusMotion.y | ||
vec.z = forcePlusMotion.z | ||
|
||
vec.sub(ship.velocity) | ||
vec.mul(mass) | ||
|
||
forces.applyInvariantForceToPos(vec, com) | ||
} | ||
|
||
applyForcePlusMotion() | ||
|
||
mgr.getStormsAround(pos, stormRange).forEach { | ||
if (it is StormObject) { | ||
runCatching { // prevent Cannot read field "listLayers" because "this.tornadoFunnelSimple" is null at weather2.weathersystem.storm.StormObject.spinObject(StormObject.java:2503) | ||
forcePlusMotion = it.spinObject( | ||
pos, | ||
forcePlusMotion, | ||
false, | ||
stormDampen | ||
) | ||
|
||
applyForcePlusMotion() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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