Подписывайтесь на наш Telegram и не пропускайте важные новости! Перейти

Визуальная часть 3д партиклы как в рокстаре base evaware v3

вопрос можно на 3.1 слить если перенесу?
Я не уверен в твоих силах))

Сливай, мне то что)


Код:
Expand Collapse Copy
package dev.hydra.functions.impl.render;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import dev.hydra.events.impl.player.EventUpdate;
import dev.hydra.events.impl.render.Render3DEvent;
import dev.hydra.functions.api.Category;
import dev.hydra.functions.api.Function;
import dev.hydra.functions.api.FunctionAnnotation;
import dev.hydra.functions.setting.impl.SliderComponent;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@FunctionAnnotation(name = "Particles", description = "3D кубы в мире", category = Category.Render)
public final class Particles extends Function {
 
    private final SliderComponent amt = new SliderComponent("Количество", "Количество кубов при спавне", 30.0f, 10.0f, 100.0f, 5.0f);
    private final SliderComponent sz = new SliderComponent("Размер", "Размер кубов при спавне", 0.15f, 0.05f, 0.5f, 0.01f);
    private final List<Cube> cubes = new ArrayList<>();
 
    private static final Identifier icon = Identifier.of("hydra", "icons/glow.png");

    private Particles() {
        settings(amt, sz);
    }

    @Override
    public void onDisable() {
        cubes.clear();
        super.onDisable();
    }

    @EventHelper
    public void onUpdate(EventUpdate e) {
        if (mc.player == null || mc.world == null) { cubes.clear(); return; }
        Vec3d pp = mc.player.getPos();
    
        Iterator<Cube> it = cubes.iterator();
        while (it.hasNext()) {
            Cube c = it.next();
            if (c.dead() || c.pos.distanceTo(pp) > 30) { it.remove(); continue; }
            BlockPos bp = new BlockPos((int) c.pos.x, (int) c.pos.y, (int) c.pos.z);
            if (!mc.world.getBlockState(bp).isAir()) it.remove();
        }

        int max = (int) amt.getAmount();
        int spawn = max - cubes.size();
        if (spawn > 0) {
            float yaw = mc.player.getYaw();
            double lx = -Math.sin(Math.toRadians(yaw)), lz = Math.cos(Math.toRadians(yaw));
            for (int i = 0; i < spawn; i++) {
                double cx, cz;
                if (Math.random() < 0.7) {
                    double fd = 5 + Math.random() * 15, sd = (Math.random() - 0.5) * 15;
                    cx = pp.x + lx * fd + lz * sd;
                    cz = pp.z + lz * fd - lx * sd;
                } else {
                    cx = pp.x + (Math.random() - 0.5) * 30;
                    cz = pp.z + (Math.random() - 0.5) * 30;
                }
                double cy = pp.y + Math.random() * 17;
                BlockPos bp = new BlockPos((int) cx, (int) cy, (int) cz);
                if (!mc.world.getBlockState(bp).isAir()) continue;
                cubes.add(new Cube(new Vec3d(cx, cy, cz), sz.getCurrent()));
            }
        }
    }

    @EventTarget
    public void onRender(Render3DEvent e) {
        if (mc.player == null || mc.world == null || cubes.isEmpty()) return;
        Camera cam = mc.getEntityRenderDispatcher().camera;
        Vec3d cp = cam.getPos();
        MatrixStack ms = e.getMatrix();

        for (Cube c : cubes) {
            c.tick();
            if (c.dead()) continue;
            Vec3d rel = c.pos.subtract(cp);
            float a = c.alpha();
            ms.push();
            ms.translate(rel.x, rel.y, rel.z);
            ms.multiply(RotationAxis.POSITIVE_X.rotationDegrees(c.rx));
            ms.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(c.ry));
            ms.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(c.rz));
            cube(ms, c.sz, (int)(a * 35), false);
            outline(ms, c.sz, (int)(a * 200));
            RenderSystem.clear(GL11.GL_DEPTH_BUFFER_BIT);
            cube(ms, c.sz * 0.35f, (int)(a * 255), true);
            ms.pop();
            glow(ms, rel, c.sz * 3f, (int)(a * 120), cam);
        }
    }

    private void cube(MatrixStack ms, float sz, int a, boolean solid) {
        if (a <= 0) return;
        float h = sz / 2f;
        RenderSystem.enableBlend();
        RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
        RenderSystem.disableCull();
        RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
        Matrix4f m = ms.peek().getPositionMatrix();
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
        faces(b, m, h, a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.enableCull();
        RenderSystem.disableBlend();
    }

    private void faces(BufferBuilder b, Matrix4f m, float h, int a) {
        float[][] v = {{-h,-h,-h,h,-h,-h,h,h,-h,-h,h,-h},{-h,-h,h,-h,h,h,h,h,h,h,-h,h},{-h,h,-h,h,h,-h,h,h,h,-h,h,h},{-h,-h,-h,-h,-h,h,h,-h,h,h,-h,-h},{-h,-h,-h,-h,h,-h,-h,h,h,-h,-h,h},{h,-h,-h,h,-h,h,h,h,h,h,h,-h}};
        for (float[] f : v) for (int i = 0; i < 12; i += 3) b.vertex(m, f[i], f[i+1], f[i+2]).color(255, 255, 255, a);
    }

    private void outline(MatrixStack ms, float sz, int a) {
        if (a <= 0) return;
        float h = sz / 2f;
        GL11.glEnable(GL11.GL_LINE_SMOOTH);
        RenderSystem.enableBlend();
        RenderSystem.lineWidth(1.5f);
        RenderSystem.setShader(ShaderProgramKeys.RENDERTYPE_LINES);
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES);
        MatrixStack.Entry e = ms.peek();
        float[][] ed = {{-h,-h,-h,h,-h,-h},{h,-h,-h,h,-h,h},{h,-h,h,-h,-h,h},{-h,-h,h,-h,-h,-h},{-h,h,-h,h,h,-h},{h,h,-h,h,h,h},{h,h,h,-h,h,h},{-h,h,h,-h,h,-h},{-h,-h,-h,-h,h,-h},{h,-h,-h,h,h,-h},{h,-h,h,h,h,h},{-h,-h,h,-h,h,h}};
        for (float[] l : ed) edge(b, e, l[0], l[1], l[2], l[3], l[4], l[5], a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.disableBlend();
        GL11.glDisable(GL11.GL_LINE_SMOOTH);
    }

    private void edge(BufferBuilder b, MatrixStack.Entry e, float x1, float y1, float z1, float x2, float y2, float z2, int a) {
        Vector3f n = new Vector3f(x2 - x1, y2 - y1, z2 - z1);
        if (n.lengthSquared() > 0) n.normalize(); else n.set(0, 1, 0);
        b.vertex(e, x1, y1, z1).color(255, 255, 255, a).normal(e, n.x, n.y, n.z);
        b.vertex(e, x2, y2, z2).color(255, 255, 255, a).normal(e, n.x, n.y, n.z);
    }

    // простой глов иконкой
    private void glow(MatrixStack ms, Vec3d p, float sz, int a, Camera cam) {
        if (a <= 0) return;
        ms.push();
        ms.translate(p.x, p.y, p.z);
        ms.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-cam.getYaw()));
        ms.multiply(RotationAxis.POSITIVE_X.rotationDegrees(cam.getPitch()));
        RenderSystem.enableBlend();
        RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE, GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE);
        RenderSystem.depthMask(false);
        RenderSystem.setShaderTexture(0, icon);
        RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX_COLOR);
        Matrix4f m = ms.peek().getPositionMatrix();
        float h = sz / 2f;
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
        float[][] q = {{-h,-h,0,0},{-h,h,0,1},{h,h,1,1},{h,-h,1,0}};
        for (float[] v : q) b.vertex(m, v[0], v[1], 0).texture(v[2], v[3]).color(255, 255, 255, a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.depthMask(true);
        RenderSystem.disableBlend();
        ms.pop();
    }

    private static class Cube {
        Vec3d pos, vel;
        float rx, ry, rz, rsx, rsy, rsz, sz;
        long spawn;

        Cube(Vec3d p, float s) {
            pos = p; sz = s;
            double ang = Math.random() * Math.PI * 2, spd = 0.02 + Math.random() * 0.02;
            vel = new Vec3d(Math.cos(ang) * spd, (Math.random() - 0.5) * 0.02, Math.sin(ang) * spd);
            rx = (float)(Math.random() * 360); ry = (float)(Math.random() * 360); rz = (float)(Math.random() * 360);
            rsx = (float)((Math.random() - 0.5) * 3); rsy = (float)((Math.random() - 0.5) * 3); rsz = (float)((Math.random() - 0.5) * 3);
            spawn = System.currentTimeMillis();
        }

        void tick() {
            vel = vel.multiply(0.98);
            pos = pos.add(vel);
            rx += rsx; ry += rsy; rz += rsz;
        }

        boolean dead() { return System.currentTimeMillis() - spawn > 10000; }

        float alpha() {
            long t = System.currentTimeMillis() - spawn;
            if (t < 100) return t / 100f;
            if (t > 7000) return 1f - ((t - 7000) / 3000f);
            return 1f;
        }
    }
}
 
Я не уверен в твоих силах))

Сливай, мне то что)



Код:
Expand Collapse Copy
package dev.hydra.functions.impl.render;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import dev.hydra.events.impl.player.EventUpdate;
import dev.hydra.events.impl.render.Render3DEvent;
import dev.hydra.functions.api.Category;
import dev.hydra.functions.api.Function;
import dev.hydra.functions.api.FunctionAnnotation;
import dev.hydra.functions.setting.impl.SliderComponent;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@FunctionAnnotation(name = "Particles", description = "3D кубы в мире", category = Category.Render)
public final class Particles extends Function {
 
