From 6809a8037648a2082d697c3a6615a823cf8aa041 Mon Sep 17 00:00:00 2001 From: alex_s168 <63254202+alex-s168@users.noreply.github.com> Date: Fri, 26 Jul 2024 04:02:14 +0000 Subject: [PATCH] Weather 2 wind & storm affecting ships (#897) * weather 2 interop * move check --- common/build.gradle | 3 + .../mixin/server/MixinMinecraftServer.java | 4 + .../mod/common/config/VSGameConfig.kt | 24 ++++++ .../valkyrienskies/mod/compat/LoadedMods.kt | 3 + .../mod/compat/Weather2Compat.kt | 73 +++++++++++++++++++ forge/build.gradle | 4 + 6 files changed, 111 insertions(+) create mode 100644 common/src/main/kotlin/org/valkyrienskies/mod/compat/Weather2Compat.kt diff --git a/common/build.gradle b/common/build.gradle index 2de1338c5..5978178a5 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -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}") diff --git a/common/src/main/java/org/valkyrienskies/mod/mixin/server/MixinMinecraftServer.java b/common/src/main/java/org/valkyrienskies/mod/mixin/server/MixinMinecraftServer.java index 1e79554e9..1b1af8967 100644 --- a/common/src/main/java/org/valkyrienskies/mod/mixin/server/MixinMinecraftServer.java +++ b/common/src/main/java/org/valkyrienskies/mod/mixin/server/MixinMinecraftServer.java @@ -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) @@ -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(); diff --git a/common/src/main/kotlin/org/valkyrienskies/mod/common/config/VSGameConfig.kt b/common/src/main/kotlin/org/valkyrienskies/mod/common/config/VSGameConfig.kt index fe225d812..ebf47e73d 100644 --- a/common/src/main/kotlin/org/valkyrienskies/mod/common/config/VSGameConfig.kt +++ b/common/src/main/kotlin/org/valkyrienskies/mod/common/config/VSGameConfig.kt @@ -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. " + diff --git a/common/src/main/kotlin/org/valkyrienskies/mod/compat/LoadedMods.kt b/common/src/main/kotlin/org/valkyrienskies/mod/compat/LoadedMods.kt index 6d3e0cd9c..995539262 100644 --- a/common/src/main/kotlin/org/valkyrienskies/mod/compat/LoadedMods.kt +++ b/common/src/main/kotlin/org/valkyrienskies/mod/compat/LoadedMods.kt @@ -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 { private var isLoaded: Boolean? = null diff --git a/common/src/main/kotlin/org/valkyrienskies/mod/compat/Weather2Compat.kt b/common/src/main/kotlin/org/valkyrienskies/mod/compat/Weather2Compat.kt new file mode 100644 index 000000000..975b461e8 --- /dev/null +++ b/common/src/main/kotlin/org/valkyrienskies/mod/compat/Weather2Compat.kt @@ -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()!! + + 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() + } + } + } + } + } +} diff --git a/forge/build.gradle b/forge/build.gradle index e932fbda1..f108a0c17 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -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")