| 1 | /*
|
| 2 | * This file is part of the Combatant Client distribution.
|
| 3 | * Copyright (c) 2026 pivosos2007.
|
| 4 | *
|
| 5 | * Licensed under the GNU General Public License v3.0.
|
| 6 | */
|
| 7 |
|
| 8 | package combatant.client.features.module.modules.visuals;
|
| 9 |
|
| 10 | import combatant.client.config.values.*;
|
| 11 | import combatant.client.features.theme.Theme;
|
| 12 | import net.minecraft.client.Minecraft;
|
| 13 | import net.minecraft.resources.Identifier;
|
| 14 | import net.minecraft.util.Mth;
|
| 15 | import net.minecraft.world.phys.AABB;
|
| 16 | import net.minecraft.world.phys.Vec3;
|
| 17 | import org.joml.Quaternionf;
|
| 18 | import org.joml.Vector3f;
|
| 19 | import combatant.client.config.common.CommonSettingSchemas;
|
| 20 | import combatant.client.features.module.Module;
|
| 21 | import combatant.client.features.module.ModuleCategory;
|
| 22 | import combatant.client.features.module.ModuleInfo;
|
| 23 | import combatant.client.features.module.WorldPhase;
|
| 24 | import combatant.client.render.engine.RenderState;
|
| 25 | import combatant.client.render.engine.TextureStorage;
|
| 26 | import combatant.client.render.engine.animation.AnimationUtility;
|
| 27 | import combatant.client.render.engine.animation.AnimatedRenderColors;
|
| 28 | import combatant.client.render.engine.color.ColorBlendMode;
|
| 29 | import combatant.client.render.engine.color.ColorEffects;
|
| 30 | import combatant.client.render.engine.pipeline.CombatantRenderPipelines;
|
| 31 | import combatant.client.render.engine.profiler.RenderCostProfiler;
|
| 32 | import combatant.client.render.engine.profiler.ProfilerPhase;
|
| 33 | import combatant.client.render.engine.renderer.Renderer3D;
|
| 34 | import combatant.client.render.engine.uniform.MeshBuilder;
|
| 35 | import combatant.client.render.engine.uniform.impl.TextureTintUniforms;
|
| 36 | import combatant.client.render.effects.particle.ParticleSimulationProfile;
|
| 37 |
|
| 38 | import java.util.ArrayList;
|
| 39 | import java.util.List;
|
| 40 | import java.util.concurrent.ThreadLocalRandom;
|
| 41 |
|
| 42 | //todo Description
|
| 43 | @ModuleInfo(
|
| 44 | id = "worldparticles",
|
| 45 | displayName = "WorldParticles",
|
| 46 | category = ModuleCategory.VISUALS
|
| 47 | )
|
| 48 | public class WorldParticles extends Module {
|
| 49 | private static final float SPRITE_SIZE_MULTIPLIER = 4.0f;
|
| 50 | private static final float SPRITE_ALPHA_MULTIPLIER = 0.40f;
|
| 51 | private static final float DIAGONAL_ALPHA_MULTIPLIER = 0.40f;
|
| 52 | private static final float OUTLINE_ALPHA_MULTIPLIER = 205.0f / 255.0f;
|
| 53 | private static final float QUAD_SWAY_MULTIPLIER = 0.22f;
|
| 54 | private static final float QUAD_BREATHE_MULTIPLIER = 0.10f;
|
| 55 | private static final float QUAD_ROLL_SPEED = 0.32f;
|
| 56 | private static final float BUBBLE_FILL_SIZE_MULTIPLIER = 3.15f;
|
| 57 | // Dense geometry is intentional here: the shell itself owns depth, so the silhouette must not
|
| 58 | // collapse to a visibly faceted low-poly sphere at close range. 16x32 stays cheap enough for
|
| 59 | // the module's default particle counts while keeping world-depth intersections stable.
|
| 60 | private static final float BUBBLE_CULL_EXTENT_MULTIPLIER = BUBBLE_FILL_SIZE_MULTIPLIER * 1.18f;
|
| 61 | private static final int BUBBLE_SPHERE_STACKS = 16;
|
| 62 | private static final int BUBBLE_SPHERE_SLICES = 32;
|
| 63 | private static final int BUBBLE_SPHERE_ROW_SIZE = BUBBLE_SPHERE_SLICES + 1;
|
| 64 | private static final int BUBBLE_SPHERE_SAMPLE_COUNT = (BUBBLE_SPHERE_STACKS + 1) * BUBBLE_SPHERE_ROW_SIZE;
|
| 65 | private static final int BUBBLE_SPHERE_INTERIOR_STACKS = BUBBLE_SPHERE_STACKS - 1;
|
| 66 | private static final int BUBBLE_SPHERE_MESH_VERTEX_COUNT = 2 + BUBBLE_SPHERE_INTERIOR_STACKS * BUBBLE_SPHERE_SLICES;
|
| 67 | private static final int BUBBLE_SPHERE_MESH_INDEX_COUNT = 6 * BUBBLE_SPHERE_SLICES * BUBBLE_SPHERE_INTERIOR_STACKS;
|
| 68 | private static final float[] BUBBLE_SPHERE_X = new float[BUBBLE_SPHERE_SAMPLE_COUNT];
|
| 69 | private static final float[] BUBBLE_SPHERE_Y = new float[BUBBLE_SPHERE_SAMPLE_COUNT];
|
| 70 | private static final float[] BUBBLE_SPHERE_Z = new float[BUBBLE_SPHERE_SAMPLE_COUNT];
|
| 71 | private static final float FUNNEL_EYE_SIZE_MULTIPLIER = 4.35f;
|
| 72 | private static final float FUNNEL_DISTORTION_SIZE_MULTIPLIER = 5.25f;
|
| 73 | private static final float FUNNEL_DISTORTION_OUTER_SIZE_MULTIPLIER = 6.85f;
|
| 74 | private static final float FUNNEL_DISTORTION_INNER_SIZE_MULTIPLIER = 3.95f;
|
| 75 | private static final float FUNNEL_EYE_ALPHA_MULTIPLIER = 0.72f;
|
| 76 | private static final float FUNNEL_DISTORTION_ALPHA_MULTIPLIER = 0.16f;
|
| 77 | private static final float FUNNEL_DISTORTION_OUTER_ALPHA_MULTIPLIER = 0.085f;
|
| 78 | private static final float FUNNEL_DISTORTION_INNER_ALPHA_MULTIPLIER = 0.115f;
|
| 79 | private static final float FUNNEL_RIM_ALPHA_MULTIPLIER = 0.22f;
|
| 80 | private static final float FUNNEL_GHOST_ALPHA_MULTIPLIER = 0.18f;
|
| 81 | private static final float FUNNEL_FLASH_ALPHA_MULTIPLIER = 0.34f;
|
| 82 | private static final float FUNNEL_LEAK_ALPHA_MULTIPLIER = 0.32f;
|
| 83 | private static final float MOTION_SCALE = 0.04f;
|
| 84 | private static final ParticleSimulationProfile PARTICLE_SIMULATION =
|
| 85 | ParticleSimulationProfile.drag(0.98f, 0.98f);
|
| 86 | private static final long ALPHA_ANIM_MS = 1000L;
|
| 87 | private static final int[][] CUBE_EDGES = {
|
| 88 | {0, 1}, {1, 2}, {2, 3}, {3, 0},
|
| 89 | {4, 5}, {5, 6}, {6, 7}, {7, 4},
|
| 90 | {0, 4}, {1, 5}, {2, 6}, {3, 7}
|
| 91 | };
|
| 92 | private static final int[][] BODY_DIAGONALS = {
|
| 93 | {0, 6}, {1, 7}, {2, 4}, {3, 5}
|
| 94 | };
|
| 95 |
|
| 96 | static {
|
| 97 | int vertex = 0;
|
| 98 | for (int stack = 0; stack <= BUBBLE_SPHERE_STACKS; stack++) {
|
| 99 | float theta = (float) Math.PI * stack / (float) BUBBLE_SPHERE_STACKS;
|
| 100 | float sinTheta = (float) Math.sin(theta);
|
| 101 | float y = (float) Math.cos(theta);
|
| 102 | for (int slice = 0; slice <= BUBBLE_SPHERE_SLICES; slice++) {
|
| 103 | float phi = (float) (Math.PI * 2.0) * slice / (float) BUBBLE_SPHERE_SLICES;
|
| 104 | BUBBLE_SPHERE_X[vertex] = (float) Math.cos(phi) * sinTheta;
|
| 105 | BUBBLE_SPHERE_Y[vertex] = y;
|
| 106 | BUBBLE_SPHERE_Z[vertex] = (float) Math.sin(phi) * sinTheta;
|
| 107 | vertex++;
|
| 108 | }
|
| 109 | }
|
| 110 | }
|
| 111 |
|
| 112 | private final Minecraft mc = Minecraft.getInstance();
|
| 113 | private final EnumValue<Mode> mode =
|
| 114 | enumSetting("mode", "mode", Mode.QUADS);
|
| 115 | private final BooleanValue depthTest =
|
| 116 | boolCommon("depth_test", CommonSettingSchemas.RENDER_DEPTH_TEST, true);
|
| 117 | private final RGBAColorValue color =
|
| 118 | common(color("color", "#FF8ED4FF"), CommonSettingSchemas.RENDER_PRIMARY_COLOR.commonI18nKey());
|
| 119 | private final ModeValue colorMode =
|
| 120 | modeSetting("worldParticlesColorMode", "color_mode", "Theme",
|
| 121 | "Static", "Rainbow", "LightRainbow", "Sky", "Fade", "DoubleColor", "Analogous", "Theme");
|
| 122 | private final NumberValue<Integer> colorSpeed =
|
| 123 | num("worldParticlesColorSpeed", "color_speed", 18, 2, 54);
|
| 124 | private final NumberValue<Integer> colorPhase =
|
| 125 | num("worldParticlesColorPhase", "color_phase", 0, 0, 360);
|
| 126 | private final NumberValue<Integer> colorSpread =
|
| 127 | num("worldParticlesColorSpread", "color_spread", 90, -720, 720);
|
| 128 | private final RGBAColorValue color2 =
|
| 129 | visibleWhen(color("worldParticlesColor2", "color2", "#FF55FFFF"), this::usesSecondaryColor);
|
| 130 | private final NumberValue<Integer> maxParticles =
|
| 131 | num("max_particles", 100, 1, 400);
|
| 132 | private final NumberValue<Integer> spawnPerTick =
|
| 133 | num("spawn_per_tick", 1, 1, 20);
|
| 134 | private final NumberValue<Double> radius =
|
| 135 | num("radius", 20.0, 1.0, 64.0);
|
| 136 | private final NumberValue<Double> height =
|
| 137 | num("height", 5.0, 0.5, 16.0);
|
| 138 | private final NumberValue<Integer> lifeMinMs =
|
| 139 | num("life_min_ms", 1500, 100, 10000);
|
| 140 | private final NumberValue<Integer> lifeMaxMs =
|
| 141 | num("life_max_ms", 4500, 100, 15000);
|
| 142 | private final NumberValue<Double> sizeMin =
|
| 143 | num("size_min", 0.10, 0.02, 1.0);
|
| 144 | private final NumberValue<Double> sizeMax =
|
| 145 | num("size_max", 0.30, 0.02, 1.5);
|
| 146 | private final NumberValue<Double> lineWidth =
|
| 147 | visibleWhen(num("line_width", 1.0, 0.5, 4.0), () -> !isFunnelMode() && !isBubbleMode());
|
| 148 | private final EnumValue<ColorBlendMode> funnelTintMode =
|
| 149 | visibleWhen(enumSetting("funnel_tint_mode", "funnel_tint_mode", ColorBlendMode.ORIGINAL), this::isFunnelMode);
|
| 150 | private final BooleanValue funnelTintSyncTheme =
|
| 151 | visibleWhen(bool("funnel_tint_sync_theme", "funnel_tint_sync_theme", true), this::isFunnelTintControlsVisible);
|
| 152 | private final RGBColorValue funnelTintColor =
|
| 153 | visibleWhen(colorNoAlpha("funnel_tint_color", "funnel_tint_color", "#78D7FF"), this::isManualFunnelTintVisible);
|
| 154 | private final NumberValue<Float> funnelTintStrength =
|
| 155 | visibleWhen(num("funnel_tint_strength", "funnel_tint_strength", 0.45f, 0.0f, 1.0f), this::isFunnelTintControlsVisible);
|
| 156 | private final List<Particle> particles = new ArrayList<>();
|
| 157 |
|
| 158 | private static double randomDoubleClosed(ThreadLocalRandom random, double min, double max) {
|
| 159 | if (!Double.isFinite(min) || !Double.isFinite(max)) {
|
| 160 | return 0.02;
|
| 161 | }
|
| 162 | double low = Math.min(min, max);
|
| 163 | double high = Math.max(min, max);
|
| 164 | if (high <= low) {
|
| 165 | return low;
|
| 166 | }
|
| 167 | return random.nextDouble(low, high);
|
| 168 | }
|
| 169 |
|
| 170 | private static long randomLongClosed(ThreadLocalRandom random, long min, long max) {
|
| 171 | long low = Math.min(min, max);
|
| 172 | long high = Math.max(min, max);
|
| 173 | if (high <= low) {
|
| 174 | return low;
|
| 175 | }
|
| 176 | if (high == Long.MAX_VALUE) {
|
| 177 | return random.nextLong(low, Long.MAX_VALUE) + 1L;
|
| 178 | }
|
| 179 | return random.nextLong(low, high + 1L);
|
| 180 | }
|
| 181 |
|
| 182 | private static Vec3 offsetInBillboardPlane(Vec3 pos, Quaternionf camRot, float angle, float distance) {
|
| 183 | Vector3f right = new Vector3f(1.0f, 0.0f, 0.0f).rotate(camRot).mul((float) Math.cos(angle) * distance);
|
| 184 | Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f).rotate(camRot).mul((float) Math.sin(angle) * distance);
|
| 185 | return pos.add(right.x() + up.x(), right.y() + up.y(), right.z() + up.z());
|
| 186 | }
|
| 187 |
|
| 188 | private static void addBillboardQuad(MeshBuilder mesh, double cx, double cy, double cz,
|
| 189 | float size, Quaternionf camRot, int argb) {
|
| 190 | addBillboardQuad(mesh, cx, cy, cz, size, camRot, 0.0f, argb);
|
| 191 | }
|
| 192 |
|
| 193 | private static void addBillboardQuad(MeshBuilder mesh, double cx, double cy, double cz,
|
| 194 | float size, Quaternionf camRot, float rollRadians, int argb) {
|
| 195 | addBillboardQuadGradient(mesh, cx, cy, cz, size, camRot, rollRadians, argb, argb, argb, argb);
|
| 196 | }
|
| 197 |
|
| 198 | private static void addBillboardQuadGradient(MeshBuilder mesh, double cx, double cy, double cz,
|
| 199 | float size, Quaternionf camRot, float rollRadians,
|
| 200 | int bottomLeftArgb,
|
| 201 | int bottomRightArgb,
|
| 202 | int topRightArgb,
|
| 203 | int topLeftArgb) {
|
| 204 | Vector3f baseRight = new Vector3f(1.0f, 0.0f, 0.0f).rotate(camRot);
|
| 205 | Vector3f baseUp = new Vector3f(0.0f, 1.0f, 0.0f).rotate(camRot);
|
| 206 | addBillboardQuadGradient(mesh, cx, cy, cz, size, baseRight, baseUp, rollRadians,
|
| 207 | bottomLeftArgb, bottomRightArgb, topRightArgb, topLeftArgb);
|
| 208 | }
|
| 209 |
|
| 210 | private static void addBillboardQuadGradient(MeshBuilder mesh, double cx, double cy, double cz,
|
| 211 | float size, Vector3f baseRight, Vector3f baseUp,
|
| 212 | float rollRadians,
|
| 213 | int bottomLeftArgb,
|
| 214 | int bottomRightArgb,
|
| 215 | int topRightArgb,
|
| 216 | int topLeftArgb) {
|
| 217 | float cos = (float) Math.cos(rollRadians);
|
| 218 | float sin = (float) Math.sin(rollRadians);
|
| 219 |
|
| 220 | float rightX = (baseRight.x() * cos + baseUp.x() * sin) * size;
|
| 221 | float rightY = (baseRight.y() * cos + baseUp.y() * sin) * size;
|
| 222 | float rightZ = (baseRight.z() * cos + baseUp.z() * sin) * size;
|
| 223 | float upX = (baseUp.x() * cos - baseRight.x() * sin) * size;
|
| 224 | float upY = (baseUp.y() * cos - baseRight.y() * sin) * size;
|
| 225 | float upZ = (baseUp.z() * cos - baseRight.z() * sin) * size;
|
| 226 |
|
| 227 | double p1x = cx - rightX - upX;
|
| 228 | double p1y = cy - rightY - upY;
|
| 229 | double p1z = cz - rightZ - upZ;
|
| 230 | double p2x = cx + rightX - upX;
|
| 231 | double p2y = cy + rightY - upY;
|
| 232 | double p2z = cz + rightZ - upZ;
|
| 233 | double p3x = cx + rightX + upX;
|
| 234 | double p3y = cy + rightY + upY;
|
| 235 | double p3z = cz + rightZ + upZ;
|
| 236 | double p4x = cx - rightX + upX;
|
| 237 | double p4y = cy - rightY + upY;
|
| 238 | double p4z = cz - rightZ + upZ;
|
| 239 |
|
| 240 | mesh.ensureQuadCapacity();
|
| 241 | int i1 = mesh.vec3(p1x, p1y, p1z).vec2(0.0, 1.0).colorArgb(bottomLeftArgb).next();
|
| 242 | int i2 = mesh.vec3(p2x, p2y, p2z).vec2(1.0, 1.0).colorArgb(bottomRightArgb).next();
|
| 243 | int i3 = mesh.vec3(p3x, p3y, p3z).vec2(1.0, 0.0).colorArgb(topRightArgb).next();
|
| 244 | int i4 = mesh.vec3(p4x, p4y, p4z).vec2(0.0, 0.0).colorArgb(topLeftArgb).next();
|
| 245 | mesh.quad(i1, i2, i3, i4);
|
| 246 | }
|
| 247 |
|
| 248 | private static void addBillboardRect(MeshBuilder mesh, double cx, double cy, double cz,
|
| 249 | float halfWidth, float halfHeight, Quaternionf camRot,
|
| 250 | float rollRadians, int argb) {
|
| 251 | Vector3f baseRight = new Vector3f(1.0f, 0.0f, 0.0f).rotate(camRot);
|
| 252 | Vector3f baseUp = new Vector3f(0.0f, 1.0f, 0.0f).rotate(camRot);
|
| 253 | float cos = (float) Math.cos(rollRadians);
|
| 254 | float sin = (float) Math.sin(rollRadians);
|
| 255 |
|
| 256 | Vector3f right = new Vector3f(baseRight).mul(cos).add(new Vector3f(baseUp).mul(sin)).mul(halfWidth);
|
| 257 | Vector3f up = new Vector3f(baseUp).mul(cos).sub(new Vector3f(baseRight).mul(sin)).mul(halfHeight);
|
| 258 |
|
| 259 | double p1x = cx - right.x() - up.x();
|
| 260 | double p1y = cy - right.y() - up.y();
|
| 261 | double p1z = cz - right.z() - up.z();
|
| 262 | double p2x = cx + right.x() - up.x();
|
| 263 | double p2y = cy + right.y() - up.y();
|
| 264 | double p2z = cz + right.z() - up.z();
|
| 265 | double p3x = cx + right.x() + up.x();
|
| 266 | double p3y = cy + right.y() + up.y();
|
| 267 | double p3z = cz + right.z() + up.z();
|
| 268 | double p4x = cx - right.x() + up.x();
|
| 269 | double p4y = cy - right.y() + up.y();
|
| 270 | double p4z = cz - right.z() + up.z();
|
| 271 |
|
| 272 | mesh.ensureQuadCapacity();
|
| 273 | int i1 = mesh.vec3(p1x, p1y, p1z).vec2(0.0, 1.0).colorArgb(argb).next();
|
| 274 | int i2 = mesh.vec3(p2x, p2y, p2z).vec2(1.0, 1.0).colorArgb(argb).next();
|
| 275 | int i3 = mesh.vec3(p3x, p3y, p3z).vec2(1.0, 0.0).colorArgb(argb).next();
|
| 276 | int i4 = mesh.vec3(p4x, p4y, p4z).vec2(0.0, 0.0).colorArgb(argb).next();
|
| 277 | mesh.quad(i1, i2, i3, i4);
|
| 278 | }
|
| 279 |
|
| 280 | private static void addCube(MeshBuilder mesh, Vec3 pos, Vec3 rotation, float size, int diagonalArgb, int outlineArgb) {
|
| 281 | Quaternionf quaternion = new Quaternionf().rotationXYZ((float) rotation.x, (float) rotation.y, (float) rotation.z);
|
| 282 | Vector3f[] corners = new Vector3f[]{
|
| 283 | rotatedCorner(-0.5f, -0.5f, -0.5f, quaternion, size, pos),
|
| 284 | rotatedCorner(0.5f, -0.5f, -0.5f, quaternion, size, pos),
|
| 285 | rotatedCorner(0.5f, 0.5f, -0.5f, quaternion, size, pos),
|
| 286 | rotatedCorner(-0.5f, 0.5f, -0.5f, quaternion, size, pos),
|
| 287 | rotatedCorner(-0.5f, -0.5f, 0.5f, quaternion, size, pos),
|
| 288 | rotatedCorner(0.5f, -0.5f, 0.5f, quaternion, size, pos),
|
| 289 | rotatedCorner(0.5f, 0.5f, 0.5f, quaternion, size, pos),
|
| 290 | rotatedCorner(-0.5f, 0.5f, 0.5f, quaternion, size, pos)
|
| 291 | };
|
| 292 |
|
| 293 | for (int[] edge : CUBE_EDGES) {
|
| 294 | addLine(mesh, corners[edge[0]], corners[edge[1]], outlineArgb);
|
| 295 | }
|
| 296 | for (int[] diagonal : BODY_DIAGONALS) {
|
| 297 | addLine(mesh, corners[diagonal[0]], corners[diagonal[1]], diagonalArgb);
|
| 298 | }
|
| 299 | }
|
| 300 |
|
| 301 | private static Vector3f rotatedCorner(float x, float y, float z, Quaternionf quaternion, float size, Vec3 pos) {
|
| 302 | return new Vector3f(x, y, z)
|
| 303 | .rotate(quaternion)
|
| 304 | .mul(size)
|
| 305 | .add((float) pos.x, (float) pos.y, (float) pos.z);
|
| 306 | }
|
| 307 |
|
| 308 | private static void addLine(MeshBuilder mesh, Vector3f from, Vector3f to, int argb) {
|
| 309 | addLineGradient(mesh, from, to, argb, argb);
|
| 310 | }
|
| 311 |
|
| 312 | private static void addLineGradient(MeshBuilder mesh, Vector3f from, Vector3f to, int fromArgb, int toArgb) {
|
| 313 | mesh.ensureLineCapacity();
|
| 314 | int i1 = mesh.vec3(from.x(), from.y(), from.z()).colorArgb(fromArgb).next();
|
| 315 | int i2 = mesh.vec3(to.x(), to.y(), to.z()).colorArgb(toArgb).next();
|
| 316 | mesh.line(i1, i2);
|
| 317 | }
|
| 318 |
|
| 319 | private static void addSphereShell(MeshBuilder mesh,
|
| 320 | Vec3 center,
|
| 321 | float radius,
|
| 322 | int baseColor,
|
| 323 | float alpha,
|
| 324 | float ageSeconds,
|
| 325 | float visualPhase) {
|
| 326 | int baseVertex = mesh.getVertexCount();
|
| 327 | mesh.ensureCapacity(BUBBLE_SPHERE_MESH_VERTEX_COUNT, BUBBLE_SPHERE_MESH_INDEX_COUNT);
|
| 328 |
|
| 329 | addSphereVertex(mesh, center, radius, baseColor, alpha, ageSeconds, visualPhase, 0);
|
| 330 | for (int stack = 1; stack < BUBBLE_SPHERE_STACKS; stack++) {
|
| 331 | int sampleRow = stack * BUBBLE_SPHERE_ROW_SIZE;
|
| 332 | for (int slice = 0; slice < BUBBLE_SPHERE_SLICES; slice++) {
|
| 333 | addSphereVertex(mesh, center, radius, baseColor, alpha, ageSeconds, visualPhase, sampleRow + slice);
|
| 334 | }
|
| 335 | }
|
| 336 | addSphereVertex(mesh, center, radius, baseColor, alpha, ageSeconds, visualPhase,
|
| 337 | BUBBLE_SPHERE_STACKS * BUBBLE_SPHERE_ROW_SIZE);
|
| 338 |
|
| 339 | int firstRing = baseVertex + 1;
|
| 340 | int bottom = firstRing + BUBBLE_SPHERE_INTERIOR_STACKS * BUBBLE_SPHERE_SLICES;
|
| 341 | for (int slice = 0; slice < BUBBLE_SPHERE_SLICES; slice++) {
|
| 342 | int next = (slice + 1) % BUBBLE_SPHERE_SLICES;
|
| 343 | mesh.triangle(baseVertex, firstRing + next, firstRing + slice);
|
| 344 | }
|
| 345 | for (int stack = 0; stack < BUBBLE_SPHERE_INTERIOR_STACKS - 1; stack++) {
|
| 346 | int row = firstRing + stack * BUBBLE_SPHERE_SLICES;
|
| 347 | int nextRow = row + BUBBLE_SPHERE_SLICES;
|
| 348 | for (int slice = 0; slice < BUBBLE_SPHERE_SLICES; slice++) {
|
| 349 | int next = (slice + 1) % BUBBLE_SPHERE_SLICES;
|
| 350 | int a = row + slice;
|
| 351 | int b = nextRow + slice;
|
| 352 | int c = nextRow + next;
|
| 353 | int d = row + next;
|
| 354 | mesh.triangle(a, c, b);
|
| 355 | mesh.triangle(c, a, d);
|
| 356 | }
|
| 357 | }
|
| 358 | int lastRing = bottom - BUBBLE_SPHERE_SLICES;
|
| 359 | for (int slice = 0; slice < BUBBLE_SPHERE_SLICES; slice++) {
|
| 360 | int next = (slice + 1) % BUBBLE_SPHERE_SLICES;
|
| 361 | mesh.triangle(bottom, lastRing + slice, lastRing + next);
|
| 362 | }
|
| 363 | }
|
| 364 |
|
| 365 | private static void addSphereVertex(MeshBuilder mesh,
|
| 366 | Vec3 center,
|
| 367 | float radius,
|
| 368 | int baseColor,
|
| 369 | float alpha,
|
| 370 | float ageSeconds,
|
| 371 | float visualPhase,
|
| 372 | int sample) {
|
| 373 | float nx = BUBBLE_SPHERE_X[sample];
|
| 374 | float ny = BUBBLE_SPHERE_Y[sample];
|
| 375 | float nz = BUBBLE_SPHERE_Z[sample];
|
| 376 | float px = (float) center.x + nx * radius;
|
| 377 | float py = (float) center.y + ny * radius;
|
| 378 | float pz = (float) center.z + nz * radius;
|
| 379 |
|
| 380 | // POS3_TEXTURE_COLOR_PARAMS2 is reused as a compact world-surface payload:
|
| 381 | // Params.xyz = unit normal, Params.w = radius; Params2.xy = age/phase.
|
| 382 | // The custom vertex shader performs the membrane deformation from this data, keeping
|
| 383 | // deformation and the rasterized depth surface identical.
|
| 384 | mesh.vec3(px, py, pz)
|
| 385 | .vec2(0.0, 0.0)
|
| 386 | .colorArgb(multiplyAlpha(baseColor, alpha))
|
| 387 | .vec4(nx, ny, nz, radius)
|
| 388 | .vec4(ageSeconds, visualPhase, 0.0f, 0.0f)
|
| 389 | .next();
|
| 390 | }
|
| 391 |
|
| 392 | private static int multiplyAlpha(int argb, float alphaMultiplier) {
|
| 393 | int alpha = (argb >>> 24) & 0xFF;
|
| 394 | int outAlpha = Mth.clamp(Math.round(alpha * alphaMultiplier), 0, 255);
|
| 395 | return (outAlpha << 24) | (argb & 0x00FFFFFF);
|
| 396 | }
|
| 397 |
|
| 398 | @Override
|
| 399 | public WorldPhase getWorldPhase() {
|
| 400 | return WorldPhase.END_MAIN;
|
| 401 | }
|
| 402 |
|
| 403 | @Override
|
| 404 | public void onDisable() {
|
| 405 | particles.clear();
|
| 406 | }
|
| 407 |
|
| 408 | @Override
|
| 409 | public void onTick() {
|
| 410 | if (!isEnabled() || mc.player == null || mc.level == null) {
|
| 411 | return;
|
| 412 | }
|
| 413 |
|
| 414 | long nowMs = System.currentTimeMillis();
|
| 415 | particles.removeIf(particle -> particle.isExpired(nowMs));
|
| 416 | for (Particle particle : particles) {
|
| 417 | particle.tick();
|
| 418 | }
|
| 419 |
|
| 420 | int targetCount = Math.max(1, maxParticles.get());
|
| 421 | int available = targetCount - particles.size();
|
| 422 | if (available <= 0) {
|
| 423 | return;
|
| 424 | }
|
| 425 |
|
| 426 | int spawnCount = Mth.clamp(spawnPerTick.get(), 0, available);
|
| 427 | for (int i = 0; i < spawnCount; i++) {
|
| 428 | Particle particle = createParticle();
|
| 429 | if (particle != null) {
|
| 430 | particles.add(particle);
|
| 431 | }
|
| 432 | }
|
| 433 | }
|
| 434 |
|
| 435 | @Override
|
| 436 | public void onRenderWorldEngine(Renderer3D renderer, Renderer3D depthRenderer, float tickDelta) {
|
| 437 | if (!isEnabled() || particles.isEmpty() || mc.player == null || mc.level == null) {
|
| 438 | return;
|
| 439 | }
|
| 440 |
|
| 441 | try (RenderCostProfiler.Scope ignored = RenderCostProfiler.worldEffect("world_particles:" + mode.get())) {
|
| 442 | boolean useDepth = depthTest.get();
|
| 443 | Renderer3D.DepthMode depthMode = useDepth ? Renderer3D.DepthMode.PRE_DEPTH : Renderer3D.DepthMode.MAIN;
|
| 444 | if (isFunnelMode()) {
|
| 445 | renderFunnel(renderer, useDepth, depthMode, tickDelta);
|
| 446 | return;
|
| 447 | }
|
| 448 |
|
| 449 | boolean bubbleMode = isBubbleMode();
|
| 450 | MeshBuilder spriteMesh = bubbleMode ? null : renderer.batchTextured(
|
| 451 | useDepth ? CombatantRenderPipelines.WORLD_TEXTURED_ADDITIVE_LIQUID_IGNORE
|
| 452 | : CombatantRenderPipelines.WORLD_TEXTURED_ADDITIVE,
|
| 453 | TextureStorage.BLOOM,
|
| 454 | depthMode
|
| 455 | );
|
| 456 |
|
| 457 | MeshBuilder lineMesh = null;
|
| 458 | if (!bubbleMode) {
|
| 459 | float prevLineWidth = RenderState.lineWidth;
|
| 460 | try {
|
| 461 | RenderState.lineWidth = Math.max(0.5f, lineWidth.get().floatValue());
|
| 462 | lineMesh = renderer.batch(
|
| 463 | useDepth ? CombatantRenderPipelines.WORLD_COLORED_LINES_LIQUID_IGNORE
|
| 464 | : CombatantRenderPipelines.WORLD_COLORED_LINES,
|
| 465 | depthMode
|
| 466 | );
|
| 467 | } finally {
|
| 468 | RenderState.lineWidth = prevLineWidth;
|
| 469 | }
|
| 470 | }
|
| 471 |
|
| 472 | Quaternionf camRot = RenderState.cameraRotation;
|
| 473 | MeshBuilder bubbleShellMesh = bubbleMode
|
| 474 | ? renderer.batch(
|
| 475 | useDepth ? CombatantRenderPipelines.WORLD_BUBBLE_SURFACE_DEPTH
|
| 476 | : CombatantRenderPipelines.WORLD_BUBBLE_SURFACE,
|
| 477 | depthMode
|
| 478 | )
|
| 479 | : null;
|
| 480 |
|
| 481 | int particleCount = particles.size();
|
| 482 | if (bubbleShellMesh != null) {
|
| 483 | bubbleShellMesh.ensureCapacity(
|
| 484 | particleCount * BUBBLE_SPHERE_MESH_VERTEX_COUNT,
|
| 485 | particleCount * BUBBLE_SPHERE_MESH_INDEX_COUNT
|
| 486 | );
|
| 487 | }
|
| 488 | if (spriteMesh != null) {
|
| 489 | spriteMesh.ensureCapacity(particleCount * 4, particleCount * 6);
|
| 490 | }
|
| 491 | if (lineMesh != null) {
|
| 492 | lineMesh.ensureCapacity(
|
| 493 | particleCount * 32,
|
| 494 | particleCount * 32
|
| 495 | );
|
| 496 | }
|
| 497 |
|
| 498 | long nowMs = System.currentTimeMillis();
|
| 499 | try (ProfilerPhase.Scope geometryScope = ProfilerPhase.scope(
|
| 500 | bubbleMode ? "world_particles:bubble_geometry" : "world_particles:quad_geometry")) {
|
| 501 | for (int i = 0; i < particles.size(); i++) {
|
| 502 | Particle particle = particles.get(i);
|
| 503 | float alpha = particle.alpha(nowMs);
|
| 504 | if (alpha <= 0.003f) {
|
| 505 | continue;
|
| 506 | }
|
| 507 |
|
| 508 | Vec3 pos = particle.interpolatePos(tickDelta);
|
| 509 | if (bubbleMode && !bubbleInFrustum(particle, pos)) {
|
| 510 | continue;
|
| 511 | }
|
| 512 | int baseColor = colorForParticle(particle, i);
|
| 513 |
|
| 514 | if (bubbleMode) {
|
| 515 | renderAirBubble(bubbleShellMesh, particle, pos, alpha, baseColor, nowMs);
|
| 516 | continue;
|
| 517 | }
|
| 518 |
|
| 519 | long ageMs = particle.ageMs(nowMs);
|
| 520 | float ageSeconds = ageMs * 0.001f;
|
| 521 | float pulse = AnimationUtility.smoothstep(
|
| 522 | 0.5f + 0.5f * (float) Math.sin(ageSeconds * 1.65f + particle.visualPhase));
|
| 523 | float appear = AnimationUtility.easeOutCubic(ageMs / 420.0f);
|
| 524 | float visualScale = (0.72f + 0.28f * appear)
|
| 525 | * (1.0f - QUAD_BREATHE_MULTIPLIER * 0.5f + QUAD_BREATHE_MULTIPLIER * pulse);
|
| 526 | float sway = particle.size * QUAD_SWAY_MULTIPLIER;
|
| 527 | float orbit = ageSeconds * 0.54f + particle.visualPhase;
|
| 528 | pos = pos.add(
|
| 529 | Math.cos(orbit) * sway,
|
| 530 | Math.sin(ageSeconds * 0.78f + particle.visualPhase) * sway * 0.32f,
|
| 531 | Math.sin(orbit) * sway
|
| 532 | );
|
| 533 |
|
| 534 | if (spriteMesh != null) {
|
| 535 | int spriteArgb = multiplyAlpha(baseColor, alpha * SPRITE_ALPHA_MULTIPLIER);
|
| 536 | float roll = particle.visualPhase + ageSeconds * QUAD_ROLL_SPEED;
|
| 537 | addBillboardQuad(spriteMesh, pos.x, pos.y, pos.z,
|
| 538 | particle.size * SPRITE_SIZE_MULTIPLIER * visualScale, camRot, roll, spriteArgb);
|
| 539 | }
|
| 540 |
|
| 541 | if (lineMesh != null) {
|
| 542 | Vec3 rotation = particle.interpolateRotation(tickDelta);
|
| 543 | int diagonalArgb = multiplyAlpha(baseColor, alpha * DIAGONAL_ALPHA_MULTIPLIER);
|
| 544 | int outlineArgb = multiplyAlpha(baseColor, alpha * OUTLINE_ALPHA_MULTIPLIER);
|
| 545 | addCube(lineMesh, pos, rotation, particle.size * visualScale, diagonalArgb, outlineArgb);
|
| 546 | }
|
| 547 | }
|
| 548 | }
|
| 549 | }
|
| 550 | }
|
| 551 |
|
| 552 | private void renderFunnel(Renderer3D renderer, boolean useDepth, Renderer3D.DepthMode depthMode, float tickDelta) {
|
| 553 | ColorBlendMode tintMode = funnelTintMode.get();
|
| 554 | TextureTintUniforms.update(
|
| 555 | funnelTintRgb(),
|
| 556 | tintMode == ColorBlendMode.ORIGINAL ? 0.0f : Mth.clamp(funnelTintStrength.get(), 0.0f, 1.0f),
|
| 557 | tintMode.ordinal()
|
| 558 | );
|
| 559 |
|
| 560 | MeshBuilder distortionMesh = tintedTexturedBatch(renderer, useDepth, depthMode, TextureStorage.FUNNEL_DISTORTION);
|
| 561 | MeshBuilder eyeMesh = tintedTexturedBatch(renderer, useDepth, depthMode, TextureStorage.FUNNEL_EYE);
|
| 562 | MeshBuilder bloomMesh = tintedTexturedBatch(renderer, useDepth, depthMode, TextureStorage.BLOOM);
|
| 563 | if (distortionMesh == null && eyeMesh == null && bloomMesh == null) {
|
| 564 | return;
|
| 565 | }
|
| 566 |
|
| 567 | int particleCount = particles.size();
|
| 568 | if (distortionMesh != null) {
|
| 569 | distortionMesh.ensureCapacity(particleCount * 12, particleCount * 18);
|
| 570 | }
|
| 571 | if (eyeMesh != null) {
|
| 572 | eyeMesh.ensureCapacity(particleCount * 16, particleCount * 24);
|
| 573 | }
|
| 574 | if (bloomMesh != null) {
|
| 575 | bloomMesh.ensureCapacity(particleCount * 20, particleCount * 30);
|
| 576 | }
|
| 577 |
|
| 578 | Quaternionf camRot = RenderState.cameraRotation;
|
| 579 | for (int i = 0; i < particles.size(); i++) {
|
| 580 | Particle particle = particles.get(i);
|
| 581 | float alpha = particle.funnelAlpha();
|
| 582 | if (alpha <= 0.003f) {
|
| 583 | continue;
|
| 584 | }
|
| 585 |
|
| 586 | Vec3 pos = particle.interpolatePos(tickDelta);
|
| 587 | int baseColor = colorForParticle(particle, i);
|
| 588 | float ageSeconds = particle.ageMs() / 1000.0f;
|
| 589 | float scale = particle.funnelScale();
|
| 590 | float pulse = 0.5f + 0.5f * (float) Math.sin(particle.ageMs() * 0.0048f + particle.visualPhase);
|
| 591 | float rimPulse = AnimationUtility.smoothstep(pulse);
|
| 592 |
|
| 593 | if (distortionMesh != null) {
|
| 594 | float outerRoll = particle.visualPhase * 0.63f - ageSeconds * particle.distortionSpin * 0.54f;
|
| 595 | int outerArgb = funnelColor(baseColor, 0xFFFFFF, alpha * FUNNEL_DISTORTION_OUTER_ALPHA_MULTIPLIER * (0.82f + rimPulse * 0.18f));
|
| 596 | addBillboardQuad(
|
| 597 | distortionMesh,
|
| 598 | pos.x, pos.y, pos.z,
|
| 599 | particle.size * FUNNEL_DISTORTION_OUTER_SIZE_MULTIPLIER * scale * (1.0f + rimPulse * 0.055f),
|
| 600 | camRot,
|
| 601 | outerRoll,
|
| 602 | outerArgb
|
| 603 | );
|
| 604 |
|
| 605 | float distortionRoll = particle.visualPhase + ageSeconds * particle.distortionSpin;
|
| 606 | int distortionArgb = funnelColor(baseColor, 0xFFFFFF, alpha * FUNNEL_DISTORTION_ALPHA_MULTIPLIER);
|
| 607 | addBillboardQuad(
|
| 608 | distortionMesh,
|
| 609 | pos.x, pos.y, pos.z,
|
| 610 | particle.size * FUNNEL_DISTORTION_SIZE_MULTIPLIER * scale,
|
| 611 | camRot,
|
| 612 | distortionRoll,
|
| 613 | distortionArgb
|
| 614 | );
|
| 615 |
|
| 616 | float innerRoll = -particle.visualPhase * 1.18f + ageSeconds * (0.18f - particle.distortionSpin * 0.35f);
|
| 617 | int innerArgb = funnelColor(baseColor, 0xFFFFFF, alpha * FUNNEL_DISTORTION_INNER_ALPHA_MULTIPLIER * (1.0f - rimPulse * 0.25f));
|
| 618 | addBillboardQuad(
|
| 619 | distortionMesh,
|
| 620 | pos.x, pos.y, pos.z,
|
| 621 | particle.size * FUNNEL_DISTORTION_INNER_SIZE_MULTIPLIER * scale,
|
| 622 | camRot,
|
| 623 | innerRoll,
|
| 624 | innerArgb
|
| 625 | );
|
| 626 | }
|
| 627 |
|
| 628 | if (eyeMesh != null) {
|
| 629 | float eyeRoll = -particle.visualPhase * 0.42f + ageSeconds * particle.eyeSpin;
|
| 630 | int rimArgb = funnelColor(baseColor, 0xFFC76A, alpha * FUNNEL_RIM_ALPHA_MULTIPLIER * (0.62f + rimPulse * 0.38f));
|
| 631 | addBillboardQuad(
|
| 632 | eyeMesh,
|
| 633 | pos.x, pos.y, pos.z,
|
| 634 | particle.size * (FUNNEL_EYE_SIZE_MULTIPLIER + 0.48f) * scale * (1.0f + rimPulse * 0.045f),
|
| 635 | camRot,
|
| 636 | eyeRoll - 0.18f,
|
| 637 | rimArgb
|
| 638 | );
|
| 639 |
|
| 640 | int ghostA = funnelColor(baseColor, 0x92E8FF, alpha * FUNNEL_GHOST_ALPHA_MULTIPLIER * (0.70f + rimPulse * 0.16f));
|
| 641 | addBillboardQuad(
|
| 642 | eyeMesh,
|
| 643 | pos.x, pos.y, pos.z,
|
| 644 | particle.size * 3.74f * scale,
|
| 645 | camRot,
|
| 646 | eyeRoll + 0.74f,
|
| 647 | ghostA
|
| 648 | );
|
| 649 |
|
| 650 | int ghostB = funnelColor(baseColor, 0xFF9D47, alpha * FUNNEL_GHOST_ALPHA_MULTIPLIER * 0.68f * (1.0f - rimPulse * 0.18f));
|
| 651 | addBillboardQuad(
|
| 652 | eyeMesh,
|
| 653 | pos.x, pos.y, pos.z,
|
| 654 | particle.size * 4.88f * scale,
|
| 655 | camRot,
|
| 656 | eyeRoll - 1.06f,
|
| 657 | ghostB
|
| 658 | );
|
| 659 |
|
| 660 | int eyeArgb = funnelColor(baseColor, 0xFFFFFF, alpha * FUNNEL_EYE_ALPHA_MULTIPLIER);
|
| 661 | addBillboardQuad(
|
| 662 | eyeMesh,
|
| 663 | pos.x, pos.y, pos.z,
|
| 664 | particle.size * FUNNEL_EYE_SIZE_MULTIPLIER * scale,
|
| 665 | camRot,
|
| 666 | eyeRoll,
|
| 667 | eyeArgb
|
| 668 | );
|
| 669 | }
|
| 670 |
|
| 671 | if (bloomMesh != null) {
|
| 672 | renderFunnelLeaks(bloomMesh, particle, pos, camRot, alpha, scale, baseColor, ageSeconds);
|
| 673 |
|
| 674 | float lifeT = particle.lifeProgress();
|
| 675 | float flashCenter = 0.34f + ColorEffects.hash01(particle.visualPhase + 5.73f) * 0.38f;
|
| 676 | float flash = 1.0f - AnimationUtility.smoothstep(Mth.clamp(Math.abs(lifeT - flashCenter) / 0.13f, 0.0f, 1.0f));
|
| 677 | if (flash > 0.002f) {
|
| 678 | int flashArgb = funnelColor(baseColor, 0x7FE8FF, alpha * FUNNEL_FLASH_ALPHA_MULTIPLIER * flash);
|
| 679 | addBillboardQuad(
|
| 680 | bloomMesh,
|
| 681 | pos.x, pos.y, pos.z,
|
| 682 | particle.size * (1.45f + flash * 0.82f) * scale,
|
| 683 | camRot,
|
| 684 | particle.visualPhase * 0.21f,
|
| 685 | flashArgb
|
| 686 | );
|
| 687 | }
|
| 688 | }
|
| 689 | }
|
| 690 | }
|
| 691 |
|
| 692 | private void renderAirBubble(MeshBuilder shellMesh,
|
| 693 | Particle particle,
|
| 694 | Vec3 pos,
|
| 695 | float alpha,
|
| 696 | int baseColor,
|
| 697 | long nowMs) {
|
| 698 | if (shellMesh == null) return;
|
| 699 |
|
| 700 | long ageMs = particle.ageMs(nowMs);
|
| 701 | float ageSeconds = ageMs / 1000.0f;
|
| 702 | float pulse = 0.5f + 0.5f * (float) Math.sin(ageSeconds * 3.1f + particle.visualPhase);
|
| 703 | float pop = 1.0f + AnimationUtility.smoothstep(pulse) * 0.065f;
|
| 704 | float sphereRadius = particle.size * BUBBLE_FILL_SIZE_MULTIPLIER * pop;
|
| 705 |
|
| 706 | // Dense shell geometry provides silhouette/depth; the shader adds Fresnel, specular and thin-film motion.
|
| 707 | addSphereShell(shellMesh, pos, sphereRadius, baseColor, alpha, ageSeconds, particle.visualPhase);
|
| 708 | }
|
| 709 |
|
| 710 | private static boolean bubbleInFrustum(Particle particle, Vec3 pos) {
|
| 711 | if (RenderState.frustum == null) return true;
|
| 712 | // A billboard's axis-aligned extent may reach halfSize * sqrt(2). Include the 9% pulse
|
| 713 | // and a small numerical margin so culling cannot clip a visible glow at a frustum edge.
|
| 714 | double extent = particle.size * BUBBLE_CULL_EXTENT_MULTIPLIER;
|
| 715 | return Renderer3D.Culling.isInFrustum(new AABB(
|
| 716 | pos.x - extent, pos.y - extent, pos.z - extent,
|
| 717 | pos.x + extent, pos.y + extent, pos.z + extent
|
| 718 | ));
|
| 719 | }
|
| 720 |
|
| 721 | private MeshBuilder tintedTexturedBatch(Renderer3D renderer,
|
| 722 | boolean useDepth,
|
| 723 | Renderer3D.DepthMode depthMode,
|
| 724 | Identifier texture) {
|
| 725 | return renderer.batch(
|
| 726 | useDepth
|
| 727 | ? CombatantRenderPipelines.WORLD_TEXTURED_TINT_ADDITIVE_LIQUID_IGNORE
|
| 728 | : CombatantRenderPipelines.WORLD_TEXTURED_TINT_ADDITIVE,
|
| 729 | depthMode,
|
| 730 | Renderer3D.BatchBindings.none()
|
| 731 | .withSampler("u_Texture", texture)
|
| 732 | .withUniform("TextureTint", TextureTintUniforms.get())
|
| 733 | );
|
| 734 | }
|
| 735 |
|
| 736 | private Particle createParticle() {
|
| 737 | ThreadLocalRandom random = ThreadLocalRandom.current();
|
| 738 | Vec3 playerPos = mc.player.position();
|
| 739 |
|
| 740 | double range = Math.max(0.1, radius.get());
|
| 741 | double heightRange = Math.max(0.1, height.get());
|
| 742 | double px = playerPos.x + random.nextDouble(-range, range);
|
| 743 | double py = playerPos.y + random.nextDouble(0.0, heightRange);
|
| 744 | double pz = playerPos.z + random.nextDouble(-range, range);
|
| 745 |
|
| 746 | Vec3 pos = new Vec3(px, py, pz);
|
| 747 | boolean bubbleMode = isBubbleMode();
|
| 748 | Vec3 motion = bubbleMode
|
| 749 | ? new Vec3(
|
| 750 | random.nextDouble(-0.42, 0.42) * MOTION_SCALE,
|
| 751 | random.nextDouble(1.10, 2.55) * MOTION_SCALE,
|
| 752 | random.nextDouble(-0.42, 0.42) * MOTION_SCALE
|
| 753 | )
|
| 754 | : new Vec3(
|
| 755 | random.nextDouble(-1.0, 1.0) * MOTION_SCALE,
|
| 756 | random.nextDouble(0.0, 2.0) * MOTION_SCALE,
|
| 757 | random.nextDouble(-1.0, 1.0) * MOTION_SCALE
|
| 758 | );
|
| 759 | Vec3 rotationMotion = new Vec3(
|
| 760 | random.nextDouble(-1.0, 1.0) * MOTION_SCALE,
|
| 761 | random.nextDouble(-1.0, 1.0) * MOTION_SCALE,
|
| 762 | random.nextDouble(-1.0, 1.0) * MOTION_SCALE
|
| 763 | );
|
| 764 |
|
| 765 | int minLife = Math.max(1, Math.min(lifeMinMs.get(), lifeMaxMs.get()));
|
| 766 | int maxLife = Math.max(minLife, Math.max(lifeMinMs.get(), lifeMaxMs.get()));
|
| 767 | long life = randomLongClosed(random, minLife, maxLife);
|
| 768 |
|
| 769 | double minSize = Math.max(0.02, Math.min(sizeMin.get(), sizeMax.get()));
|
| 770 | double maxSize = Math.max(minSize, Math.max(sizeMin.get(), sizeMax.get()));
|
| 771 | float size = (float) randomDoubleClosed(random, minSize, maxSize);
|
| 772 |
|
| 773 | float visualPhase = (float) random.nextDouble(0.0, Math.PI * 2.0);
|
| 774 | float eyeSpin = (float) random.nextDouble(0.38, 0.72);
|
| 775 | float distortionSpin = (float) random.nextDouble(-0.28, -0.12);
|
| 776 |
|
| 777 | return new Particle(pos, motion, rotationMotion, life, size, visualPhase, eyeSpin, distortionSpin);
|
| 778 | }
|
| 779 |
|
| 780 | private void renderFunnelLeaks(MeshBuilder mesh,
|
| 781 | Particle particle,
|
| 782 | Vec3 pos,
|
| 783 | Quaternionf camRot,
|
| 784 | float alpha,
|
| 785 | float scale,
|
| 786 | int baseColor,
|
| 787 | float ageSeconds) {
|
| 788 | for (int i = 0; i < 4; i++) {
|
| 789 | float seed = ColorEffects.hash01(particle.visualPhase + i * 13.17f);
|
| 790 | float angle = particle.visualPhase + i * 1.5708f + ageSeconds * (0.28f + seed * 0.16f);
|
| 791 | float distance = particle.size * scale * (1.45f + seed * 1.10f);
|
| 792 | Vec3 leakPos = offsetInBillboardPlane(pos, camRot, angle, distance);
|
| 793 |
|
| 794 | float wave = 0.5f + 0.5f * (float) Math.sin(ageSeconds * (2.0f + seed * 0.9f) + particle.visualPhase + i);
|
| 795 | float leakAlpha = alpha * FUNNEL_LEAK_ALPHA_MULTIPLIER * (0.45f + AnimationUtility.smoothstep(wave) * 0.55f);
|
| 796 | int leakRgb = switch (i & 3) {
|
| 797 | case 0 -> 0xFF3A24;
|
| 798 | case 1 -> 0xA7FF2E;
|
| 799 | case 2 -> 0xFFD84E;
|
| 800 | default -> 0x55F7FF;
|
| 801 | };
|
| 802 |
|
| 803 | addBillboardRect(
|
| 804 | mesh,
|
| 805 | leakPos.x, leakPos.y, leakPos.z,
|
| 806 | particle.size * scale * (0.055f + seed * 0.035f),
|
| 807 | particle.size * scale * (0.42f + seed * 0.34f),
|
| 808 | camRot,
|
| 809 | angle - 1.5708f,
|
| 810 | funnelColor(baseColor, leakRgb, leakAlpha)
|
| 811 | );
|
| 812 | }
|
| 813 | }
|
| 814 |
|
| 815 | private int funnelColor(int baseArgb, int sourceRgb, float alphaMultiplier) {
|
| 816 | return ColorEffects.argbWithBaseAlpha(baseArgb, sourceRgb, alphaMultiplier);
|
| 817 | }
|
| 818 |
|
| 819 | private int colorForParticle(Particle particle, int index) {
|
| 820 | int phase = colorPhase.get()
|
| 821 | + Math.round(index * colorSpread.get() / 90.0f)
|
| 822 | + Math.round(particle.visualPhase * 57.29578f);
|
| 823 | return AnimatedRenderColors.resolve(
|
| 824 | animatedColorMode(),
|
| 825 | colorSpeed.get(),
|
| 826 | phase,
|
| 827 | color.getArgb(),
|
| 828 | color2.getArgb(),
|
| 829 | true
|
| 830 | );
|
| 831 | }
|
| 832 |
|
| 833 | private boolean usesSecondaryColor() {
|
| 834 | return AnimatedRenderColors.usesSecondary(animatedColorMode());
|
| 835 | }
|
| 836 |
|
| 837 | private AnimatedRenderColors.Mode animatedColorMode() {
|
| 838 | return switch (colorMode.get()) {
|
| 839 | case "Rainbow" -> AnimatedRenderColors.Mode.RAINBOW;
|
| 840 | case "LightRainbow" -> AnimatedRenderColors.Mode.LIGHT_RAINBOW;
|
| 841 | case "Sky" -> AnimatedRenderColors.Mode.SKY;
|
| 842 | case "Fade" -> AnimatedRenderColors.Mode.FADE;
|
| 843 | case "DoubleColor" -> AnimatedRenderColors.Mode.DOUBLE_COLOR;
|
| 844 | case "Analogous" -> AnimatedRenderColors.Mode.ANALOGOUS;
|
| 845 | case "Theme" -> AnimatedRenderColors.Mode.THEME;
|
| 846 | default -> AnimatedRenderColors.Mode.STATIC;
|
| 847 | };
|
| 848 | }
|
| 849 |
|
| 850 | private int funnelTintRgb() {
|
| 851 | if (funnelTintSyncTheme.get()) {
|
| 852 | return Theme.theme().accent() & 0x00FFFFFF;
|
| 853 | }
|
| 854 | return funnelTintColor.getArgb() & 0x00FFFFFF;
|
| 855 | }
|
| 856 |
|
| 857 | private boolean isFunnelTintControlsVisible() {
|
| 858 | return isFunnelMode() && funnelTintMode.get() != ColorBlendMode.ORIGINAL;
|
| 859 | }
|
| 860 |
|
| 861 | private boolean isManualFunnelTintVisible() {
|
| 862 | return isFunnelTintControlsVisible() && !funnelTintSyncTheme.get();
|
| 863 | }
|
| 864 |
|
| 865 | private boolean isFunnelMode() {
|
| 866 | return mode.get() == Mode.FUNNEL;
|
| 867 | }
|
| 868 |
|
| 869 | private boolean isBubbleMode() {
|
| 870 | return mode.get() == Mode.AIR_BUBBLES;
|
| 871 | }
|
| 872 |
|
| 873 | private enum Mode implements EnumValue.AliasProvider {
|
| 874 | QUADS,
|
| 875 | AIR_BUBBLES,
|
| 876 | FUNNEL;
|
| 877 |
|
| 878 | @Override
|
| 879 | public List<String> aliases() {
|
| 880 | return switch (this) {
|
| 881 | case AIR_BUBBLES -> List.of("AirBubbles");
|
| 882 | case QUADS -> List.of("Quads");
|
| 883 | case FUNNEL -> List.of("Funnel");
|
| 884 | };
|
| 885 | }
|
| 886 | }
|
| 887 |
|
| 888 | private static final class Particle {
|
| 889 | private final long spawnMs;
|
| 890 | private final long lifeMs;
|
| 891 | private final float size;
|
| 892 | private final float visualPhase;
|
| 893 | private final float eyeSpin;
|
| 894 | private final float distortionSpin;
|
| 895 | private Vec3 prevPos;
|
| 896 | private Vec3 pos;
|
| 897 | private Vec3 prevRotation;
|
| 898 | private Vec3 rotation;
|
| 899 | private Vec3 motion;
|
| 900 | private Vec3 rotationMotion;
|
| 901 |
|
| 902 | private Particle(Vec3 pos, Vec3 motion, Vec3 rotationMotion, long lifeMs, float size,
|
| 903 | float visualPhase, float eyeSpin, float distortionSpin) {
|
| 904 | this.prevPos = pos;
|
| 905 | this.pos = pos;
|
| 906 | this.prevRotation = Vec3.ZERO;
|
| 907 | this.rotation = Vec3.ZERO;
|
| 908 | this.motion = motion;
|
| 909 | this.rotationMotion = rotationMotion;
|
| 910 | this.spawnMs = System.currentTimeMillis();
|
| 911 | this.lifeMs = Math.max(1L, lifeMs);
|
| 912 | this.size = size;
|
| 913 | this.visualPhase = visualPhase;
|
| 914 | this.eyeSpin = eyeSpin;
|
| 915 | this.distortionSpin = distortionSpin;
|
| 916 | }
|
| 917 |
|
| 918 | private void tick() {
|
| 919 | prevPos = pos;
|
| 920 | prevRotation = rotation;
|
| 921 | pos = pos.add(motion);
|
| 922 | rotation = rotation.add(rotationMotion);
|
| 923 | motion = motion.scale(PARTICLE_SIMULATION.linearDrag());
|
| 924 | rotationMotion = rotationMotion.scale(PARTICLE_SIMULATION.angularDrag());
|
| 925 | }
|
| 926 |
|
| 927 | private float alpha() {
|
| 928 | return alpha(System.currentTimeMillis());
|
| 929 | }
|
| 930 |
|
| 931 | private float alpha(long nowMs) {
|
| 932 | long age = nowMs - spawnMs;
|
| 933 | if (age <= 0L) {
|
| 934 | return 0.0f;
|
| 935 | }
|
| 936 | if (age < ALPHA_ANIM_MS) {
|
| 937 | return AnimationUtility.smoothstep(age / (float) ALPHA_ANIM_MS);
|
| 938 | }
|
| 939 | if (age < lifeMs) {
|
| 940 | return 1.0f;
|
| 941 | }
|
| 942 | float fade = 1.0f - (age - lifeMs) / (float) ALPHA_ANIM_MS;
|
| 943 | return AnimationUtility.smoothstep(Mth.clamp(fade, 0.0f, 1.0f));
|
| 944 | }
|
| 945 |
|
| 946 | private float funnelAlpha() {
|
| 947 | long age = ageMs();
|
| 948 | if (age <= 0L) {
|
| 949 | return 0.0f;
|
| 950 | }
|
| 951 |
|
| 952 | float appear = AnimationUtility.easeOutCubic(age / 720.0f);
|
| 953 | float disappear = 1.0f;
|
| 954 | if (age > lifeMs) {
|
| 955 | disappear = 1.0f - AnimationUtility.easeInCubic((age - lifeMs) / (float) ALPHA_ANIM_MS);
|
| 956 | }
|
| 957 |
|
| 958 | float breath = 0.88f + 0.12f * (float) Math.sin(age * 0.0032f + visualPhase);
|
| 959 | return AnimationUtility.clamp01(appear * disappear * breath);
|
| 960 | }
|
| 961 |
|
| 962 | private float funnelScale() {
|
| 963 | long age = ageMs();
|
| 964 | float appear = AnimationUtility.easeOutCubic(age / 900.0f);
|
| 965 | float disappear = 1.0f;
|
| 966 | if (age > lifeMs) {
|
| 967 | disappear = 1.0f - AnimationUtility.smoothstep((age - lifeMs) / (float) ALPHA_ANIM_MS);
|
| 968 | }
|
| 969 |
|
| 970 | float open = AnimationUtility.lerp(0.68f, 1.04f, appear);
|
| 971 | float close = AnimationUtility.lerp(0.82f, 1.0f, disappear);
|
| 972 | return open * close;
|
| 973 | }
|
| 974 |
|
| 975 | private long ageMs() {
|
| 976 | return System.currentTimeMillis() - spawnMs;
|
| 977 | }
|
| 978 |
|
| 979 | private long ageMs(long nowMs) {
|
| 980 | return nowMs - spawnMs;
|
| 981 | }
|
| 982 |
|
| 983 | private float lifeProgress() {
|
| 984 | return AnimationUtility.clamp01(ageMs() / (float) Math.max(1L, lifeMs));
|
| 985 | }
|
| 986 |
|
| 987 | private float lifeProgress(long ageMs) {
|
| 988 | return AnimationUtility.clamp01(ageMs / (float) Math.max(1L, lifeMs));
|
| 989 | }
|
| 990 |
|
| 991 | private boolean isExpired() {
|
| 992 | return System.currentTimeMillis() - spawnMs >= lifeMs + ALPHA_ANIM_MS;
|
| 993 | }
|
| 994 |
|
| 995 | private boolean isExpired(long nowMs) {
|
| 996 | return nowMs - spawnMs >= lifeMs + ALPHA_ANIM_MS;
|
| 997 | }
|
| 998 |
|
| 999 | private Vec3 interpolatePos(float tickDelta) {
|
| 1000 | return prevPos.lerp(pos, tickDelta);
|
| 1001 | }
|
| 1002 |
|
| 1003 | private Vec3 interpolateRotation(float tickDelta) {
|
| 1004 | return prevRotation.lerp(rotation, tickDelta);
|
| 1005 | }
|
| 1006 | }
|
| 1007 | }
|
| 1008 |
|