    private final SliderComponent amt = new SliderComponent("Количество", "Количество кубов при спавне", 30.0f, 10.0f, 100.0f, 5.0f);
    private final SliderComponent sz = new SliderComponent("Размер", "Размер кубов при спавне", 0.15f, 0.05f, 0.5f, 0.01f);
    private final List<Cube> cubes = new ArrayList<>();
 
    private static final Identifier icon = Identifier.of("hydra", "icons/glow.png");

    private Particles() {
        settings(amt, sz);
    }

    @Override
    public void onDisable() {
        cubes.clear();
        super.onDisable();
    }

    @EventHelper
    public void onUpdate(EventUpdate e) {
        if (mc.player == null || mc.world == null) { cubes.clear(); return; }
        Vec3d pp = mc.player.getPos();
   
        Iterator<Cube> it = cubes.iterator();
        while (it.hasNext()) {
            Cube c = it.next();
            if (c.dead() || c.pos.distanceTo(pp) > 30) { it.remove(); continue; }
            BlockPos bp = new BlockPos((int) c.pos.x, (int) c.pos.y, (int) c.pos.z);
            if (!mc.world.getBlockState(bp).isAir()) it.remove();
        }

        int max = (int) amt.getAmount();
        int spawn = max - cubes.size();
        if (spawn > 0) {
            float yaw = mc.player.getYaw();
            double lx = -Math.sin(Math.toRadians(yaw)), lz = Math.cos(Math.toRadians(yaw));
            for (int i = 0; i < spawn; i++) {
                double cx, cz;
                if (Math.random() < 0.7) {
                    double fd = 5 + Math.random() * 15, sd = (Math.random() - 0.5) * 15;
                    cx = pp.x + lx * fd + lz * sd;
                    cz = pp.z + lz * fd - lx * sd;
                } else {
                    cx = pp.x + (Math.random() - 0.5) * 30;
                    cz = pp.z + (Math.random() - 0.5) * 30;
                }
                double cy = pp.y + Math.random() * 17;
                BlockPos bp = new BlockPos((int) cx, (int) cy, (int) cz);
                if (!mc.world.getBlockState(bp).isAir()) continue;
                cubes.add(new Cube(new Vec3d(cx, cy, cz), sz.getCurrent()));
            }
        }
    }

    @EventTarget
    public void onRender(Render3DEvent e) {
        if (mc.player == null || mc.world == null || cubes.isEmpty()) return;
        Camera cam = mc.getEntityRenderDispatcher().camera;
        Vec3d cp = cam.getPos();
        MatrixStack ms = e.getMatrix();

        for (Cube c : cubes) {
            c.tick();
            if (c.dead()) continue;
            Vec3d rel = c.pos.subtract(cp);
            float a = c.alpha();
            ms.push();
            ms.translate(rel.x, rel.y, rel.z);
            ms.multiply(RotationAxis.POSITIVE_X.rotationDegrees(c.rx));
            ms.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(c.ry));
            ms.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(c.rz));
            cube(ms, c.sz, (int)(a * 35), false);
            outline(ms, c.sz, (int)(a * 200));
            RenderSystem.clear(GL11.GL_DEPTH_BUFFER_BIT);
            cube(ms, c.sz * 0.35f, (int)(a * 255), true);
            ms.pop();
            glow(ms, rel, c.sz * 3f, (int)(a * 120), cam);
        }
    }

    private void cube(MatrixStack ms, float sz, int a, boolean solid) {
        if (a <= 0) return;
        float h = sz / 2f;
        RenderSystem.enableBlend();
        RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
        RenderSystem.disableCull();
        RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
        Matrix4f m = ms.peek().getPositionMatrix();
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
        faces(b, m, h, a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.enableCull();
        RenderSystem.disableBlend();
    }

    private void faces(BufferBuilder b, Matrix4f m, float h, int a) {
        float[][] v = {{-h,-h,-h,h,-h,-h,h,h,-h,-h,h,-h},{-h,-h,h,-h,h,h,h,h,h,h,-h,h},{-h,h,-h,h,h,-h,h,h,h,-h,h,h},{-h,-h,-h,-h,-h,h,h,-h,h,h,-h,-h},{-h,-h,-h,-h,h,-h,-h,h,h,-h,-h,h},{h,-h,-h,h,-h,h,h,h,h,h,h,-h}};
        for (float[] f : v) for (int i = 0; i < 12; i += 3) b.vertex(m, f[i], f[i+1], f[i+2]).color(255, 255, 255, a);
    }

    private void outline(MatrixStack ms, float sz, int a) {
        if (a <= 0) return;
        float h = sz / 2f;
        GL11.glEnable(GL11.GL_LINE_SMOOTH);
        RenderSystem.enableBlend();
        RenderSystem.lineWidth(1.5f);
        RenderSystem.setShader(ShaderProgramKeys.RENDERTYPE_LINES);
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES);
        MatrixStack.Entry e = ms.peek();
        float[][] ed = {{-h,-h,-h,h,-h,-h},{h,-h,-h,h,-h,h},{h,-h,h,-h,-h,h},{-h,-h,h,-h,-h,-h},{-h,h,-h,h,h,-h},{h,h,-h,h,h,h},{h,h,h,-h,h,h},{-h,h,h,-h,h,-h},{-h,-h,-h,-h,h,-h},{h,-h,-h,h,h,-h},{h,-h,h,h,h,h},{-h,-h,h,-h,h,h}};
        for (float[] l : ed) edge(b, e, l[0], l[1], l[2], l[3], l[4], l[5], a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.disableBlend();
        GL11.glDisable(GL11.GL_LINE_SMOOTH);
    }

    private void edge(BufferBuilder b, MatrixStack.Entry e, float x1, float y1, float z1, float x2, float y2, float z2, int a) {
        Vector3f n = new Vector3f(x2 - x1, y2 - y1, z2 - z1);
        if (n.lengthSquared() > 0) n.normalize(); else n.set(0, 1, 0);
        b.vertex(e, x1, y1, z1).color(255, 255, 255, a).normal(e, n.x, n.y, n.z);
        b.vertex(e, x2, y2, z2).color(255, 255, 255, a).normal(e, n.x, n.y, n.z);
    }

    // простой глов иконкой
    private void glow(MatrixStack ms, Vec3d p, float sz, int a, Camera cam) {
        if (a <= 0) return;
        ms.push();
        ms.translate(p.x, p.y, p.z);
        ms.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-cam.getYaw()));
        ms.multiply(RotationAxis.POSITIVE_X.rotationDegrees(cam.getPitch()));
        RenderSystem.enableBlend();
        RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE, GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE);
        RenderSystem.depthMask(false);
        RenderSystem.setShaderTexture(0, icon);
        RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX_COLOR);
        Matrix4f m = ms.peek().getPositionMatrix();
        float h = sz / 2f;
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
        float[][] q = {{-h,-h,0,0},{-h,h,0,1},{h,h,1,1},{h,-h,1,0}};
        for (float[] v : q) b.vertex(m, v[0], v[1], 0).texture(v[2], v[3]).color(255, 255, 255, a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.depthMask(true);
        RenderSystem.disableBlend();
        ms.pop();
    }

    private static class Cube {
        Vec3d pos, vel;
        float rx, ry, rz, rsx, rsy, rsz, sz;
        long spawn;

        Cube(Vec3d p, float s) {
            pos = p; sz = s;
            double ang = Math.random() * Math.PI * 2, spd = 0.02 + Math.random() * 0.02;
            vel = new Vec3d(Math.cos(ang) * spd, (Math.random() - 0.5) * 0.02, Math.sin(ang) * spd);
            rx = (float)(Math.random() * 360); ry = (float)(Math.random() * 360); rz = (float)(Math.random() * 360);
            rsx = (float)((Math.random() - 0.5) * 3); rsy = (float)((Math.random() - 0.5) * 3); rsz = (float)((Math.random() - 0.5) * 3);
            spawn = System.currentTimeMillis();
        }

        void tick() {
            vel = vel.multiply(0.98);
            pos = pos.add(vel);
            rx += rsx; ry += rsy; rz += rsz;
        }

        boolean dead() { return System.currentTimeMillis() - spawn > 10000; }

        float alpha() {
            long t = System.currentTimeMillis() - spawn;
            if (t < 100) return t / 100f;
            if (t > 7000) return 1f - ((t - 7000) / 3000f);
            return 1f;
        }
    }
}
ia tvoi ruki celoval
 
