Skip to content

Commit

Permalink
sync wind direction with wilder wilds / frozenlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Fourmisain committed May 26, 2024
1 parent d23b820 commit cc08b7b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ dependencies {
}

modCompileOnly "com.github.Fourmisain:fabric-seasons:jitpack-SNAPSHOT"

// TODO frozenlib jitpack build fails, same with local builds...?!
//modCompileOnly "com.github.Fourmisain:FrozenLib:depends-SNAPSHOT"
modCompileOnly files("frozenlib-1.7.2-mc1.20.6.jar")
}

processResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.frozenblock.lib.wind.api.ClientWindManager;
import net.minecraft.client.particle.*;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -153,8 +155,26 @@ public void tick() {
// the wind coefficient is just another factor in (0, 1) to add some variance between leaves.
// this implementation lags behind the actual wind speed and will never reach it fully,
// so wind speeds needs to be adjusted accordingly
velocityX += (Wind.windX - velocityX) * windCoefficient / 60.0f;
velocityZ += (Wind.windZ - velocityZ) * windCoefficient / 60.0f;
double ax = (Wind.windX - velocityX) * windCoefficient / 60.0f;
double az = (Wind.windZ - velocityZ) * windCoefficient / 60.0f;

if (FabricLoader.getInstance().isModLoaded("wilderwild")) {
// redirect wind in direction of Wilder Wild / FrozenLib wind
Vec3d wind = ClientWindManager.getWindMovement(world, new Vec3d(x, y, z));

double windNorm2d = Math.sqrt(wind.x * wind.x + wind.z * wind.z);
if (windNorm2d >= 1.0E-4) {
double norm = Math.sqrt(ax*ax + az*az);
ax = norm * wind.x / windNorm2d;
az = norm * wind.z / windNorm2d;
} else {
// hopefully doesn't happen too often
ax = az = 0;
}
}

velocityX += ax;
velocityZ += az;
}

move(velocityX, velocityY, velocityZ);
Expand Down

0 comments on commit cc08b7b

Please sign in to comment.