Skip to content

Commit

Permalink
Weather 2 wind & storm affecting ships (#897)
Browse files Browse the repository at this point in the history
* weather 2 interop

* move check
  • Loading branch information
alex-s168 authored Jul 26, 2024
1 parent 1681692 commit 6809a80
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 0 deletions.
3 changes: 3 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ dependencies {
modCompileOnly("curse.maven:ftb-teams-404468:4229138")
modCompileOnly("curse.maven:ftb-chunks-314906:4229120")

// Weather2 1.18
modCompileOnly("curse.maven:weather-storms-tornadoes-237746:4426524")

//Common create compat,
//We just use a version from a platform and hope the classes exist on both versions and mixins apply correctly
modCompileOnly("com.simibubi.create:create-fabric-${minecraft_version}:${create_fabric_version}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
import org.valkyrienskies.mod.common.util.VSServerLevel;
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt;
import org.valkyrienskies.mod.common.world.ChunkManagement;
import org.valkyrienskies.mod.compat.LoadedMods;
import org.valkyrienskies.mod.compat.Weather2Compat;
import org.valkyrienskies.mod.util.KrunchSupport;

@Mixin(MinecraftServer.class)
Expand Down Expand Up @@ -229,6 +231,8 @@ private void postTick(final CallbackInfo ci) {
// Only drag entities after we have updated the ship positions
for (final ServerLevel level : getAllLevels()) {
EntityDragger.INSTANCE.dragEntitiesWithShips(level.getAllEntities());
if (LoadedMods.getWeather2())
Weather2Compat.INSTANCE.tick(level);
}

handleShipPortals();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,30 @@ object VSGameConfig {
var canTurtlesLeaveScaledShips = false
}

val Weather2 = WEATHER2()

class WEATHER2 {
@JsonSchema(
description = "How much Weather 2's wind affects VS ships"
)
var windMultiplier = 0.0001f

@JsonSchema(
description = "The maximum velocity a VS ship can travel because of wind"
)
var windMaxVel = 20.0f

@JsonSchema(
description = "In what range storms affect VS ships"
)
var stormRange = 150.0

@JsonSchema(
description = "Storm effect dampening on VS ships"
)
var stormDampening = 0.0f
}

@JsonSchema(
description = "By default, the vanilla server prevents block interacts past a certain distance " +
"to prevent cheat clients from breaking blocks halfway across the map. " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ object LoadedMods {
@JvmStatic
val iris by CompatInfo("net.coderbot.iris.Iris")

@JvmStatic
val weather2 by CompatInfo("weather2.Weather")

class CompatInfo(private val className: String) : ReadOnlyProperty<Any?, Boolean> {
private var isLoaded: Boolean? = null

Expand Down
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()
}
}
}
}
}
}
4 changes: 4 additions & 0 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ dependencies {
modImplementation("com.jozufozu.flywheel:flywheel-forge-${minecraft_version}:${flywheel_version}")
modImplementation("com.tterrag.registrate:Registrate:${registrate_version}")

// Weather2 1.18
modImplementation("curse.maven:weather-storms-tornadoes-237746:4426524")
modImplementation("curse.maven:coroutil-237749:5008370")

// CC Tweaked
modCompileOnly("curse.maven:cc-tweaked-282001:4061947")

Expand Down

0 comments on commit 6809a80

Please sign in to comment.