вот что то более менее
кодик:
Expand Collapse Copy
package solude.dev.client.features.modules.render.particles;

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
import org.joml.Matrix4f;
import solude.dev.api.event.EventListener;
import solude.dev.api.event.Listener;
import solude.dev.api.event.events.player.other.UpdateEvent;
import solude.dev.api.event.events.render.Render3DEvent;
import solude.dev.api.module.setting.BooleanSetting;
import solude.dev.api.module.setting.SliderSetting;
import solude.dev.api.system.interfaces.QuickImports;
import solude.dev.api.utils.animation.AnimationUtil;
import solude.dev.api.utils.animation.Easing;
import solude.dev.api.utils.color.ColorUtil;
import solude.dev.api.utils.color.UIColors;
import solude.dev.api.utils.math.MathUtil;
import solude.dev.api.utils.math.TimerUtil;
import solude.dev.api.utils.render.RenderUtil;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class CubeParticles extends ParticlesModule.BaseSettings implements QuickImports {
    private final SliderSetting distance = new SliderSetting(prefix + "Distance").value(20f).range(5f, 50f).step(1f);
    private final SliderSetting riseSpeed = new SliderSetting(prefix + "Rise Speed").value(0.03f).range(0.01f, 0.1f).step(0.01f);
    private final SliderSetting rotateSpeed = new SliderSetting(prefix + "Rotate Speed").value(2f).range(0.5f, 5f).step(0.5f);
    private final BooleanSetting glow = new BooleanSetting(prefix + "Glow").value(true);
    private final SliderSetting glowSize = new SliderSetting(prefix + "Glow Size").value(2f).range(1f, 4f).step(0.5f);

    private final List<CubeParticle> particles = new ArrayList<>();
    private final TimerUtil spawnTimer = new TimerUtil();

    public CubeParticles() {
        super("Cubes");
        addSettings(distance, riseSpeed, rotateSpeed, glow, glowSize);
    }

    public void toggle() {
        particles.clear();
        spawnTimer.reset();
    }

    @Override
    public void onEvent() {
        EventListener updateEvent = UpdateEvent.getInstance().subscribe(new Listener<>(event -> {
            particles.removeIf(CubeParticle::update);

            int diff = count().getValue().intValue() - particles.size();
            if (diff > 0) {
                float d = distance.getValue();
                int toSpawn = Math.min(diff, 5);
              
                for (int i = 0; i < toSpawn; i++) {
                    double spawnX = mc.player.getX() + MathUtil.randomInRange(-d, d);
                    double spawnZ = mc.player.getZ() + MathUtil.randomInRange(-d, d);
                    double spawnY = findGroundY(spawnX, spawnZ);
                  
                    particles.add(new CubeParticle(
                            (float) spawnX,
                            (float) spawnY,
                            (float) spawnZ,
                            MathUtil.randomInRange(-0.005f, 0.005f),
                            riseSpeed.getValue(),
                            MathUtil.randomInRange(-0.005f, 0.005f),
                            particles.size(),
                            size().getValue(),
                            lifeTime().getValue().intValue(),
                            spawnDuration().getValue(), dyingDuration().getValue(),
                            rotateSpeed.getValue()
                    ));
                }
            }
        }));

        EventListener renderEvent = Render3DEvent.getInstance().subscribe(new Listener<>(event -> {
            MatrixStack matrixStack = event.matrixStack();

            for (CubeParticle particle : particles) {
                particle.updateAlpha();
                RenderUtil.WORLD.startRender(matrixStack);
                particle.render(matrixStack, glow.getValue(), glowSize.getValue());
                RenderUtil.WORLD.endRender(matrixStack);
            }
        }));

        addEvents(renderEvent, updateEvent);
    }
  
    private double findGroundY(double x, double z) {
        if (mc.world == null || mc.player == null) return mc.player.getY() - 1;
      
        int playerY = (int) mc.player.getY();
      
        for (int y = playerY + 2; y > playerY - 15; y--) {
            BlockPos pos = new BlockPos((int) Math.floor(x), y, (int) Math.floor(z));
            BlockPos above = pos.up();
          
            boolean blockSolid = !mc.world.getBlockState(pos).isAir();
            boolean aboveAir = mc.world.getBlockState(above).isAir();
          
            if (blockSolid && aboveAir) {
                return y + 1.0;
            }
        }
      
        return mc.player.getY();
    }

    private static class CubeParticle implements QuickImports {
        private float prevX, prevY, prevZ;
        private float x, y, z;
        private float motionX, motionY, motionZ;
        private int maxLife;
        private float size, prevSize = 0f;
        private int index;
      
        private float rotX, rotY, rotZ;
        private float prevRotX, prevRotY, prevRotZ;
        private float rotSpeedX, rotSpeedY, rotSpeedZ;
      
        private float spawnDuration, dyingDuration;
        private final TimerUtil timerUtil = new TimerUtil();
        private final AnimationUtil alphaAnimation = new AnimationUtil();

        public CubeParticle(float x, float y, float z,
                           float motionX, float motionY, float motionZ,
                           int index, float size, int lifetime,
                           float spawnDuration, float dyingDuration, float rotateSpeed) {
            this.prevX = x;
            this.prevY = y;
            this.prevZ = z;
            this.x = x;
            this.y = y;
            this.z = z;
            this.motionX = motionX;
            this.motionY = motionY;
            this.motionZ = motionZ;
            this.index = index;
            this.size = size;
            this.maxLife = MathUtil.randomInRange(Math.max(lifetime / 2, 0), lifetime);
            this.spawnDuration = spawnDuration;
            this.dyingDuration = dyingDuration;
          
            this.rotX = MathUtil.randomInRange(-180f, 180f);
            this.rotY = MathUtil.randomInRange(-180f, 180f);
            this.rotZ = MathUtil.randomInRange(-180f, 180f);
            this.prevRotX = rotX;
            this.prevRotY = rotY;
            this.prevRotZ = rotZ;
          
            this.rotSpeedX = MathUtil.randomInRange(-rotateSpeed, rotateSpeed);
            this.rotSpeedY = MathUtil.randomInRange(-rotateSpeed, rotateSpeed);
            this.rotSpeedZ = MathUtil.randomInRange(-rotateSpeed, rotateSpeed);
        }

        public boolean update() {
            prevX = x;
            prevY = y;
            prevZ = z;
            prevRotX = rotX;
            prevRotY = rotY;
            prevRotZ = rotZ;

            x += motionX;
            y += motionY;
            z += motionZ;

            rotX += rotSpeedX;
            rotY += rotSpeedY;
            rotZ += rotSpeedZ;

            return mc.player.getPos().distanceTo(new Vec3d(x, y, z)) >= 80 ||
                    alphaAnimation.getValue() <= 0.0 && timerUtil.finished((spawnDuration + dyingDuration + maxLife) * 50);
        }

        public void updateAlpha() {
            alphaAnimation.update();
            float alphaAnim = (float) alphaAnimation.getValue();

            if (alphaAnim <= 0.0 && !timerUtil.finished(spawnDuration * 50))
                alphaAnimation.run(1.0, (long) (spawnDuration * 50), Easing.QUINT_OUT);

            if (alphaAnim >= 1.0 && timerUtil.finished((spawnDuration + maxLife) * 50))
                alphaAnimation.run(0.0, (long) (dyingDuration * 50), Easing.QUINT_OUT);
        }

        public void render(MatrixStack matrixStack, boolean glow, float glowSize) {
            Vec3d cam = mc.getEntityRenderDispatcher().camera.getPos();
            float alpha = (float) alphaAnimation.getValue();
          
            double interpX = MathUtil.interpolate(prevX, x) - cam.x;
            double interpY = MathUtil.interpolate(prevY, y) - cam.y;
            double interpZ = MathUtil.interpolate(prevZ, z) - cam.z;
          
            float interpRotX = MathUtil.interpolate(prevRotX, rotX);
            float interpRotY = MathUtil.interpolate(prevRotY, rotY);
            float interpRotZ = MathUtil.interpolate(prevRotZ, rotZ);

            float halfSize = MathUtil.interpolate(prevSize, size * alpha);
            prevSize = halfSize;

            Color color = ColorUtil.setAlpha(UIColors.gradient(index * 90), (int) (255 * alpha));

            matrixStack.push();
            matrixStack.translate(interpX, interpY, interpZ);
            matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(interpRotX));
            matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(interpRotY));
            matrixStack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(interpRotZ));

            if (glow) {
                renderGlow(matrixStack, halfSize * glowSize, color, alpha);
            }
          
            renderCube(matrixStack, halfSize, color);

            matrixStack.pop();
        }
      
        private void renderGlow(MatrixStack matrixStack, float size, Color color, float alpha) {
            Camera camera = mc.gameRenderer.getCamera();
          
            matrixStack.push();
            matrixStack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(-MathUtil.interpolate(prevRotZ, rotZ)));
            matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-MathUtil.interpolate(prevRotY, rotY)));
            matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-MathUtil.interpolate(prevRotX, rotX)));
            matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-camera.getYaw()));
            matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch()));
          
            Matrix4f glowMatrix = matrixStack.peek().getPositionMatrix();
          
            RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
            RenderSystem.enableBlend();
            RenderSystem.defaultBlendFunc();
            RenderSystem.disableCull();
          
            BufferBuilder buf = Tessellator.getInstance().begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
            int r = color.getRed(), g = color.getGreen(), b = color.getBlue();
            int centerAlpha = (int) (80 * alpha);
            int edgeAlpha = 0;
          
            buf.vertex(glowMatrix, 0, 0, 0).color(r, g, b, centerAlpha);
          
            int segments = 16;
            for (int i = 0; i <= segments; i++) {
                float angle = (float) (i * 2 * Math.PI / segments);
                float px = (float) Math.cos(angle) * size;
                float py = (float) Math.sin(angle) * size;
                buf.vertex(glowMatrix, px, py, 0).color(r, g, b, edgeAlpha);
            }
          
            BufferRenderer.drawWithGlobalProgram(buf.end());
            RenderSystem.enableCull();
            matrixStack.pop();
        }

        private void renderCube(MatrixStack matrixStack, float size, Color color) {
            Matrix4f matrix = matrixStack.peek().getPositionMatrix();
            float s = size;
          
            RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
            RenderSystem.enableBlend();
            RenderSystem.defaultBlendFunc();
            RenderSystem.disableCull();
            RenderSystem.lineWidth(2f);

            BufferBuilder buf = Tessellator.getInstance().begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR);
            int r = color.getRed(), g = color.getGreen(), b = color.getBlue(), a = color.getAlpha();

            buf.vertex(matrix, -s, -s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, -s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, -s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, -s, s).color(r, g, b, a);
            buf.vertex(matrix, s, -s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, -s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, -s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, -s, -s).color(r, g, b, a);

            buf.vertex(matrix, -s, s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, s, s).color(r, g, b, a);
            buf.vertex(matrix, s, s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, s, -s).color(r, g, b, a);

            buf.vertex(matrix, -s, -s, -s).color(r, g, b, a);
            buf.vertex(matrix, -s, s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, -s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, -s, s).color(r, g, b, a);
            buf.vertex(matrix, s, s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, -s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, s, s).color(r, g, b, a);

            buf.vertex(matrix, -s, -s, -s).color(r, g, b, a / 2);
            buf.vertex(matrix, s, s, s).color(r, g, b, a / 2);
            buf.vertex(matrix, s, -s, -s).color(r, g, b, a / 2);
            buf.vertex(matrix, -s, s, s).color(r, g, b, a / 2);
            buf.vertex(matrix, -s, -s, s).color(r, g, b, a / 2);
            buf.vertex(matrix, s, s, -s).color(r, g, b, a / 2);
            buf.vertex(matrix, s, -s, s).color(r, g, b, a / 2);
            buf.vertex(matrix, -s, s, -s).color(r, g, b, a / 2);

            BufferRenderer.drawWithGlobalProgram(buf.end());
            RenderSystem.enableCull();
        }
    }
}
ss:Посмотреть вложение 324890
а вот как в рокстаре(no ad) Посмотреть вложение 324891
+rep годно
 
