/* * Decompiled with CFR 0.152. */ package com.vinlanx.explosionoverhaul.client; import com.vinlanx.explosionoverhaul.Config; import java.util.Random; import net.minecraft.client.Minecraft; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.phys.Vec3; public class ExplosionWindController { private static final double BASE_SPEED = 0.05; private static final double MAX_SPEED = 0.06; private static final double LERP_FACTOR = 0.03; private static final Random RANDOM = new Random(); private static final double[] HEIGHT_STOPS = new double[]{0.0, 0.25, 0.5, 0.75, 1.0}; private static final double[] DUST_SPEEDS = new double[]{0.02, 0.02, 0.02, 0.02, 0.02}; private static final double[] GLOW_SPEEDS = new double[]{0.0, 0.02, 0.04, 0.06, 0.08}; private static Vec3 currentWind = Vec3.f_82478_; private static Vec3 targetDirection = Vec3.f_82478_; private static int ticksUntilDirectionShift = 0; private ExplosionWindController() { } public static void tick() { Vec3 desiredWind; if (ticksUntilDirectionShift-- <= 0) { targetDirection = ExplosionWindController.randomHorizontalDirection(); ticksUntilDirectionShift = 80 + RANDOM.nextInt(120); } if ((currentWind = ExplosionWindController.lerp(currentWind, desiredWind = targetDirection.m_82490_(0.05), 0.03)).m_82553_() > 0.06) { currentWind = currentWind.m_82541_().m_82490_(0.06); } } public static void reset() { currentWind = Vec3.f_82478_; targetDirection = Vec3.f_82478_; ticksUntilDirectionShift = 0; } public static Vec3 getWind() { if (!((Boolean)Config.CLIENT.enableWindEffect.get()).booleanValue()) { return Vec3.f_82478_; } double multiplier = (Double)Config.CLIENT.windSpeedMultiplier.get(); return currentWind.m_82490_(multiplier); } public static Vec3 getScaledWind(double scale) { if (!((Boolean)Config.CLIENT.enableWindEffect.get()).booleanValue()) { return Vec3.f_82478_; } double multiplier = (Double)Config.CLIENT.windSpeedMultiplier.get(); return currentWind.m_82490_(scale * multiplier); } public static Vec3 getWindDirection() { if (!((Boolean)Config.CLIENT.enableWindEffect.get()).booleanValue()) { return Vec3.f_82478_; } double length = Math.sqrt(ExplosionWindController.currentWind.f_82479_ * ExplosionWindController.currentWind.f_82479_ + ExplosionWindController.currentWind.f_82481_ * ExplosionWindController.currentWind.f_82481_); if (length < 1.0E-4) { return Vec3.f_82478_; } return new Vec3(ExplosionWindController.currentWind.f_82479_ / length, 0.0, ExplosionWindController.currentWind.f_82481_ / length); } private static double getWeatherMultiplier() { Minecraft minecraft = Minecraft.m_91087_(); if (minecraft.f_91073_ != null && minecraft.f_91074_ != null) { Biome.Precipitation precipitation = ((Biome)minecraft.f_91073_.m_204166_(minecraft.f_91074_.m_20183_()).m_203334_()).m_264600_(minecraft.f_91074_.m_20183_()); if (minecraft.f_91073_.m_46471_() || minecraft.f_91073_.m_46470_()) { return 1.5; } } return 1.0; } public static double computeDustSpeed(double heightPercent) { if (!((Boolean)Config.CLIENT.enableWindEffect.get()).booleanValue()) { return 0.0; } double baseSpeed = ExplosionWindController.sampleProfile(heightPercent, DUST_SPEEDS); double weatherMultiplier = ExplosionWindController.getWeatherMultiplier(); return baseSpeed * (Double)Config.CLIENT.windSpeedMultiplier.get() * weatherMultiplier; } public static double computeGlowSpeed(double heightPercent) { if (!((Boolean)Config.CLIENT.enableWindEffect.get()).booleanValue()) { return 0.0; } double baseSpeed = ExplosionWindController.sampleProfile(heightPercent, GLOW_SPEEDS); double weatherMultiplier = ExplosionWindController.getWeatherMultiplier(); return baseSpeed * (Double)Config.CLIENT.windSpeedMultiplier.get() * weatherMultiplier; } public static Vec3 getDustWindVector(double heightPercent) { Vec3 direction = ExplosionWindController.getWindDirection(); if (direction == Vec3.f_82478_) { return direction; } return direction.m_82490_(ExplosionWindController.computeDustSpeed(heightPercent)); } public static Vec3 getGlowWindVector(double heightPercent) { Vec3 direction = ExplosionWindController.getWindDirection(); if (direction == Vec3.f_82478_) { return direction; } return direction.m_82490_(ExplosionWindController.computeGlowSpeed(heightPercent)); } private static double sampleProfile(double heightPercent, double[] speeds) { double clamped = Math.max(0.0, Math.min(1.0, heightPercent)); for (int i = 1; i < HEIGHT_STOPS.length; ++i) { double prevStop = HEIGHT_STOPS[i - 1]; double stop = HEIGHT_STOPS[i]; if (!(clamped <= stop)) continue; double t = stop <= prevStop ? 0.0 : (clamped - prevStop) / (stop - prevStop); double prevValue = speeds[i - 1]; double value = speeds[i]; return prevValue + (value - prevValue) * t; } return speeds[speeds.length - 1]; } private static Vec3 lerp(Vec3 from, Vec3 to, double factor) { double clamped = Math.max(0.0, Math.min(1.0, factor)); double x = from.f_82479_ + (to.f_82479_ - from.f_82479_) * clamped; double y = from.f_82480_ + (to.f_82480_ - from.f_82480_) * clamped; double z = from.f_82481_ + (to.f_82481_ - from.f_82481_) * clamped; return new Vec3(x, y, z); } private static Vec3 randomHorizontalDirection() { double angle = RANDOM.nextDouble() * Math.PI * 2.0; double x = Math.cos(angle); double z = Math.sin(angle); return new Vec3(x, 0.0, z); } }