Дай мне тоже, посмотрю как работает
package dev.hydra.functions.impl.render;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import dev.hydra.events.impl.player.EventUpdate;
import dev.hydra.events.impl.render.Render3DEvent;
import dev.hydra.functions.api.Category;
import dev.hydra.functions.api.Function;
import dev.hydra.functions.api.FunctionAnnotation;
import dev.hydra.functions.setting.impl.SliderComponent;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@FunctionAnnotation(name = "Particles", description = "3D кубы в мире", category = Category.Render)
public final class Particles extends Function {

private final SliderComponent amt = new SliderComponent("Количество", "Количество кубов при спавне", 30.0f, 10.0f, 100.0f, 5.0f);
private final SliderComponent sz = new SliderComponent("Размер", "Размер кубов при спавне", 0.15f, 0.05f, 0.5f, 0.01f);
private final List<Cube> cubes = new ArrayList<>();

private static final Identifier icon = Identifier.of("hydra", "icons/glow.png");

private Particles() {
settings(amt, sz);
}

@override
public void onDisable() {
cubes.clear();
super.onDisable();
}

@EventHelper
public void onUpdate(EventUpdate e) {
if (mc.player == null || mc.world == null) { cubes.clear(); return; }
Vec3d pp = mc.player.getPos();

Iterator<Cube> it = cubes.iterator();
while (it.hasNext()) {
Cube c = it.next();
if (c.dead() || c.pos.distanceTo(pp) > 30) { it.remove(); continue; }
BlockPos bp = new BlockPos((int) c.pos.x, (int) c.pos.y, (int) c.pos.z);
if (!mc.world.getBlockState(bp).isAir()) it.remove();
}

int max = (int) amt.getAmount();
int spawn = max - cubes.size();
if (spawn > 0) {
float yaw = mc.player.getYaw();
double lx = -Math.sin(Math.toRadians(yaw)), lz = Math.cos(Math.toRadians(yaw));
for (int i = 0; i < spawn; i++) {
double cx, cz;
if (Math.random() < 0.7) {
double fd = 5 + Math.random() * 15, sd = (Math.random() - 0.5) * 15;
cx = pp.x + lx * fd + lz * sd;
cz = pp.z + lz * fd - lx * sd;
} else {
cx = pp.x + (Math.random() - 0.5) * 30;
cz = pp.z + (Math.random() - 0.5) * 30;
}
double cy = pp.y + Math.random() * 17;
BlockPos bp = new BlockPos((int) cx, (int) cy, (int) cz);
if (!mc.world.getBlockState(bp).isAir()) continue;
cubes.add(new Cube(new Vec3d(cx, cy, cz), sz.getCurrent()));
}
}
}

@EventTarget
public void onRender(Render3DEvent e) {
if (mc.player == null || mc.world == null || cubes.isEmpty()) return;
Camera cam = mc.getEntityRenderDispatcher().camera;
Vec3d cp = cam.getPos();
MatrixStack ms = e.getMatrix();

for (Cube c : cubes) {
c.tick();
if (c.dead()) continue;
Vec3d rel = c.pos.subtract(cp);
float a = c.alpha();
ms.push();
ms.translate(rel.x, rel.y, rel.z);
ms.multiply(RotationAxis.POSITIVE_X.rotationDegrees(c.rx));
ms.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(c.ry));
ms.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(c.rz));
cube(ms, c.sz, (int)(a * 35), false);
outline(ms, c.sz, (int)(a * 200));
RenderSystem.clear(GL11.GL_DEPTH_BUFFER_BIT);
cube(ms, c.sz * 0.35f, (int)(a * 255), true);
ms.pop();
glow(ms, rel, c.sz * 3f, (int)(a * 120), cam);
}
}

private void cube(MatrixStack ms, float sz, int a, boolean solid) {
if (a <= 0) return;
float h = sz / 2f;
RenderSystem.enableBlend();
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.disableCull();
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
Matrix4f m = ms.peek().getPositionMatrix();
BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
faces(b, m, h, a);
BufferRenderer.drawWithGlobalProgram(b.end());
RenderSystem.enableCull();
RenderSystem.disableBlend();
}

private void faces(BufferBuilder b, Matrix4f m, float h, int a) {
float[][] v = {{-h,-h,-h,h,-h,-h,h,h,-h,-h,h,-h},{-h,-h,h,-h,h,h,h,h,h,h,-h,h},{-h,h,-h,h,h,-h,h,h,h,-h,h,h},{-h,-h,-h,-h,-h,h,h,-h,h,h,-h,-h},{-h,-h,-h,-h,h,-h,-h,h,h,-h,-h,h},{h,-h,-h,h,-h,h,h,h,h,h,h,-h}};
for (float[] f : v) for (int i = 0; i < 12; i += 3) b.vertex(m, f, f[i+1], f[i+2]).color(255, 255, 255, a);
}

private void outline(MatrixStack ms, float sz, int a) {
if (a <= 0) return;
float h = sz / 2f;
GL11.glEnable(GL11.GL_LINE_SMOOTH);
RenderSystem.enableBlend();
RenderSystem.lineWidth(1.5f);
RenderSystem.setShader(ShaderProgramKeys.RENDERTYPE_LINES);
BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES);
MatrixStack.Entry e = ms.peek();
float[][] ed = {{-h,-h,-h,h,-h,-h},{h,-h,-h,h,-h,h},{h,-h,h,-h,-h,h},{-h,-h,h,-h,-h,-h},{-h,h,-h,h,h,-h},{h,h,-h,h,h,h},{h,h,h,-h,h,h},{-h,h,h,-h,h,-h},{-h,-h,-h,-h,h,-h},{h,-h,-h,h,h,-h},{h,-h,h,h,h,h},{-h,-h,h,-h,h,h}};
for (float[] l : ed) edge(b, e, l[0], l[1], l[2], l[3], l[4], l[5], a);
BufferRenderer.drawWithGlobalProgram(b.end());
RenderSystem.disableBlend();
GL11.glDisable(GL11.GL_LINE_SMOOTH);
}

private void edge(BufferBuilder b, MatrixStack.Entry e, float x1, float y1, float z1, float x2, float y2, float z2, int a) {
Vector3f n = new Vector3f(x2 - x1, y2 - y1, z2 - z1);
if (n.lengthSquared() > 0) n.normalize(); else n.set(0, 1, 0);
b.vertex(e, x1, y1, z1).color(255, 255, 255, a).normal(e, n.x, n.y, n.z);
b.vertex(e, x2, y2, z2).color(255, 255, 255, a).normal(e, n.x, n.y, n.z);
}

// простой глов иконкой
private void glow(MatrixStack ms, Vec3d p, float sz, int a, Camera cam) {
if (a <= 0) return;
ms.push();
ms.translate(p.x, p.y, p.z);
ms.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-cam.getYaw()));
ms.multiply(RotationAxis.POSITIVE_X.rotationDegrees(cam.getPitch()));
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE, GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE);
RenderSystem.depthMask(false);
RenderSystem.setShaderTexture(0, icon);
RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX_COLOR);
Matrix4f m = ms.peek().getPositionMatrix();
float h = sz / 2f;
BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
float[][] q = {{-h,-h,0,0},{-h,h,0,1},{h,h,1,1},{h,-h,1,0}};
for (float[] v : q) b.vertex(m, v[0], v[1], 0).texture(v[2], v[3]).color(255, 255, 255, a);
BufferRenderer.drawWithGlobalProgram(b.end());
RenderSystem.depthMask(true);
RenderSystem.disableBlend();
ms.pop();
}

private static class Cube {
Vec3d pos, vel;
float rx, ry, rz, rsx, rsy, rsz, sz;
long spawn;

Cube(Vec3d p, float s) {
pos = p; sz = s;
double ang = Math.random() * Math.PI * 2, spd = 0.02 + Math.random() * 0.02;
vel = new Vec3d(Math.cos(ang) * spd, (Math.random() - 0.5) * 0.02, Math.sin(ang) * spd);
rx = (float)(Math.random() * 360); ry = (float)(Math.random() * 360); rz = (float)(Math.random() * 360);
rsx = (float)((Math.random() - 0.5) * 3); rsy = (float)((Math.random() - 0.5) * 3); rsz = (float)((Math.random() - 0.5) * 3);
spawn = System.currentTimeMillis();
}

void tick() {
vel = vel.multiply(0.98);
pos = pos.add(vel);
rx += rsx; ry += rsy; rz += rsz;
}

boolean dead() { return System.currentTimeMillis() - spawn > 10000; }

float alpha() {
long t = System.currentTimeMillis() - spawn;
if (t < 100) return t / 100f;
if (t > 7000) return 1f - ((t - 7000) / 3000f);
return 1f;
}
}
}
 
вот что то более менее
кодик:
Expand Collapse Copy
package solude.dev.client.features.modules.render.particles;

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
import org.joml.Matrix4f;
import solude.dev.api.event.EventListener;
import solude.dev.api.event.Listener;
import solude.dev.api.event.events.player.other.UpdateEvent;
import solude.dev.api.event.events.render.Render3DEvent;
import solude.dev.api.module.setting.BooleanSetting;
import solude.dev.api.module.setting.SliderSetting;
import solude.dev.api.system.interfaces.QuickImports;
import solude.dev.api.utils.animation.AnimationUtil;
import solude.dev.api.utils.animation.Easing;
import solude.dev.api.utils.color.ColorUtil;
import solude.dev.api.utils.color.UIColors;
import solude.dev.api.utils.math.MathUtil;
import solude.dev.api.utils.math.TimerUtil;
import solude.dev.api.utils.render.RenderUtil;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class CubeParticles extends ParticlesModule.BaseSettings implements QuickImports {
    private final SliderSetting distance = new SliderSetting(prefix + "Distance").value(20f).range(5f, 50f).step(1f);
    private final SliderSetting riseSpeed = new SliderSetting(prefix + "Rise Speed").value(0.03f).range(0.01f, 0.1f).step(0.01f);
    private final SliderSetting rotateSpeed = new SliderSetting(prefix + "Rotate Speed").value(2f).range(0.5f, 5f).step(0.5f);
    private final BooleanSetting glow = new BooleanSetting(prefix + "Glow").value(true);
    private final SliderSetting glowSize = new SliderSetting(prefix + "Glow Size").value(2f).range(1f, 4f).step(0.5f);

    private final List<CubeParticle> particles = new ArrayList<>();
    private final TimerUtil spawnTimer = new TimerUtil();

    public CubeParticles() {
        super("Cubes");
        addSettings(distance, riseSpeed, rotateSpeed, glow, glowSize);
    }

    public void toggle() {
        particles.clear();
        spawnTimer.reset();
    }

    @Override
    public void onEvent() {
        EventListener updateEvent = UpdateEvent.getInstance().subscribe(new Listener<>(event -> {
            particles.removeIf(CubeParticle::update);

            int diff = count().getValue().intValue() - particles.size();
            if (diff > 0) {
                float d = distance.getValue();
                int toSpawn = Math.min(diff, 5);
              
                for (int i = 0; i < toSpawn; i++) {
                    double spawnX = mc.player.getX() + MathUtil.randomInRange(-d, d);
                    double spawnZ = mc.player.getZ() + MathUtil.randomInRange(-d, d);
                    double spawnY = findGroundY(spawnX, spawnZ);
                  
                    particles.add(new CubeParticle(
                            (float) spawnX,
                            (float) spawnY,
                            (float) spawnZ,
                            MathUtil.randomInRange(-0.005f, 0.005f),
                            riseSpeed.getValue(),
                            MathUtil.randomInRange(-0.005f, 0.005f),
                            particles.size(),
                            size().getValue(),
                            lifeTime().getValue().intValue(),
                            spawnDuration().getValue(), dyingDuration().getValue(),
                            rotateSpeed.getValue()
                    ));
                }
            }
        }));

        EventListener renderEvent = Render3DEvent.getInstance().subscribe(new Listener<>(event -> {
            MatrixStack matrixStack = event.matrixStack();

            for (CubeParticle particle : particles) {
                particle.updateAlpha();
                RenderUtil.WORLD.startRender(matrixStack);
                particle.render(matrixStack, glow.getValue(), glowSize.getValue());
                RenderUtil.WORLD.endRender(matrixStack);
            }
        }));

        addEvents(renderEvent, updateEvent);
    }
  
    private double findGroundY(double x, double z) {
        if (mc.world == null || mc.player == null) return mc.player.getY() - 1;
      
        int playerY = (int) mc.player.getY();
      
        for (int y = playerY + 2; y > playerY - 15; y--) {
            BlockPos pos = new BlockPos((int) Math.floor(x), y, (int) Math.floor(z));
            BlockPos above = pos.up();
          
            boolean blockSolid = !mc.world.getBlockState(pos).isAir();
            boolean aboveAir = mc.world.getBlockState(above).isAir();
          
            if (blockSolid && aboveAir) {
                return y + 1.0;
            }
        }
      
        return mc.player.getY();
    }

    private static class CubeParticle implements QuickImports {
        private float prevX, prevY, prevZ;
        private float x, y, z;
        private float motionX, motionY, motionZ;
        private int maxLife;
        private float size, prevSize = 0f;
        private int index;
      
        private float rotX, rotY, rotZ;
        private float prevRotX, prevRotY, prevRotZ;
        private float rotSpeedX, rotSpeedY, rotSpeedZ;
      
        private float spawnDuration, dyingDuration;
        private final TimerUtil timerUtil = new TimerUtil();
        private final AnimationUtil alphaAnimation = new AnimationUtil();

        public CubeParticle(float x, float y, float z,
                           float motionX, float motionY, float motionZ,
                           int index, float size, int lifetime,
                           float spawnDuration, float dyingDuration, float rotateSpeed) {
            this.prevX = x;
            this.prevY = y;
            this.prevZ = z;
            this.x = x;
            this.y = y;
            this.z = z;
            this.motionX = motionX;
            this.motionY = motionY;
            this.motionZ = motionZ;
            this.index = index;
            this.size = size;
            this.maxLife = MathUtil.randomInRange(Math.max(lifetime / 2, 0), lifetime);
            this.spawnDuration = spawnDuration;
            this.dyingDuration = dyingDuration;
          
            this.rotX = MathUtil.randomInRange(-180f, 180f);
            this.rotY = MathUtil.randomInRange(-180f, 180f);
            this.rotZ = MathUtil.randomInRange(-180f, 180f);
            this.prevRotX = rotX;
            this.prevRotY = rotY;
            this.prevRotZ = rotZ;
          
            this.rotSpeedX = MathUtil.randomInRange(-rotateSpeed, rotateSpeed);
            this.rotSpeedY = MathUtil.randomInRange(-rotateSpeed, rotateSpeed);
            this.rotSpeedZ = MathUtil.randomInRange(-rotateSpeed, rotateSpeed);
        }

        public boolean update() {
            prevX = x;
            prevY = y;
            prevZ = z;
            prevRotX = rotX;
            prevRotY = rotY;
            prevRotZ = rotZ;

            x += motionX;
            y += motionY;
            z += motionZ;

            rotX += rotSpeedX;
            rotY += rotSpeedY;
            rotZ += rotSpeedZ;

            return mc.player.getPos().distanceTo(new Vec3d(x, y, z)) >= 80 ||
                    alphaAnimation.getValue() <= 0.0 && timerUtil.finished((spawnDuration + dyingDuration + maxLife) * 50);
        }

        public void updateAlpha() {
            alphaAnimation.update();
            float alphaAnim = (float) alphaAnimation.getValue();

            if (alphaAnim <= 0.0 && !timerUtil.finished(spawnDuration * 50))
                alphaAnimation.run(1.0, (long) (spawnDuration * 50), Easing.QUINT_OUT);

            if (alphaAnim >= 1.0 && timerUtil.finished((spawnDuration + maxLife) * 50))
                alphaAnimation.run(0.0, (long) (dyingDuration * 50), Easing.QUINT_OUT);
        }

        public void render(MatrixStack matrixStack, boolean glow, float glowSize) {
            Vec3d cam = mc.getEntityRenderDispatcher().camera.getPos();
            float alpha = (float) alphaAnimation.getValue();
          
            double interpX = MathUtil.interpolate(prevX, x) - cam.x;
            double interpY = MathUtil.interpolate(prevY, y) - cam.y;
            double interpZ = MathUtil.interpolate(prevZ, z) - cam.z;
          
            float interpRotX = MathUtil.interpolate(prevRotX, rotX);
            float interpRotY = MathUtil.interpolate(prevRotY, rotY);
            float interpRotZ = MathUtil.interpolate(prevRotZ, rotZ);

            float halfSize = MathUtil.interpolate(prevSize, size * alpha);
            prevSize = halfSize;

            Color color = ColorUtil.setAlpha(UIColors.gradient(index * 90), (int) (255 * alpha));

            matrixStack.push();
            matrixStack.translate(interpX, interpY, interpZ);
            matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(interpRotX));
            matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(interpRotY));
            matrixStack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(interpRotZ));

            if (glow) {
                renderGlow(matrixStack, halfSize * glowSize, color, alpha);
            }
          
            renderCube(matrixStack, halfSize, color);

            matrixStack.pop();
        }
      
        private void renderGlow(MatrixStack matrixStack, float size, Color color, float alpha) {
            Camera camera = mc.gameRenderer.getCamera();
          
            matrixStack.push();
            matrixStack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(-MathUtil.interpolate(prevRotZ, rotZ)));
            matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-MathUtil.interpolate(prevRotY, rotY)));
            matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-MathUtil.interpolate(prevRotX, rotX)));
            matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-camera.getYaw()));
            matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch()));
          
            Matrix4f glowMatrix = matrixStack.peek().getPositionMatrix();
          
            RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
            RenderSystem.enableBlend();
            RenderSystem.defaultBlendFunc();
            RenderSystem.disableCull();
          
            BufferBuilder buf = Tessellator.getInstance().begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
            int r = color.getRed(), g = color.getGreen(), b = color.getBlue();
            int centerAlpha = (int) (80 * alpha);
            int edgeAlpha = 0;
          
            buf.vertex(glowMatrix, 0, 0, 0).color(r, g, b, centerAlpha);
          
            int segments = 16;
            for (int i = 0; i <= segments; i++) {
                float angle = (float) (i * 2 * Math.PI / segments);
                float px = (float) Math.cos(angle) * size;
                float py = (float) Math.sin(angle) * size;
                buf.vertex(glowMatrix, px, py, 0).color(r, g, b, edgeAlpha);
            }
          
            BufferRenderer.drawWithGlobalProgram(buf.end());
            RenderSystem.enableCull();
            matrixStack.pop();
        }

        private void renderCube(MatrixStack matrixStack, float size, Color color) {
            Matrix4f matrix = matrixStack.peek().getPositionMatrix();
            float s = size;
          
            RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
            RenderSystem.enableBlend();
            RenderSystem.defaultBlendFunc();
            RenderSystem.disableCull();
            RenderSystem.lineWidth(2f);

            BufferBuilder buf = Tessellator.getInstance().begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR);
            int r = color.getRed(), g = color.getGreen(), b = color.getBlue(), a = color.getAlpha();

            buf.vertex(matrix, -s, -s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, -s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, -s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, -s, s).color(r, g, b, a);
            buf.vertex(matrix, s, -s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, -s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, -s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, -s, -s).color(r, g, b, a);

            buf.vertex(matrix, -s, s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, s, s).color(r, g, b, a);
            buf.vertex(matrix, s, s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, s, -s).color(r, g, b, a);

            buf.vertex(matrix, -s, -s, -s).color(r, g, b, a);
            buf.vertex(matrix, -s, s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, -s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, s, -s).color(r, g, b, a);
            buf.vertex(matrix, s, -s, s).color(r, g, b, a);
            buf.vertex(matrix, s, s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, -s, s).color(r, g, b, a);
            buf.vertex(matrix, -s, s, s).color(r, g, b, a);

            buf.vertex(matrix, -s, -s, -s).color(r, g, b, a / 2);
            buf.vertex(matrix, s, s, s).color(r, g, b, a / 2);
            buf.vertex(matrix, s, -s, -s).color(r, g, b, a / 2);
            buf.vertex(matrix, -s, s, s).color(r, g, b, a / 2);
            buf.vertex(matrix, -s, -s, s).color(r, g, b, a / 2);
            buf.vertex(matrix, s, s, -s).color(r, g, b, a / 2);
            buf.vertex(matrix, s, -s, s).color(r, g, b, a / 2);
            buf.vertex(matrix, -s, s, -s).color(r, g, b, a / 2);

            BufferRenderer.drawWithGlobalProgram(buf.end());
            RenderSystem.enableCull();
        }
    }
}
ss:Посмотреть вложение 324890
а вот как в рокстаре(no ad) Посмотреть вложение 324891
да че вы хейтите его норм выглядит похоже
 
Скрытое содержимое дай тоже
Дай мне тоже, посмотрю как работает
Код:
Expand Collapse Copy
package dev.hydra.functions.impl.render;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import dev.hydra.events.impl.player.EventUpdate;
import dev.hydra.events.impl.render.Render3DEvent;
import dev.hydra.functions.api.Category;
import dev.hydra.functions.api.Function;
import dev.hydra.functions.api.FunctionAnnotation;
import dev.hydra.functions.setting.impl.SliderComponent;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@FunctionAnnotation(name = "Particles", description = "3D кубы в мире", category = Category.Render)
public final class Particles extends Function {
 
    private final SliderComponent amt = new SliderComponent("Количество", "Количество кубов при спавне", 30.0f, 10.0f, 100.0f, 5.0f);
    private final SliderComponent sz = new SliderComponent("Размер", "Размер кубов при спавне", 0.15f, 0.05f, 0.5f, 0.01f);
    private final List<Cube> cubes = new ArrayList<>();
 
    private static final Identifier icon = Identifier.of("hydra", "icons/glow.png");

    private Particles() {
        settings(amt, sz);
    }

    @Override
    public void onDisable() {
        cubes.clear();
        super.onDisable();
    }

    @EventHelper
    public void onUpdate(EventUpdate e) {
        if (mc.player == null || mc.world == null) { cubes.clear(); return; }
        Vec3d pp = mc.player.getPos();
    
        Iterator<Cube> it = cubes.iterator();
        while (it.hasNext()) {
            Cube c = it.next();
            if (c.dead() || c.pos.distanceTo(pp) > 30) { it.remove(); continue; }
            BlockPos bp = new BlockPos((int) c.pos.x, (int) c.pos.y, (int) c.pos.z);
            if (!mc.world.getBlockState(bp).isAir()) it.remove();
        }

        int max = (int) amt.getAmount();
        int spawn = max - cubes.size();
        if (spawn > 0) {
            float yaw = mc.player.getYaw();
            double lx = -Math.sin(Math.toRadians(yaw)), lz = Math.cos(Math.toRadians(yaw));
            for (int i = 0; i < spawn; i++) {
                double cx, cz;
                if (Math.random() < 0.7) {
                    double fd = 5 + Math.random() * 15, sd = (Math.random() - 0.5) * 15;
                    cx = pp.x + lx * fd + lz * sd;
                    cz = pp.z + lz * fd - lx * sd;
                } else {
                    cx = pp.x + (Math.random() - 0.5) * 30;
                    cz = pp.z + (Math.random() - 0.5) * 30;
                }
                double cy = pp.y + Math.random() * 17;
                BlockPos bp = new BlockPos((int) cx, (int) cy, (int) cz);
                if (!mc.world.getBlockState(bp).isAir()) continue;
                cubes.add(new Cube(new Vec3d(cx, cy, cz), sz.getCurrent()));
            }
        }
    }

    @EventTarget
    public void onRender(Render3DEvent e) {
        if (mc.player == null || mc.world == null || cubes.isEmpty()) return;
        Camera cam = mc.getEntityRenderDispatcher().camera;
        Vec3d cp = cam.getPos();
        MatrixStack ms = e.getMatrix();

        for (Cube c : cubes) {
            c.tick();
            if (c.dead()) continue;
            Vec3d rel = c.pos.subtract(cp);
            float a = c.alpha();
            ms.push();
            ms.translate(rel.x, rel.y, rel.z);
            ms.multiply(RotationAxis.POSITIVE_X.rotationDegrees(c.rx));
            ms.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(c.ry));
            ms.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(c.rz));
            cube(ms, c.sz, (int)(a * 35), false);
            outline(ms, c.sz, (int)(a * 200));
            RenderSystem.clear(GL11.GL_DEPTH_BUFFER_BIT);
            cube(ms, c.sz * 0.35f, (int)(a * 255), true);
            ms.pop();
            glow(ms, rel, c.sz * 3f, (int)(a * 120), cam);
        }
    }

    private void cube(MatrixStack ms, float sz, int a, boolean solid) {
        if (a <= 0) return;
        float h = sz / 2f;
        RenderSystem.enableBlend();
        RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
        RenderSystem.disableCull();
        RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
        Matrix4f m = ms.peek().getPositionMatrix();
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
        faces(b, m, h, a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.enableCull();
        RenderSystem.disableBlend();
    }

    private void faces(BufferBuilder b, Matrix4f m, float h, int a) {
        float[][] v = {{-h,-h,-h,h,-h,-h,h,h,-h,-h,h,-h},{-h,-h,h,-h,h,h,h,h,h,h,-h,h},{-h,h,-h,h,h,-h,h,h,h,-h,h,h},{-h,-h,-h,-h,-h,h,h,-h,h,h,-h,-h},{-h,-h,-h,-h,h,-h,-h,h,h,-h,-h,h},{h,-h,-h,h,-h,h,h,h,h,h,h,-h}};
        for (float[] f : v) for (int i = 0; i < 12; i += 3) b.vertex(m, f[i], f[i+1], f[i+2]).color(255, 255, 255, a);
    }

    private void outline(MatrixStack ms, float sz, int a) {
        if (a <= 0) return;
        float h = sz / 2f;
        GL11.glEnable(GL11.GL_LINE_SMOOTH);
        RenderSystem.enableBlend();
        RenderSystem.lineWidth(1.5f);
        RenderSystem.setShader(ShaderProgramKeys.RENDERTYPE_LINES);
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES);
        MatrixStack.Entry e = ms.peek();
        float[][] ed = {{-h,-h,-h,h,-h,-h},{h,-h,-h,h,-h,h},{h,-h,h,-h,-h,h},{-h,-h,h,-h,-h,-h},{-h,h,-h,h,h,-h},{h,h,-h,h,h,h},{h,h,h,-h,h,h},{-h,h,h,-h,h,-h},{-h,-h,-h,-h,h,-h},{h,-h,-h,h,h,-h},{h,-h,h,h,h,h},{-h,-h,h,-h,h,h}};
        for (float[] l : ed) edge(b, e, l[0], l[1], l[2], l[3], l[4], l[5], a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.disableBlend();
        GL11.glDisable(GL11.GL_LINE_SMOOTH);
    }

    private void edge(BufferBuilder b, MatrixStack.Entry e, float x1, float y1, float z1, float x2, float y2, float z2, int a) {
        Vector3f n = new Vector3f(x2 - x1, y2 - y1, z2 - z1);
        if (n.lengthSquared() > 0) n.normalize(); else n.set(0, 1, 0);
        b.vertex(e, x1, y1, z1).color(255, 255, 255, a).normal(e, n.x, n.y, n.z);
        b.vertex(e, x2, y2, z2).color(255, 255, 255, a).normal(e, n.x, n.y, n.z);
    }

    // простой глов иконкой
    private void glow(MatrixStack ms, Vec3d p, float sz, int a, Camera cam) {
        if (a <= 0) return;
        ms.push();
        ms.translate(p.x, p.y, p.z);
        ms.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-cam.getYaw()));
        ms.multiply(RotationAxis.POSITIVE_X.rotationDegrees(cam.getPitch()));
        RenderSystem.enableBlend();
        RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE, GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE);
        RenderSystem.depthMask(false);
        RenderSystem.setShaderTexture(0, icon);
        RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX_COLOR);
        Matrix4f m = ms.peek().getPositionMatrix();
        float h = sz / 2f;
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
        float[][] q = {{-h,-h,0,0},{-h,h,0,1},{h,h,1,1},{h,-h,1,0}};
        for (float[] v : q) b.vertex(m, v[0], v[1], 0).texture(v[2], v[3]).color(255, 255, 255, a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.depthMask(true);
        RenderSystem.disableBlend();
        ms.pop();
    }

    private static class Cube {
        Vec3d pos, vel;
        float rx, ry, rz, rsx, rsy, rsz, sz;
        long spawn;

        Cube(Vec3d p, float s) {
            pos = p; sz = s;
            double ang = Math.random() * Math.PI * 2, spd = 0.02 + Math.random() * 0.02;
            vel = new Vec3d(Math.cos(ang) * spd, (Math.random() - 0.5) * 0.02, Math.sin(ang) * spd);
            rx = (float)(Math.random() * 360); ry = (float)(Math.random() * 360); rz = (float)(Math.random() * 360);
            rsx = (float)((Math.random() - 0.5) * 3); rsy = (float)((Math.random() - 0.5) * 3); rsz = (float)((Math.random() - 0.5) * 3);
            spawn = System.currentTimeMillis();
        }

        void tick() {
            vel = vel.multiply(0.98);
            pos = pos.add(vel);
            rx += rsx; ry += rsy; rz += rsz;
        }

        boolean dead() { return System.currentTimeMillis() - spawn > 10000; }

        float alpha() {
            long t = System.currentTimeMillis() - spawn;
            if (t < 100) return t / 100f;
            if (t > 7000) return 1f - ((t - 7000) / 3000f);
            return 1f;
        }
    }
}
 
Код:
Expand Collapse Copy
package dev.hydra.functions.impl.render;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import dev.hydra.events.impl.player.EventUpdate;
import dev.hydra.events.impl.render.Render3DEvent;
import dev.hydra.functions.api.Category;
import dev.hydra.functions.api.Function;
import dev.hydra.functions.api.FunctionAnnotation;
import dev.hydra.functions.setting.impl.SliderComponent;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@FunctionAnnotation(name = "Particles", description = "3D кубы в мире", category = Category.Render)
public final class Particles extends Function {
 
    private final SliderComponent amt = new SliderComponent("Количество", "Количество кубов при спавне", 30.0f, 10.0f, 100.0f, 5.0f);
    private final SliderComponent sz = new SliderComponent("Размер", "Размер кубов при спавне", 0.15f, 0.05f, 0.5f, 0.01f);
    private final List<Cube> cubes = new ArrayList<>();
 
    private static final Identifier icon = Identifier.of("hydra", "icons/glow.png");

    private Particles() {
        settings(amt, sz);
    }

    @Override
    public void onDisable() {
        cubes.clear();
        super.onDisable();
    }

    @EventHelper
    public void onUpdate(EventUpdate e) {
        if (mc.player == null || mc.world == null) { cubes.clear(); return; }
        Vec3d pp = mc.player.getPos();
    
        Iterator<Cube> it = cubes.iterator();
        while (it.hasNext()) {
            Cube c = it.next();
            if (c.dead() || c.pos.distanceTo(pp) > 30) { it.remove(); continue; }
            BlockPos bp = new BlockPos((int) c.pos.x, (int) c.pos.y, (int) c.pos.z);
            if (!mc.world.getBlockState(bp).isAir()) it.remove();
        }

        int max = (int) amt.getAmount();
        int spawn = max - cubes.size();
        if (spawn > 0) {
            float yaw = mc.player.getYaw();
            double lx = -Math.sin(Math.toRadians(yaw)), lz = Math.cos(Math.toRadians(yaw));
            for (int i = 0; i < spawn; i++) {
                double cx, cz;
                if (Math.random() < 0.7) {
                    double fd = 5 + Math.random() * 15, sd = (Math.random() - 0.5) * 15;
                    cx = pp.x + lx * fd + lz * sd;
                    cz = pp.z + lz * fd - lx * sd;
                } else {
                    cx = pp.x + (Math.random() - 0.5) * 30;
                    cz = pp.z + (Math.random() - 0.5) * 30;
                }
                double cy = pp.y + Math.random() * 17;
                BlockPos bp = new BlockPos((int) cx, (int) cy, (int) cz);
                if (!mc.world.getBlockState(bp).isAir()) continue;
                cubes.add(new Cube(new Vec3d(cx, cy, cz), sz.getCurrent()));
            }
        }
    }

    @EventTarget
    public void onRender(Render3DEvent e) {
        if (mc.player == null || mc.world == null || cubes.isEmpty()) return;
        Camera cam = mc.getEntityRenderDispatcher().camera;
        Vec3d cp = cam.getPos();
        MatrixStack ms = e.getMatrix();

        for (Cube c : cubes) {
            c.tick();
            if (c.dead()) continue;
            Vec3d rel = c.pos.subtract(cp);
            float a = c.alpha();
            ms.push();
            ms.translate(rel.x, rel.y, rel.z);
            ms.multiply(RotationAxis.POSITIVE_X.rotationDegrees(c.rx));
            ms.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(c.ry));
            ms.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(c.rz));
            cube(ms, c.sz, (int)(a * 35), false);
            outline(ms, c.sz, (int)(a * 200));
            RenderSystem.clear(GL11.GL_DEPTH_BUFFER_BIT);
            cube(ms, c.sz * 0.35f, (int)(a * 255), true);
            ms.pop();
            glow(ms, rel, c.sz * 3f, (int)(a * 120), cam);
        }
    }

    private void cube(MatrixStack ms, float sz, int a, boolean solid) {
        if (a <= 0) return;
        float h = sz / 2f;
        RenderSystem.enableBlend();
        RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
        RenderSystem.disableCull();
        RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
        Matrix4f m = ms.peek().getPositionMatrix();
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
        faces(b, m, h, a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.enableCull();
        RenderSystem.disableBlend();
    }

    private void faces(BufferBuilder b, Matrix4f m, float h, int a) {
        float[][] v = {{-h,-h,-h,h,-h,-h,h,h,-h,-h,h,-h},{-h,-h,h,-h,h,h,h,h,h,h,-h,h},{-h,h,-h,h,h,-h,h,h,h,-h,h,h},{-h,-h,-h,-h,-h,h,h,-h,h,h,-h,-h},{-h,-h,-h,-h,h,-h,-h,h,h,-h,-h,h},{h,-h,-h,h,-h,h,h,h,h,h,h,-h}};
        for (float[] f : v) for (int i = 0; i < 12; i += 3) b.vertex(m, f[i], f[i+1], f[i+2]).color(255, 255, 255, a);
    }

    private void outline(MatrixStack ms, float sz, int a) {
        if (a <= 0) return;
        float h = sz / 2f;
        GL11.glEnable(GL11.GL_LINE_SMOOTH);
        RenderSystem.enableBlend();
        RenderSystem.lineWidth(1.5f);
        RenderSystem.setShader(ShaderProgramKeys.RENDERTYPE_LINES);
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES);
        MatrixStack.Entry e = ms.peek();
        float[][] ed = {{-h,-h,-h,h,-h,-h},{h,-h,-h,h,-h,h},{h,-h,h,-h,-h,h},{-h,-h,h,-h,-h,-h},{-h,h,-h,h,h,-h},{h,h,-h,h,h,h},{h,h,h,-h,h,h},{-h,h,h,-h,h,-h},{-h,-h,-h,-h,h,-h},{h,-h,-h,h,h,-h},{h,-h,h,h,h,h},{-h,-h,h,-h,h,h}};
        for (float[] l : ed) edge(b, e, l[0], l[1], l[2], l[3], l[4], l[5], a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.disableBlend();
        GL11.glDisable(GL11.GL_LINE_SMOOTH);
    }

    private void edge(BufferBuilder b, MatrixStack.Entry e, float x1, float y1, float z1, float x2, float y2, float z2, int a) {
        Vector3f n = new Vector3f(x2 - x1, y2 - y1, z2 - z1);
        if (n.lengthSquared() > 0) n.normalize(); else n.set(0, 1, 0);
        b.vertex(e, x1, y1, z1).color(255, 255, 255, a).normal(e, n.x, n.y, n.z);
        b.vertex(e, x2, y2, z2).color(255, 255, 255, a).normal(e, n.x, n.y, n.z);
    }

    // простой глов иконкой
    private void glow(MatrixStack ms, Vec3d p, float sz, int a, Camera cam) {
        if (a <= 0) return;
        ms.push();
        ms.translate(p.x, p.y, p.z);
        ms.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-cam.getYaw()));
        ms.multiply(RotationAxis.POSITIVE_X.rotationDegrees(cam.getPitch()));
        RenderSystem.enableBlend();
        RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE, GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE);
        RenderSystem.depthMask(false);
        RenderSystem.setShaderTexture(0, icon);
        RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX_COLOR);
        Matrix4f m = ms.peek().getPositionMatrix();
        float h = sz / 2f;
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
        float[][] q = {{-h,-h,0,0},{-h,h,0,1},{h,h,1,1},{h,-h,1,0}};
        for (float[] v : q) b.vertex(m, v[0], v[1], 0).texture(v[2], v[3]).color(255, 255, 255, a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.depthMask(true);
        RenderSystem.disableBlend();
        ms.pop();
    }

    private static class Cube {
        Vec3d pos, vel;
        float rx, ry, rz, rsx, rsy, rsz, sz;
        long spawn;

        Cube(Vec3d p, float s) {
            pos = p; sz = s;
            double ang = Math.random() * Math.PI * 2, spd = 0.02 + Math.random() * 0.02;
            vel = new Vec3d(Math.cos(ang) * spd, (Math.random() - 0.5) * 0.02, Math.sin(ang) * spd);
            rx = (float)(Math.random() * 360); ry = (float)(Math.random() * 360); rz = (float)(Math.random() * 360);
            rsx = (float)((Math.random() - 0.5) * 3); rsy = (float)((Math.random() - 0.5) * 3); rsz = (float)((Math.random() - 0.5) * 3);
            spawn = System.currentTimeMillis();
        }

        void tick() {
            vel = vel.multiply(0.98);
            pos = pos.add(vel);
            rx += rsx; ry += rsy; rz += rsz;
        }

        boolean dead() { return System.currentTimeMillis() - spawn > 10000; }

        float alpha() {
            long t = System.currentTimeMillis() - spawn;
            if (t < 100) return t / 100f;
            if (t > 7000) return 1f - ((t - 7000) / 3000f);
            return 1f;
        }
    }
}
 
Код:
Expand Collapse Copy
package dev.hydra.functions.impl.render;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import dev.hydra.events.impl.player.EventUpdate;
import dev.hydra.events.impl.render.Render3DEvent;
import dev.hydra.functions.api.Category;
import dev.hydra.functions.api.Function;
import dev.hydra.functions.api.FunctionAnnotation;
import dev.hydra.functions.setting.impl.SliderComponent;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@FunctionAnnotation(name = "Particles", description = "3D кубы в мире", category = Category.Render)
public final class Particles extends Function {
 
    private final SliderComponent amt = new SliderComponent("Количество", "Количество кубов при спавне", 30.0f, 10.0f, 100.0f, 5.0f);
    private final SliderComponent sz = new SliderComponent("Размер", "Размер кубов при спавне", 0.15f, 0.05f, 0.5f, 0.01f);
    private final List<Cube> cubes = new ArrayList<>();
 
    private static final Identifier icon = Identifier.of("hydra", "icons/glow.png");

    private Particles() {
        settings(amt, sz);
    }

    @Override
    public void onDisable() {
        cubes.clear();
        super.onDisable();
    }

    @EventHelper
    public void onUpdate(EventUpdate e) {
        if (mc.player == null || mc.world == null) { cubes.clear(); return; }
        Vec3d pp = mc.player.getPos();
   
        Iterator<Cube> it = cubes.iterator();
        while (it.hasNext()) {
            Cube c = it.next();
            if (c.dead() || c.pos.distanceTo(pp) > 30) { it.remove(); continue; }
            BlockPos bp = new BlockPos((int) c.pos.x, (int) c.pos.y, (int) c.pos.z);
            if (!mc.world.getBlockState(bp).isAir()) it.remove();
        }

        int max = (int) amt.getAmount();
        int spawn = max - cubes.size();
        if (spawn > 0) {
            float yaw = mc.player.getYaw();
            double lx = -Math.sin(Math.toRadians(yaw)), lz = Math.cos(Math.toRadians(yaw));
            for (int i = 0; i < spawn; i++) {
                double cx, cz;
                if (Math.random() < 0.7) {
                    double fd = 5 + Math.random() * 15, sd = (Math.random() - 0.5) * 15;
                    cx = pp.x + lx * fd + lz * sd;
                    cz = pp.z + lz * fd - lx * sd;
                } else {
                    cx = pp.x + (Math.random() - 0.5) * 30;
                    cz = pp.z + (Math.random() - 0.5) * 30;
                }
                double cy = pp.y + Math.random() * 17;
                BlockPos bp = new BlockPos((int) cx, (int) cy, (int) cz);
                if (!mc.world.getBlockState(bp).isAir()) continue;
                cubes.add(new Cube(new Vec3d(cx, cy, cz), sz.getCurrent()));
            }
        }
    }

    @EventTarget
    public void onRender(Render3DEvent e) {
        if (mc.player == null || mc.world == null || cubes.isEmpty()) return;
        Camera cam = mc.getEntityRenderDispatcher().camera;
        Vec3d cp = cam.getPos();
        MatrixStack ms = e.getMatrix();

        for (Cube c : cubes) {
            c.tick();
            if (c.dead()) continue;
            Vec3d rel = c.pos.subtract(cp);
            float a = c.alpha();
            ms.push();
            ms.translate(rel.x, rel.y, rel.z);
            ms.multiply(RotationAxis.POSITIVE_X.rotationDegrees(c.rx));
            ms.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(c.ry));
            ms.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(c.rz));
            cube(ms, c.sz, (int)(a * 35), false);
            outline(ms, c.sz, (int)(a * 200));
            RenderSystem.clear(GL11.GL_DEPTH_BUFFER_BIT);
            cube(ms, c.sz * 0.35f, (int)(a * 255), true);
            ms.pop();
            glow(ms, rel, c.sz * 3f, (int)(a * 120), cam);
        }
    }

    private void cube(MatrixStack ms, float sz, int a, boolean solid) {
        if (a <= 0) return;
        float h = sz / 2f;
        RenderSystem.enableBlend();
        RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
        RenderSystem.disableCull();
        RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
        Matrix4f m = ms.peek().getPositionMatrix();
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
        faces(b, m, h, a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.enableCull();
        RenderSystem.disableBlend();
    }

    private void faces(BufferBuilder b, Matrix4f m, float h, int a) {
        float[][] v = {{-h,-h,-h,h,-h,-h,h,h,-h,-h,h,-h},{-h,-h,h,-h,h,h,h,h,h,h,-h,h},{-h,h,-h,h,h,-h,h,h,h,-h,h,h},{-h,-h,-h,-h,-h,h,h,-h,h,h,-h,-h},{-h,-h,-h,-h,h,-h,-h,h,h,-h,-h,h},{h,-h,-h,h,-h,h,h,h,h,h,h,-h}};
        for (float[] f : v) for (int i = 0; i < 12; i += 3) b.vertex(m, f[i], f[i+1], f[i+2]).color(255, 255, 255, a);
    }

    private void outline(MatrixStack ms, float sz, int a) {
        if (a <= 0) return;
        float h = sz / 2f;
        GL11.glEnable(GL11.GL_LINE_SMOOTH);
        RenderSystem.enableBlend();
        RenderSystem.lineWidth(1.5f);
        RenderSystem.setShader(ShaderProgramKeys.RENDERTYPE_LINES);
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES);
        MatrixStack.Entry e = ms.peek();
        float[][] ed = {{-h,-h,-h,h,-h,-h},{h,-h,-h,h,-h,h},{h,-h,h,-h,-h,h},{-h,-h,h,-h,-h,-h},{-h,h,-h,h,h,-h},{h,h,-h,h,h,h},{h,h,h,-h,h,h},{-h,h,h,-h,h,-h},{-h,-h,-h,-h,h,-h},{h,-h,-h,h,h,-h},{h,-h,h,h,h,h},{-h,-h,h,-h,h,h}};
        for (float[] l : ed) edge(b, e, l[0], l[1], l[2], l[3], l[4], l[5], a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.disableBlend();
        GL11.glDisable(GL11.GL_LINE_SMOOTH);
    }

    private void edge(BufferBuilder b, MatrixStack.Entry e, float x1, float y1, float z1, float x2, float y2, float z2, int a) {
        Vector3f n = new Vector3f(x2 - x1, y2 - y1, z2 - z1);
        if (n.lengthSquared() > 0) n.normalize(); else n.set(0, 1, 0);
        b.vertex(e, x1, y1, z1).color(255, 255, 255, a).normal(e, n.x, n.y, n.z);
        b.vertex(e, x2, y2, z2).color(255, 255, 255, a).normal(e, n.x, n.y, n.z);
    }

    // простой глов иконкой
    private void glow(MatrixStack ms, Vec3d p, float sz, int a, Camera cam) {
        if (a <= 0) return;
        ms.push();
        ms.translate(p.x, p.y, p.z);
        ms.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-cam.getYaw()));
        ms.multiply(RotationAxis.POSITIVE_X.rotationDegrees(cam.getPitch()));
        RenderSystem.enableBlend();
        RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE, GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE);
        RenderSystem.depthMask(false);
        RenderSystem.setShaderTexture(0, icon);
        RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX_COLOR);
        Matrix4f m = ms.peek().getPositionMatrix();
        float h = sz / 2f;
        BufferBuilder b = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
        float[][] q = {{-h,-h,0,0},{-h,h,0,1},{h,h,1,1},{h,-h,1,0}};
        for (float[] v : q) b.vertex(m, v[0], v[1], 0).texture(v[2], v[3]).color(255, 255, 255, a);
        BufferRenderer.drawWithGlobalProgram(b.end());
        RenderSystem.depthMask(true);
        RenderSystem.disableBlend();
        ms.pop();
    }

    private static class Cube {
        Vec3d pos, vel;
        float rx, ry, rz, rsx, rsy, rsz, sz;
        long spawn;

        Cube(Vec3d p, float s) {
            pos = p; sz = s;
            double ang = Math.random() * Math.PI * 2, spd = 0.02 + Math.random() * 0.02;
            vel = new Vec3d(Math.cos(ang) * spd, (Math.random() - 0.5) * 0.02, Math.sin(ang) * spd);
            rx = (float)(Math.random() * 360); ry = (float)(Math.random() * 360); rz = (float)(Math.random() * 360);
            rsx = (float)((Math.random() - 0.5) * 3); rsy = (float)((Math.random() - 0.5) * 3); rsz = (float)((Math.random() - 0.5) * 3);
            spawn = System.currentTimeMillis();
        }

        void tick() {
            vel = vel.multiply(0.98);
            pos = pos.add(vel);
            rx += rsx; ry += rsy; rz += rsz;
        }

        boolean dead() { return System.currentTimeMillis() - spawn > 10000; }

        float alpha() {
            long t = System.currentTimeMillis() - spawn;
            if (t < 100) return t / 100f;
            if (t > 7000) return 1f - ((t - 7000) / 3000f);
            return 1f;
        }
    }
}
Зачем вы кидаете 1 и тот же код по кругу кому надо перейдут на 2 страницу в чем проблема
 
Назад
Сверху Снизу