• Я зарабатываю 100 000 RUB / месяц на этом сайте!

    А знаешь как? Я всего-лишь публикую (создаю темы), а админ мне платит. Трачу деньги на мороженое, робуксы и сервера в Minecraft. А ещё на паль из Китая. 

    Хочешь так же? Пиши и узнавай условия: https://t.me/alex_redact
    Реклама: https://t.me/yougame_official

Визуальная часть LineWorld (exp 3.1 ready)

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
9 Окт 2021
Сообщения
6
Реакции
0
Выберите загрузчик игры
  1. OptiFine
SS:
1758080969532.png

Сам код:
LineWorld:
Expand Collapse Copy
package im.expensive.functions.impl.render;

import com.google.common.eventbus.Subscribe;
import im.expensive.events.WorldEvent;
import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import net.minecraft.util.math.vector.Vector3d;
import org.lwjgl.opengl.GL11;

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

@FunctionRegister(name = "LineWorld", type = Category.Render)
public class LineWorld extends Function {

    private static final int MAX_LINES = 150;
    private static final int TRAIL_LENGTH = 30;
    private static final double SPEED = 0.10;
    private static final double SPAWN_RANGE = 20.0;
    private static final int LIFE_MIN = 160;
    private static final int LIFE_VAR = 120;
    private static final int MAX_SPARKS = 800;

    private final List<Line> lines = new ArrayList<>();
    private final List<Spark> sparks = new ArrayList<>();
    private final Random rnd = new Random();

    private static class Line {
        Vector3d pos;
        Vector3d vel;
        List<Vector3d> trail = new ArrayList<>();
        int colorInt;
        int life, maxLife;
        float baseThickness;
        Line(Vector3d pos, Vector3d vel, int colorInt, int life, float thickness) {
            this.pos = pos;
            this.vel = vel;
            this.colorInt = colorInt;
            this.life = life;
            this.maxLife = life;
            this.baseThickness = thickness;
            this.trail.add(pos);
        }
        boolean isDead() { return life <= 0; }
        float fade() { return (float) life / (float) maxLife; }
        void update(Random rnd) {
            double jitter = 0.035;
            Vector3d n = new Vector3d(
                    (rnd.nextDouble() - 0.5) * jitter,
                    (rnd.nextDouble() - 0.5) * jitter * 0.7,
                    (rnd.nextDouble() - 0.5) * jitter
            );
            vel = add(vel, n);
            vel = normalize(vel);
            vel = mul(vel, SPEED);
            pos = pos.add(vel);
            trail.add(pos);
            if (trail.size() > TRAIL_LENGTH) trail.remove(0);
            life--;
        }
    }

    private static class Spark {
        Vector3d pos;
        Vector3d vel;
        int life, maxLife;
        int colorInt;
        Spark(Vector3d pos, Vector3d vel, int life, int colorInt) {
            this.pos = pos;
            this.vel = vel;
            this.life = life;
            this.maxLife = life;
            this.colorInt = colorInt;
        }
        void update() {
            pos = pos.add(vel);
            vel = mul(vel, 0.96);
            life--;
        }
        boolean isDead() { return life <= 0; }
        float alpha() { return (float) life / (float) maxLife; }
    }

    @Subscribe
    public void onRender(WorldEvent e) {
        if (mc.player == null || mc.world == null) return;

        while (lines.size() < MAX_LINES) {
            double ang = rnd.nextDouble() * Math.PI * 2.0;
            double dist = rnd.nextDouble() * SPAWN_RANGE;
            double dx = Math.cos(ang) * dist;
            double dz = Math.sin(ang) * dist;
            double x = mc.player.getPosX() + dx;
            double y = mc.player.getPosY() + (rnd.nextDouble() - 0.5) * 4.0;
            double z = mc.player.getPosZ() + dz;
            Vector3d vel = new Vector3d(rnd.nextDouble() - 0.5, (rnd.nextDouble() - 0.5) * 0.3, rnd.nextDouble() - 0.5);
            vel = normalize(vel);
            vel = mul(vel, SPEED);
            int color = im.expensive.functions.impl.render.HUD.getColor(0, 1);
            int life = LIFE_MIN + rnd.nextInt(LIFE_VAR);
            float thickness = 1.6f + rnd.nextFloat() * 2.4f;
            lines.add(new Line(new Vector3d(x, y, z), vel, color, life, thickness));
        }

        Iterator<Line> lit = lines.iterator();
        while (lit.hasNext()) {
            Line L = lit.next();
            if (sparks.size() < MAX_SPARKS && rnd.nextDouble() < 0.18) {
                Vector3d svel = add(L.vel, new Vector3d((rnd.nextDouble() - 0.5) * 0.4, (rnd.nextDouble() - 0.5) * 0.4, (rnd.nextDouble() - 0.5) * 0.4));
                svel = normalize(svel);
                svel = mul(svel, 0.35 + rnd.nextDouble() * 0.6);
                int spLife = 12 + rnd.nextInt(18);
                sparks.add(new Spark(L.pos, svel, spLife, L.colorInt));
            }
            L.update(rnd);
            if (L.isDead()) lit.remove();
        }

        Iterator<Spark> sit = sparks.iterator();
        while (sit.hasNext()) {
            Spark s = sit.next();
            s.update();
            if (s.isDead()) sit.remove();
        }

        Vector3d camPos = mc.getRenderManager().info.getProjectedView();

        GL11.glPushMatrix();
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
        GL11.glEnable(GL11.GL_LINE_SMOOTH);

        for (Line L : lines) {
            int n = L.trail.size();
            if (n < 2) continue;
            int baseCol = L.colorInt;
            float baseR = ((baseCol >> 16) & 0xFF) / 255f;
            float baseG = ((baseCol >> 8) & 0xFF) / 255f;
            float baseB = (baseCol & 0xFF) / 255f;
            float fadeMaster = L.fade();

            for (int i = 1; i < n; i++) {
                Vector3d p1 = L.trail.get(i - 1);
                Vector3d p2 = L.trail.get(i);
                float t = (float) i / (float) (n - 1);
                float thickness = L.baseThickness * (1.0f - 0.85f * t) + 0.8f;
                float alpha = (1.0f - t * 0.95f) * fadeMaster;
                float satMult = 1.0f - t * 0.6f;
                float brightMult = 0.6f + (1.0f - t) * 0.4f;
                float r = clamp(baseR * satMult * brightMult, 0f, 1f);
                float g = clamp(baseG * satMult * brightMult, 0f, 1f);
                float b = clamp(baseB * satMult * brightMult, 0f, 1f);
                GL11.glLineWidth(Math.max(1.0f, thickness));
                GL11.glBegin(GL11.GL_LINES);
                GL11.glColor4f(r, g, b, alpha);
                GL11.glVertex3d(p1.x - camPos.x, p1.y - camPos.y, p1.z - camPos.z);
                GL11.glVertex3d(p2.x - camPos.x, p2.y - camPos.y, p2.z - camPos.z);
                GL11.glEnd();
            }
        }

        GL11.glPointSize(2.0f);
        GL11.glEnable(GL11.GL_POINT_SMOOTH);
        GL11.glBegin(GL11.GL_POINTS);
        for (Spark s : sparks) {
            float a = s.alpha();
            int c = s.colorInt;
            float rr = ((c >> 16) & 0xFF) / 255f;
            float gg = ((c >> 8) & 0xFF) / 255f;
            float bb = (c & 0xFF) / 255f;
            GL11.glColor4f(Math.min(1f, rr * 1.5f), Math.min(1f, gg * 1.5f), Math.min(1f, bb * 1.5f), a * 0.9f);
            GL11.glVertex3d(s.pos.x - camPos.x, s.pos.y - camPos.y, s.pos.z - camPos.z);
        }
        GL11.glEnd();
        GL11.glDisable(GL11.GL_POINT_SMOOTH);

        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_LINE_SMOOTH);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glPopMatrix();
    }

    private static Vector3d add(Vector3d a, Vector3d b) {
        return new Vector3d(a.x + b.x, a.y + b.y, a.z + b.z);
    }

    private static Vector3d mul(Vector3d v, double s) {
        return new Vector3d(v.x * s, v.y * s, v.z * s);
    }

    private static Vector3d normalize(Vector3d v) {
        double len = Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
        if (len == 0) return new Vector3d(0, 0, 0);
        return new Vector3d(v.x / len, v.y / len, v.z / len);
    }

    private static float clamp(float v, float a, float b) {
        return v < a ? a : Math.min(v, b);
    }
}
 
Почему решил без теста глубины сделать (С выключенным GL_DEPTH_TEST)? Плохо выглядело когда летало сквозь блоки и мобов?
 
SS:Посмотреть вложение 315931
Сам код:
LineWorld:
Expand Collapse Copy
package im.expensive.functions.impl.render;

import com.google.common.eventbus.Subscribe;
import im.expensive.events.WorldEvent;
import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import net.minecraft.util.math.vector.Vector3d;
import org.lwjgl.opengl.GL11;

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

@FunctionRegister(name = "LineWorld", type = Category.Render)
public class LineWorld extends Function {

    private static final int MAX_LINES = 150;
    private static final int TRAIL_LENGTH = 30;
    private static final double SPEED = 0.10;
    private static final double SPAWN_RANGE = 20.0;
    private static final int LIFE_MIN = 160;
    private static final int LIFE_VAR = 120;
    private static final int MAX_SPARKS = 800;

    private final List<Line> lines = new ArrayList<>();
    private final List<Spark> sparks = new ArrayList<>();
    private final Random rnd = new Random();

    private static class Line {
        Vector3d pos;
        Vector3d vel;
        List<Vector3d> trail = new ArrayList<>();
        int colorInt;
        int life, maxLife;
        float baseThickness;
        Line(Vector3d pos, Vector3d vel, int colorInt, int life, float thickness) {
            this.pos = pos;
            this.vel = vel;
            this.colorInt = colorInt;
            this.life = life;
            this.maxLife = life;
            this.baseThickness = thickness;
            this.trail.add(pos);
        }
        boolean isDead() { return life <= 0; }
        float fade() { return (float) life / (float) maxLife; }
        void update(Random rnd) {
            double jitter = 0.035;
            Vector3d n = new Vector3d(
                    (rnd.nextDouble() - 0.5) * jitter,
                    (rnd.nextDouble() - 0.5) * jitter * 0.7,
                    (rnd.nextDouble() - 0.5) * jitter
            );
            vel = add(vel, n);
            vel = normalize(vel);
            vel = mul(vel, SPEED);
            pos = pos.add(vel);
            trail.add(pos);
            if (trail.size() > TRAIL_LENGTH) trail.remove(0);
            life--;
        }
    }

    private static class Spark {
        Vector3d pos;
        Vector3d vel;
        int life, maxLife;
        int colorInt;
        Spark(Vector3d pos, Vector3d vel, int life, int colorInt) {
            this.pos = pos;
            this.vel = vel;
            this.life = life;
            this.maxLife = life;
            this.colorInt = colorInt;
        }
        void update() {
            pos = pos.add(vel);
            vel = mul(vel, 0.96);
            life--;
        }
        boolean isDead() { return life <= 0; }
        float alpha() { return (float) life / (float) maxLife; }
    }

    @Subscribe
    public void onRender(WorldEvent e) {
        if (mc.player == null || mc.world == null) return;

        while (lines.size() < MAX_LINES) {
            double ang = rnd.nextDouble() * Math.PI * 2.0;
            double dist = rnd.nextDouble() * SPAWN_RANGE;
            double dx = Math.cos(ang) * dist;
            double dz = Math.sin(ang) * dist;
            double x = mc.player.getPosX() + dx;
            double y = mc.player.getPosY() + (rnd.nextDouble() - 0.5) * 4.0;
            double z = mc.player.getPosZ() + dz;
            Vector3d vel = new Vector3d(rnd.nextDouble() - 0.5, (rnd.nextDouble() - 0.5) * 0.3, rnd.nextDouble() - 0.5);
            vel = normalize(vel);
            vel = mul(vel, SPEED);
            int color = im.expensive.functions.impl.render.HUD.getColor(0, 1);
            int life = LIFE_MIN + rnd.nextInt(LIFE_VAR);
            float thickness = 1.6f + rnd.nextFloat() * 2.4f;
            lines.add(new Line(new Vector3d(x, y, z), vel, color, life, thickness));
        }

        Iterator<Line> lit = lines.iterator();
        while (lit.hasNext()) {
            Line L = lit.next();
            if (sparks.size() < MAX_SPARKS && rnd.nextDouble() < 0.18) {
                Vector3d svel = add(L.vel, new Vector3d((rnd.nextDouble() - 0.5) * 0.4, (rnd.nextDouble() - 0.5) * 0.4, (rnd.nextDouble() - 0.5) * 0.4));
                svel = normalize(svel);
                svel = mul(svel, 0.35 + rnd.nextDouble() * 0.6);
                int spLife = 12 + rnd.nextInt(18);
                sparks.add(new Spark(L.pos, svel, spLife, L.colorInt));
            }
            L.update(rnd);
            if (L.isDead()) lit.remove();
        }

        Iterator<Spark> sit = sparks.iterator();
        while (sit.hasNext()) {
            Spark s = sit.next();
            s.update();
            if (s.isDead()) sit.remove();
        }

        Vector3d camPos = mc.getRenderManager().info.getProjectedView();

        GL11.glPushMatrix();
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
        GL11.glEnable(GL11.GL_LINE_SMOOTH);

        for (Line L : lines) {
            int n = L.trail.size();
            if (n < 2) continue;
            int baseCol = L.colorInt;
            float baseR = ((baseCol >> 16) & 0xFF) / 255f;
            float baseG = ((baseCol >> 8) & 0xFF) / 255f;
            float baseB = (baseCol & 0xFF) / 255f;
            float fadeMaster = L.fade();

            for (int i = 1; i < n; i++) {
                Vector3d p1 = L.trail.get(i - 1);
                Vector3d p2 = L.trail.get(i);
                float t = (float) i / (float) (n - 1);
                float thickness = L.baseThickness * (1.0f - 0.85f * t) + 0.8f;
                float alpha = (1.0f - t * 0.95f) * fadeMaster;
                float satMult = 1.0f - t * 0.6f;
                float brightMult = 0.6f + (1.0f - t) * 0.4f;
                float r = clamp(baseR * satMult * brightMult, 0f, 1f);
                float g = clamp(baseG * satMult * brightMult, 0f, 1f);
                float b = clamp(baseB * satMult * brightMult, 0f, 1f);
                GL11.glLineWidth(Math.max(1.0f, thickness));
                GL11.glBegin(GL11.GL_LINES);
                GL11.glColor4f(r, g, b, alpha);
                GL11.glVertex3d(p1.x - camPos.x, p1.y - camPos.y, p1.z - camPos.z);
                GL11.glVertex3d(p2.x - camPos.x, p2.y - camPos.y, p2.z - camPos.z);
                GL11.glEnd();
            }
        }

        GL11.glPointSize(2.0f);
        GL11.glEnable(GL11.GL_POINT_SMOOTH);
        GL11.glBegin(GL11.GL_POINTS);
        for (Spark s : sparks) {
            float a = s.alpha();
            int c = s.colorInt;
            float rr = ((c >> 16) & 0xFF) / 255f;
            float gg = ((c >> 8) & 0xFF) / 255f;
            float bb = (c & 0xFF) / 255f;
            GL11.glColor4f(Math.min(1f, rr * 1.5f), Math.min(1f, gg * 1.5f), Math.min(1f, bb * 1.5f), a * 0.9f);
            GL11.glVertex3d(s.pos.x - camPos.x, s.pos.y - camPos.y, s.pos.z - camPos.z);
        }
        GL11.glEnd();
        GL11.glDisable(GL11.GL_POINT_SMOOTH);

        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_LINE_SMOOTH);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glPopMatrix();
    }

    private static Vector3d add(Vector3d a, Vector3d b) {
        return new Vector3d(a.x + b.x, a.y + b.y, a.z + b.z);
    }

    private static Vector3d mul(Vector3d v, double s) {
        return new Vector3d(v.x * s, v.y * s, v.z * s);
    }

    private static Vector3d normalize(Vector3d v) {
        double len = Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
        if (len == 0) return new Vector3d(0, 0, 0);
        return new Vector3d(v.x / len, v.y / len, v.z / len);
    }

    private static float clamp(float v, float a, float b) {
        return v < a ? a : Math.min(v, b);
    }
}
Красота
 
Почему решил без теста глубины сделать (С выключенным GL_DEPTH_TEST)? Плохо выглядело когда летало сквозь блоки и мобов?
Я немного новичок в Java и OpenGL, поэтому не додумался. Да и думаю смысла нету так делать, так проще
 
SS:Посмотреть вложение 315931
Сам код:
LineWorld:
Expand Collapse Copy
package im.expensive.functions.impl.render;

import com.google.common.eventbus.Subscribe;
import im.expensive.events.WorldEvent;
import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import net.minecraft.util.math.vector.Vector3d;
import org.lwjgl.opengl.GL11;

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

@FunctionRegister(name = "LineWorld", type = Category.Render)
public class LineWorld extends Function {

    private static final int MAX_LINES = 150;
    private static final int TRAIL_LENGTH = 30;
    private static final double SPEED = 0.10;
    private static final double SPAWN_RANGE = 20.0;
    private static final int LIFE_MIN = 160;
    private static final int LIFE_VAR = 120;
    private static final int MAX_SPARKS = 800;

    private final List<Line> lines = new ArrayList<>();
    private final List<Spark> sparks = new ArrayList<>();
    private final Random rnd = new Random();

    private static class Line {
        Vector3d pos;
        Vector3d vel;
        List<Vector3d> trail = new ArrayList<>();
        int colorInt;
        int life, maxLife;
        float baseThickness;
        Line(Vector3d pos, Vector3d vel, int colorInt, int life, float thickness) {
            this.pos = pos;
            this.vel = vel;
            this.colorInt = colorInt;
            this.life = life;
            this.maxLife = life;
            this.baseThickness = thickness;
            this.trail.add(pos);
        }
        boolean isDead() { return life <= 0; }
        float fade() { return (float) life / (float) maxLife; }
        void update(Random rnd) {
            double jitter = 0.035;
            Vector3d n = new Vector3d(
                    (rnd.nextDouble() - 0.5) * jitter,
                    (rnd.nextDouble() - 0.5) * jitter * 0.7,
                    (rnd.nextDouble() - 0.5) * jitter
            );
            vel = add(vel, n);
            vel = normalize(vel);
            vel = mul(vel, SPEED);
            pos = pos.add(vel);
            trail.add(pos);
            if (trail.size() > TRAIL_LENGTH) trail.remove(0);
            life--;
        }
    }

    private static class Spark {
        Vector3d pos;
        Vector3d vel;
        int life, maxLife;
        int colorInt;
        Spark(Vector3d pos, Vector3d vel, int life, int colorInt) {
            this.pos = pos;
            this.vel = vel;
            this.life = life;
            this.maxLife = life;
            this.colorInt = colorInt;
        }
        void update() {
            pos = pos.add(vel);
            vel = mul(vel, 0.96);
            life--;
        }
        boolean isDead() { return life <= 0; }
        float alpha() { return (float) life / (float) maxLife; }
    }

    @Subscribe
    public void onRender(WorldEvent e) {
        if (mc.player == null || mc.world == null) return;

        while (lines.size() < MAX_LINES) {
            double ang = rnd.nextDouble() * Math.PI * 2.0;
            double dist = rnd.nextDouble() * SPAWN_RANGE;
            double dx = Math.cos(ang) * dist;
            double dz = Math.sin(ang) * dist;
            double x = mc.player.getPosX() + dx;
            double y = mc.player.getPosY() + (rnd.nextDouble() - 0.5) * 4.0;
            double z = mc.player.getPosZ() + dz;
            Vector3d vel = new Vector3d(rnd.nextDouble() - 0.5, (rnd.nextDouble() - 0.5) * 0.3, rnd.nextDouble() - 0.5);
            vel = normalize(vel);
            vel = mul(vel, SPEED);
            int color = im.expensive.functions.impl.render.HUD.getColor(0, 1);
            int life = LIFE_MIN + rnd.nextInt(LIFE_VAR);
            float thickness = 1.6f + rnd.nextFloat() * 2.4f;
            lines.add(new Line(new Vector3d(x, y, z), vel, color, life, thickness));
        }

        Iterator<Line> lit = lines.iterator();
        while (lit.hasNext()) {
            Line L = lit.next();
            if (sparks.size() < MAX_SPARKS && rnd.nextDouble() < 0.18) {
                Vector3d svel = add(L.vel, new Vector3d((rnd.nextDouble() - 0.5) * 0.4, (rnd.nextDouble() - 0.5) * 0.4, (rnd.nextDouble() - 0.5) * 0.4));
                svel = normalize(svel);
                svel = mul(svel, 0.35 + rnd.nextDouble() * 0.6);
                int spLife = 12 + rnd.nextInt(18);
                sparks.add(new Spark(L.pos, svel, spLife, L.colorInt));
            }
            L.update(rnd);
            if (L.isDead()) lit.remove();
        }

        Iterator<Spark> sit = sparks.iterator();
        while (sit.hasNext()) {
            Spark s = sit.next();
            s.update();
            if (s.isDead()) sit.remove();
        }

        Vector3d camPos = mc.getRenderManager().info.getProjectedView();

        GL11.glPushMatrix();
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
        GL11.glEnable(GL11.GL_LINE_SMOOTH);

        for (Line L : lines) {
            int n = L.trail.size();
            if (n < 2) continue;
            int baseCol = L.colorInt;
            float baseR = ((baseCol >> 16) & 0xFF) / 255f;
            float baseG = ((baseCol >> 8) & 0xFF) / 255f;
            float baseB = (baseCol & 0xFF) / 255f;
            float fadeMaster = L.fade();

            for (int i = 1; i < n; i++) {
                Vector3d p1 = L.trail.get(i - 1);
                Vector3d p2 = L.trail.get(i);
                float t = (float) i / (float) (n - 1);
                float thickness = L.baseThickness * (1.0f - 0.85f * t) + 0.8f;
                float alpha = (1.0f - t * 0.95f) * fadeMaster;
                float satMult = 1.0f - t * 0.6f;
                float brightMult = 0.6f + (1.0f - t) * 0.4f;
                float r = clamp(baseR * satMult * brightMult, 0f, 1f);
                float g = clamp(baseG * satMult * brightMult, 0f, 1f);
                float b = clamp(baseB * satMult * brightMult, 0f, 1f);
                GL11.glLineWidth(Math.max(1.0f, thickness));
                GL11.glBegin(GL11.GL_LINES);
                GL11.glColor4f(r, g, b, alpha);
                GL11.glVertex3d(p1.x - camPos.x, p1.y - camPos.y, p1.z - camPos.z);
                GL11.glVertex3d(p2.x - camPos.x, p2.y - camPos.y, p2.z - camPos.z);
                GL11.glEnd();
            }
        }

        GL11.glPointSize(2.0f);
        GL11.glEnable(GL11.GL_POINT_SMOOTH);
        GL11.glBegin(GL11.GL_POINTS);
        for (Spark s : sparks) {
            float a = s.alpha();
            int c = s.colorInt;
            float rr = ((c >> 16) & 0xFF) / 255f;
            float gg = ((c >> 8) & 0xFF) / 255f;
            float bb = (c & 0xFF) / 255f;
            GL11.glColor4f(Math.min(1f, rr * 1.5f), Math.min(1f, gg * 1.5f), Math.min(1f, bb * 1.5f), a * 0.9f);
            GL11.glVertex3d(s.pos.x - camPos.x, s.pos.y - camPos.y, s.pos.z - camPos.z);
        }
        GL11.glEnd();
        GL11.glDisable(GL11.GL_POINT_SMOOTH);

        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_LINE_SMOOTH);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glPopMatrix();
    }

    private static Vector3d add(Vector3d a, Vector3d b) {
        return new Vector3d(a.x + b.x, a.y + b.y, a.z + b.z);
    }

    private static Vector3d mul(Vector3d v, double s) {
        return new Vector3d(v.x * s, v.y * s, v.z * s);
    }

    private static Vector3d normalize(Vector3d v) {
        double len = Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
        if (len == 0) return new Vector3d(0, 0, 0);
        return new Vector3d(v.x / len, v.y / len, v.z / len);
    }

    private static float clamp(float v, float a, float b) {
        return v < a ? a : Math.min(v, b);
    }
}
доделать, пойдет
 
чо за летающие сперматозоиды
 
SS:Посмотреть вложение 315931
Сам код:
LineWorld:
Expand Collapse Copy
package im.expensive.functions.impl.render;

import com.google.common.eventbus.Subscribe;
import im.expensive.events.WorldEvent;
import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import net.minecraft.util.math.vector.Vector3d;
import org.lwjgl.opengl.GL11;

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

@FunctionRegister(name = "LineWorld", type = Category.Render)
public class LineWorld extends Function {

    private static final int MAX_LINES = 150;
    private static final int TRAIL_LENGTH = 30;
    private static final double SPEED = 0.10;
    private static final double SPAWN_RANGE = 20.0;
    private static final int LIFE_MIN = 160;
    private static final int LIFE_VAR = 120;
    private static final int MAX_SPARKS = 800;

    private final List<Line> lines = new ArrayList<>();
    private final List<Spark> sparks = new ArrayList<>();
    private final Random rnd = new Random();

    private static class Line {
        Vector3d pos;
        Vector3d vel;
        List<Vector3d> trail = new ArrayList<>();
        int colorInt;
        int life, maxLife;
        float baseThickness;
        Line(Vector3d pos, Vector3d vel, int colorInt, int life, float thickness) {
            this.pos = pos;
            this.vel = vel;
            this.colorInt = colorInt;
            this.life = life;
            this.maxLife = life;
            this.baseThickness = thickness;
            this.trail.add(pos);
        }
        boolean isDead() { return life <= 0; }
        float fade() { return (float) life / (float) maxLife; }
        void update(Random rnd) {
            double jitter = 0.035;
            Vector3d n = new Vector3d(
                    (rnd.nextDouble() - 0.5) * jitter,
                    (rnd.nextDouble() - 0.5) * jitter * 0.7,
                    (rnd.nextDouble() - 0.5) * jitter
            );
            vel = add(vel, n);
            vel = normalize(vel);
            vel = mul(vel, SPEED);
            pos = pos.add(vel);
            trail.add(pos);
            if (trail.size() > TRAIL_LENGTH) trail.remove(0);
            life--;
        }
    }

    private static class Spark {
        Vector3d pos;
        Vector3d vel;
        int life, maxLife;
        int colorInt;
        Spark(Vector3d pos, Vector3d vel, int life, int colorInt) {
            this.pos = pos;
            this.vel = vel;
            this.life = life;
            this.maxLife = life;
            this.colorInt = colorInt;
        }
        void update() {
            pos = pos.add(vel);
            vel = mul(vel, 0.96);
            life--;
        }
        boolean isDead() { return life <= 0; }
        float alpha() { return (float) life / (float) maxLife; }
    }

    @Subscribe
    public void onRender(WorldEvent e) {
        if (mc.player == null || mc.world == null) return;

        while (lines.size() < MAX_LINES) {
            double ang = rnd.nextDouble() * Math.PI * 2.0;
            double dist = rnd.nextDouble() * SPAWN_RANGE;
            double dx = Math.cos(ang) * dist;
            double dz = Math.sin(ang) * dist;
            double x = mc.player.getPosX() + dx;
            double y = mc.player.getPosY() + (rnd.nextDouble() - 0.5) * 4.0;
            double z = mc.player.getPosZ() + dz;
            Vector3d vel = new Vector3d(rnd.nextDouble() - 0.5, (rnd.nextDouble() - 0.5) * 0.3, rnd.nextDouble() - 0.5);
            vel = normalize(vel);
            vel = mul(vel, SPEED);
            int color = im.expensive.functions.impl.render.HUD.getColor(0, 1);
            int life = LIFE_MIN + rnd.nextInt(LIFE_VAR);
            float thickness = 1.6f + rnd.nextFloat() * 2.4f;
            lines.add(new Line(new Vector3d(x, y, z), vel, color, life, thickness));
        }

        Iterator<Line> lit = lines.iterator();
        while (lit.hasNext()) {
            Line L = lit.next();
            if (sparks.size() < MAX_SPARKS && rnd.nextDouble() < 0.18) {
                Vector3d svel = add(L.vel, new Vector3d((rnd.nextDouble() - 0.5) * 0.4, (rnd.nextDouble() - 0.5) * 0.4, (rnd.nextDouble() - 0.5) * 0.4));
                svel = normalize(svel);
                svel = mul(svel, 0.35 + rnd.nextDouble() * 0.6);
                int spLife = 12 + rnd.nextInt(18);
                sparks.add(new Spark(L.pos, svel, spLife, L.colorInt));
            }
            L.update(rnd);
            if (L.isDead()) lit.remove();
        }

        Iterator<Spark> sit = sparks.iterator();
        while (sit.hasNext()) {
            Spark s = sit.next();
            s.update();
            if (s.isDead()) sit.remove();
        }

        Vector3d camPos = mc.getRenderManager().info.getProjectedView();

        GL11.glPushMatrix();
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
        GL11.glEnable(GL11.GL_LINE_SMOOTH);

        for (Line L : lines) {
            int n = L.trail.size();
            if (n < 2) continue;
            int baseCol = L.colorInt;
            float baseR = ((baseCol >> 16) & 0xFF) / 255f;
            float baseG = ((baseCol >> 8) & 0xFF) / 255f;
            float baseB = (baseCol & 0xFF) / 255f;
            float fadeMaster = L.fade();

            for (int i = 1; i < n; i++) {
                Vector3d p1 = L.trail.get(i - 1);
                Vector3d p2 = L.trail.get(i);
                float t = (float) i / (float) (n - 1);
                float thickness = L.baseThickness * (1.0f - 0.85f * t) + 0.8f;
                float alpha = (1.0f - t * 0.95f) * fadeMaster;
                float satMult = 1.0f - t * 0.6f;
                float brightMult = 0.6f + (1.0f - t) * 0.4f;
                float r = clamp(baseR * satMult * brightMult, 0f, 1f);
                float g = clamp(baseG * satMult * brightMult, 0f, 1f);
                float b = clamp(baseB * satMult * brightMult, 0f, 1f);
                GL11.glLineWidth(Math.max(1.0f, thickness));
                GL11.glBegin(GL11.GL_LINES);
                GL11.glColor4f(r, g, b, alpha);
                GL11.glVertex3d(p1.x - camPos.x, p1.y - camPos.y, p1.z - camPos.z);
                GL11.glVertex3d(p2.x - camPos.x, p2.y - camPos.y, p2.z - camPos.z);
                GL11.glEnd();
            }
        }

        GL11.glPointSize(2.0f);
        GL11.glEnable(GL11.GL_POINT_SMOOTH);
        GL11.glBegin(GL11.GL_POINTS);
        for (Spark s : sparks) {
            float a = s.alpha();
            int c = s.colorInt;
            float rr = ((c >> 16) & 0xFF) / 255f;
            float gg = ((c >> 8) & 0xFF) / 255f;
            float bb = (c & 0xFF) / 255f;
            GL11.glColor4f(Math.min(1f, rr * 1.5f), Math.min(1f, gg * 1.5f), Math.min(1f, bb * 1.5f), a * 0.9f);
            GL11.glVertex3d(s.pos.x - camPos.x, s.pos.y - camPos.y, s.pos.z - camPos.z);
        }
        GL11.glEnd();
        GL11.glDisable(GL11.GL_POINT_SMOOTH);

        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_LINE_SMOOTH);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glPopMatrix();
    }

    private static Vector3d add(Vector3d a, Vector3d b) {
        return new Vector3d(a.x + b.x, a.y + b.y, a.z + b.z);
    }

    private static Vector3d mul(Vector3d v, double s) {
        return new Vector3d(v.x * s, v.y * s, v.z * s);
    }

    private static Vector3d normalize(Vector3d v) {
        double len = Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
        if (len == 0) return new Vector3d(0, 0, 0);
        return new Vector3d(v.x / len, v.y / len, v.z / len);
    }

    private static float clamp(float v, float a, float b) {
        return v < a ? a : Math.min(v, b);
    }
}
Нормально сделано
 
SS:Посмотреть вложение 315931
Сам код:
LineWorld:
Expand Collapse Copy
package im.expensive.functions.impl.render;

import com.google.common.eventbus.Subscribe;
import im.expensive.events.WorldEvent;
import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import net.minecraft.util.math.vector.Vector3d;
import org.lwjgl.opengl.GL11;

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

@FunctionRegister(name = "LineWorld", type = Category.Render)
public class LineWorld extends Function {

    private static final int MAX_LINES = 150;
    private static final int TRAIL_LENGTH = 30;
    private static final double SPEED = 0.10;
    private static final double SPAWN_RANGE = 20.0;
    private static final int LIFE_MIN = 160;
    private static final int LIFE_VAR = 120;
    private static final int MAX_SPARKS = 800;

    private final List<Line> lines = new ArrayList<>();
    private final List<Spark> sparks = new ArrayList<>();
    private final Random rnd = new Random();

    private static class Line {
        Vector3d pos;
        Vector3d vel;
        List<Vector3d> trail = new ArrayList<>();
        int colorInt;
        int life, maxLife;
        float baseThickness;
        Line(Vector3d pos, Vector3d vel, int colorInt, int life, float thickness) {
            this.pos = pos;
            this.vel = vel;
            this.colorInt = colorInt;
            this.life = life;
            this.maxLife = life;
            this.baseThickness = thickness;
            this.trail.add(pos);
        }
        boolean isDead() { return life <= 0; }
        float fade() { return (float) life / (float) maxLife; }
        void update(Random rnd) {
            double jitter = 0.035;
            Vector3d n = new Vector3d(
                    (rnd.nextDouble() - 0.5) * jitter,
                    (rnd.nextDouble() - 0.5) * jitter * 0.7,
                    (rnd.nextDouble() - 0.5) * jitter
            );
            vel = add(vel, n);
            vel = normalize(vel);
            vel = mul(vel, SPEED);
            pos = pos.add(vel);
            trail.add(pos);
            if (trail.size() > TRAIL_LENGTH) trail.remove(0);
            life--;
        }
    }

    private static class Spark {
        Vector3d pos;
        Vector3d vel;
        int life, maxLife;
        int colorInt;
        Spark(Vector3d pos, Vector3d vel, int life, int colorInt) {
            this.pos = pos;
            this.vel = vel;
            this.life = life;
            this.maxLife = life;
            this.colorInt = colorInt;
        }
        void update() {
            pos = pos.add(vel);
            vel = mul(vel, 0.96);
            life--;
        }
        boolean isDead() { return life <= 0; }
        float alpha() { return (float) life / (float) maxLife; }
    }

    @Subscribe
    public void onRender(WorldEvent e) {
        if (mc.player == null || mc.world == null) return;

        while (lines.size() < MAX_LINES) {
            double ang = rnd.nextDouble() * Math.PI * 2.0;
            double dist = rnd.nextDouble() * SPAWN_RANGE;
            double dx = Math.cos(ang) * dist;
            double dz = Math.sin(ang) * dist;
            double x = mc.player.getPosX() + dx;
            double y = mc.player.getPosY() + (rnd.nextDouble() - 0.5) * 4.0;
            double z = mc.player.getPosZ() + dz;
            Vector3d vel = new Vector3d(rnd.nextDouble() - 0.5, (rnd.nextDouble() - 0.5) * 0.3, rnd.nextDouble() - 0.5);
            vel = normalize(vel);
            vel = mul(vel, SPEED);
            int color = im.expensive.functions.impl.render.HUD.getColor(0, 1);
            int life = LIFE_MIN + rnd.nextInt(LIFE_VAR);
            float thickness = 1.6f + rnd.nextFloat() * 2.4f;
            lines.add(new Line(new Vector3d(x, y, z), vel, color, life, thickness));
        }

        Iterator<Line> lit = lines.iterator();
        while (lit.hasNext()) {
            Line L = lit.next();
            if (sparks.size() < MAX_SPARKS && rnd.nextDouble() < 0.18) {
                Vector3d svel = add(L.vel, new Vector3d((rnd.nextDouble() - 0.5) * 0.4, (rnd.nextDouble() - 0.5) * 0.4, (rnd.nextDouble() - 0.5) * 0.4));
                svel = normalize(svel);
                svel = mul(svel, 0.35 + rnd.nextDouble() * 0.6);
                int spLife = 12 + rnd.nextInt(18);
                sparks.add(new Spark(L.pos, svel, spLife, L.colorInt));
            }
            L.update(rnd);
            if (L.isDead()) lit.remove();
        }

        Iterator<Spark> sit = sparks.iterator();
        while (sit.hasNext()) {
            Spark s = sit.next();
            s.update();
            if (s.isDead()) sit.remove();
        }

        Vector3d camPos = mc.getRenderManager().info.getProjectedView();

        GL11.glPushMatrix();
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
        GL11.glEnable(GL11.GL_LINE_SMOOTH);

        for (Line L : lines) {
            int n = L.trail.size();
            if (n < 2) continue;
            int baseCol = L.colorInt;
            float baseR = ((baseCol >> 16) & 0xFF) / 255f;
            float baseG = ((baseCol >> 8) & 0xFF) / 255f;
            float baseB = (baseCol & 0xFF) / 255f;
            float fadeMaster = L.fade();

            for (int i = 1; i < n; i++) {
                Vector3d p1 = L.trail.get(i - 1);
                Vector3d p2 = L.trail.get(i);
                float t = (float) i / (float) (n - 1);
                float thickness = L.baseThickness * (1.0f - 0.85f * t) + 0.8f;
                float alpha = (1.0f - t * 0.95f) * fadeMaster;
                float satMult = 1.0f - t * 0.6f;
                float brightMult = 0.6f + (1.0f - t) * 0.4f;
                float r = clamp(baseR * satMult * brightMult, 0f, 1f);
                float g = clamp(baseG * satMult * brightMult, 0f, 1f);
                float b = clamp(baseB * satMult * brightMult, 0f, 1f);
                GL11.glLineWidth(Math.max(1.0f, thickness));
                GL11.glBegin(GL11.GL_LINES);
                GL11.glColor4f(r, g, b, alpha);
                GL11.glVertex3d(p1.x - camPos.x, p1.y - camPos.y, p1.z - camPos.z);
                GL11.glVertex3d(p2.x - camPos.x, p2.y - camPos.y, p2.z - camPos.z);
                GL11.glEnd();
            }
        }

        GL11.glPointSize(2.0f);
        GL11.glEnable(GL11.GL_POINT_SMOOTH);
        GL11.glBegin(GL11.GL_POINTS);
        for (Spark s : sparks) {
            float a = s.alpha();
            int c = s.colorInt;
            float rr = ((c >> 16) & 0xFF) / 255f;
            float gg = ((c >> 8) & 0xFF) / 255f;
            float bb = (c & 0xFF) / 255f;
            GL11.glColor4f(Math.min(1f, rr * 1.5f), Math.min(1f, gg * 1.5f), Math.min(1f, bb * 1.5f), a * 0.9f);
            GL11.glVertex3d(s.pos.x - camPos.x, s.pos.y - camPos.y, s.pos.z - camPos.z);
        }
        GL11.glEnd();
        GL11.glDisable(GL11.GL_POINT_SMOOTH);

        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_LINE_SMOOTH);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glPopMatrix();
    }

    private static Vector3d add(Vector3d a, Vector3d b) {
        return new Vector3d(a.x + b.x, a.y + b.y, a.z + b.z);
    }

    private static Vector3d mul(Vector3d v, double s) {
        return new Vector3d(v.x * s, v.y * s, v.z * s);
    }

    private static Vector3d normalize(Vector3d v) {
        double len = Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
        if (len == 0) return new Vector3d(0, 0, 0);
        return new Vector3d(v.x / len, v.y / len, v.z / len);
    }

    private static float clamp(float v, float a, float b) {
        return v < a ? a : Math.min(v, b);
    }
}
глисты
 
SS:Посмотреть вложение 315931
Сам код:
LineWorld:
Expand Collapse Copy
package im.expensive.functions.impl.render;

import com.google.common.eventbus.Subscribe;
import im.expensive.events.WorldEvent;
import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import net.minecraft.util.math.vector.Vector3d;
import org.lwjgl.opengl.GL11;

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

@FunctionRegister(name = "LineWorld", type = Category.Render)
public class LineWorld extends Function {

    private static final int MAX_LINES = 150;
    private static final int TRAIL_LENGTH = 30;
    private static final double SPEED = 0.10;
    private static final double SPAWN_RANGE = 20.0;
    private static final int LIFE_MIN = 160;
    private static final int LIFE_VAR = 120;
    private static final int MAX_SPARKS = 800;

    private final List<Line> lines = new ArrayList<>();
    private final List<Spark> sparks = new ArrayList<>();
    private final Random rnd = new Random();

    private static class Line {
        Vector3d pos;
        Vector3d vel;
        List<Vector3d> trail = new ArrayList<>();
        int colorInt;
        int life, maxLife;
        float baseThickness;
        Line(Vector3d pos, Vector3d vel, int colorInt, int life, float thickness) {
            this.pos = pos;
            this.vel = vel;
            this.colorInt = colorInt;
            this.life = life;
            this.maxLife = life;
            this.baseThickness = thickness;
            this.trail.add(pos);
        }
        boolean isDead() { return life <= 0; }
        float fade() { return (float) life / (float) maxLife; }
        void update(Random rnd) {
            double jitter = 0.035;
            Vector3d n = new Vector3d(
                    (rnd.nextDouble() - 0.5) * jitter,
                    (rnd.nextDouble() - 0.5) * jitter * 0.7,
                    (rnd.nextDouble() - 0.5) * jitter
            );
            vel = add(vel, n);
            vel = normalize(vel);
            vel = mul(vel, SPEED);
            pos = pos.add(vel);
            trail.add(pos);
            if (trail.size() > TRAIL_LENGTH) trail.remove(0);
            life--;
        }
    }

    private static class Spark {
        Vector3d pos;
        Vector3d vel;
        int life, maxLife;
        int colorInt;
        Spark(Vector3d pos, Vector3d vel, int life, int colorInt) {
            this.pos = pos;
            this.vel = vel;
            this.life = life;
            this.maxLife = life;
            this.colorInt = colorInt;
        }
        void update() {
            pos = pos.add(vel);
            vel = mul(vel, 0.96);
            life--;
        }
        boolean isDead() { return life <= 0; }
        float alpha() { return (float) life / (float) maxLife; }
    }

    @Subscribe
    public void onRender(WorldEvent e) {
        if (mc.player == null || mc.world == null) return;

        while (lines.size() < MAX_LINES) {
            double ang = rnd.nextDouble() * Math.PI * 2.0;
            double dist = rnd.nextDouble() * SPAWN_RANGE;
            double dx = Math.cos(ang) * dist;
            double dz = Math.sin(ang) * dist;
            double x = mc.player.getPosX() + dx;
            double y = mc.player.getPosY() + (rnd.nextDouble() - 0.5) * 4.0;
            double z = mc.player.getPosZ() + dz;
            Vector3d vel = new Vector3d(rnd.nextDouble() - 0.5, (rnd.nextDouble() - 0.5) * 0.3, rnd.nextDouble() - 0.5);
            vel = normalize(vel);
            vel = mul(vel, SPEED);
            int color = im.expensive.functions.impl.render.HUD.getColor(0, 1);
            int life = LIFE_MIN + rnd.nextInt(LIFE_VAR);
            float thickness = 1.6f + rnd.nextFloat() * 2.4f;
            lines.add(new Line(new Vector3d(x, y, z), vel, color, life, thickness));
        }

        Iterator<Line> lit = lines.iterator();
        while (lit.hasNext()) {
            Line L = lit.next();
            if (sparks.size() < MAX_SPARKS && rnd.nextDouble() < 0.18) {
                Vector3d svel = add(L.vel, new Vector3d((rnd.nextDouble() - 0.5) * 0.4, (rnd.nextDouble() - 0.5) * 0.4, (rnd.nextDouble() - 0.5) * 0.4));
                svel = normalize(svel);
                svel = mul(svel, 0.35 + rnd.nextDouble() * 0.6);
                int spLife = 12 + rnd.nextInt(18);
                sparks.add(new Spark(L.pos, svel, spLife, L.colorInt));
            }
            L.update(rnd);
            if (L.isDead()) lit.remove();
        }

        Iterator<Spark> sit = sparks.iterator();
        while (sit.hasNext()) {
            Spark s = sit.next();
            s.update();
            if (s.isDead()) sit.remove();
        }

        Vector3d camPos = mc.getRenderManager().info.getProjectedView();

        GL11.glPushMatrix();
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
        GL11.glEnable(GL11.GL_LINE_SMOOTH);

        for (Line L : lines) {
            int n = L.trail.size();
            if (n < 2) continue;
            int baseCol = L.colorInt;
            float baseR = ((baseCol >> 16) & 0xFF) / 255f;
            float baseG = ((baseCol >> 8) & 0xFF) / 255f;
            float baseB = (baseCol & 0xFF) / 255f;
            float fadeMaster = L.fade();

            for (int i = 1; i < n; i++) {
                Vector3d p1 = L.trail.get(i - 1);
                Vector3d p2 = L.trail.get(i);
                float t = (float) i / (float) (n - 1);
                float thickness = L.baseThickness * (1.0f - 0.85f * t) + 0.8f;
                float alpha = (1.0f - t * 0.95f) * fadeMaster;
                float satMult = 1.0f - t * 0.6f;
                float brightMult = 0.6f + (1.0f - t) * 0.4f;
                float r = clamp(baseR * satMult * brightMult, 0f, 1f);
                float g = clamp(baseG * satMult * brightMult, 0f, 1f);
                float b = clamp(baseB * satMult * brightMult, 0f, 1f);
                GL11.glLineWidth(Math.max(1.0f, thickness));
                GL11.glBegin(GL11.GL_LINES);
                GL11.glColor4f(r, g, b, alpha);
                GL11.glVertex3d(p1.x - camPos.x, p1.y - camPos.y, p1.z - camPos.z);
                GL11.glVertex3d(p2.x - camPos.x, p2.y - camPos.y, p2.z - camPos.z);
                GL11.glEnd();
            }
        }

        GL11.glPointSize(2.0f);
        GL11.glEnable(GL11.GL_POINT_SMOOTH);
        GL11.glBegin(GL11.GL_POINTS);
        for (Spark s : sparks) {
            float a = s.alpha();
            int c = s.colorInt;
            float rr = ((c >> 16) & 0xFF) / 255f;
            float gg = ((c >> 8) & 0xFF) / 255f;
            float bb = (c & 0xFF) / 255f;
            GL11.glColor4f(Math.min(1f, rr * 1.5f), Math.min(1f, gg * 1.5f), Math.min(1f, bb * 1.5f), a * 0.9f);
            GL11.glVertex3d(s.pos.x - camPos.x, s.pos.y - camPos.y, s.pos.z - camPos.z);
        }
        GL11.glEnd();
        GL11.glDisable(GL11.GL_POINT_SMOOTH);

        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_LINE_SMOOTH);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glPopMatrix();
    }

    private static Vector3d add(Vector3d a, Vector3d b) {
        return new Vector3d(a.x + b.x, a.y + b.y, a.z + b.z);
    }

    private static Vector3d mul(Vector3d v, double s) {
        return new Vector3d(v.x * s, v.y * s, v.z * s);
    }

    private static Vector3d normalize(Vector3d v) {
        double len = Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
        if (len == 0) return new Vector3d(0, 0, 0);
        return new Vector3d(v.x / len, v.y / len, v.z / len);
    }

    private static float clamp(float v, float a, float b) {
        return v < a ? a : Math.min(v, b);
    }
}
ну бля хз, при пвп ебать глаза будет сильно, а так наверное доделать надо хз. Ну а так сойдёт
 
ну бля хз, при пвп ебать глаза будет сильно, а так наверное доделать надо хз. Ну а так сойдёт
я по коду смотрю, там можно изменить если че типа шире его сделать или меньше количество и радиус, по этому я не думаю то что сильно ебать будет глаза если ты настроишь под себя
 
я по коду смотрю, там можно изменить если че типа шире его сделать или меньше количество и радиус, по этому я не думаю то что сильно ебать будет глаза если ты настроишь под себя
ну да если так можно, то ну нормас сойдёт в целом, не отрицаю идея имба и реализация тоже. Я код просто не чекал.
 
ну да если так можно, то ну нормас сойдёт в целом, не отрицаю идея имба и реализация тоже. Я код просто не чекал.
в целом такое я впервые нашел на югейме (именно на 1.16.5 и с таким ахуенным кодом, не реально пиздатый код, особенно мне понравилось как человек, реализовал вектора 2д и 3д)
 
ну бля хз, при пвп ебать глаза будет сильно, а так наверное доделать надо хз. Ну а так сойдёт
Можешь попробовать доделать по другому, как пример реализации - берешь координаты игрока, расширяешь их через условные sin/cos до сферы, и если эти палочки подлетают в радиус игрока - их позицию откидывать можно в другую сторону либо прижимать к границе сферы, ну и тип сферу такую по размеру подобрать нужно так, что-бы в неё попадал и другой игрок при пвп
 
Можешь попробовать доделать по другому, как пример реализации - берешь координаты игрока, расширяешь их через условные sin/cos до сферы, и если эти палочки подлетают в радиус игрока - их позицию откидывать можно в другую сторону либо прижимать к границе сферы, ну и тип сферу такую по размеру подобрать нужно так, что-бы в неё попадал и другой игрок при пвп
Бир, а сам как оцениваешь код этого человека? Лично мне он понравился
 
Бир, а сам как оцениваешь код этого человека? Лично мне он понравился
Я бы не назвал его быстрым из-за использования glBegin, glEnd, glVertex* - это всё уже очень давно устаревший функционал со времён первых версий OpenGL, вместо этого лучше использовать майнкрафтовый Tessellator который из себя обычно представляет
VBO-VAO рендерер, так будет и более правильно, и подозреваю что сильно быстрее.
Вместо Iterator я бы использовал обычные for-циклы с обратным направлением раз нужно чистить.
Обновлял бы я частицы в тиках, а при рендере просто интерполировал бы позиции (если проще будет - lerp), т.к. частота обновлений совершенно нестабильная если делать это в каждом кадре (ну зависит от фпс, а не от тикрейта который почти всегда постоянен).
А код стайл - вряд-ли скорее всего при разработке чего-то подобного что-то значит, но я бы придерживался конвенции хотя-бы частично.

Проще говоря - есть куда расти, главное было бы желание :)
 
SS:Посмотреть вложение 315931
Сам код:
LineWorld:
Expand Collapse Copy
package im.expensive.functions.impl.render;

import com.google.common.eventbus.Subscribe;
import im.expensive.events.WorldEvent;
import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import net.minecraft.util.math.vector.Vector3d;
import org.lwjgl.opengl.GL11;

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

@FunctionRegister(name = "LineWorld", type = Category.Render)
public class LineWorld extends Function {

    private static final int MAX_LINES = 150;
    private static final int TRAIL_LENGTH = 30;
    private static final double SPEED = 0.10;
    private static final double SPAWN_RANGE = 20.0;
    private static final int LIFE_MIN = 160;
    private static final int LIFE_VAR = 120;
    private static final int MAX_SPARKS = 800;

    private final List<Line> lines = new ArrayList<>();
    private final List<Spark> sparks = new ArrayList<>();
    private final Random rnd = new Random();

    private static class Line {
        Vector3d pos;
        Vector3d vel;
        List<Vector3d> trail = new ArrayList<>();
        int colorInt;
        int life, maxLife;
        float baseThickness;
        Line(Vector3d pos, Vector3d vel, int colorInt, int life, float thickness) {
            this.pos = pos;
            this.vel = vel;
            this.colorInt = colorInt;
            this.life = life;
            this.maxLife = life;
            this.baseThickness = thickness;
            this.trail.add(pos);
        }
        boolean isDead() { return life <= 0; }
        float fade() { return (float) life / (float) maxLife; }
        void update(Random rnd) {
            double jitter = 0.035;
            Vector3d n = new Vector3d(
                    (rnd.nextDouble() - 0.5) * jitter,
                    (rnd.nextDouble() - 0.5) * jitter * 0.7,
                    (rnd.nextDouble() - 0.5) * jitter
            );
            vel = add(vel, n);
            vel = normalize(vel);
            vel = mul(vel, SPEED);
            pos = pos.add(vel);
            trail.add(pos);
            if (trail.size() > TRAIL_LENGTH) trail.remove(0);
            life--;
        }
    }

    private static class Spark {
        Vector3d pos;
        Vector3d vel;
        int life, maxLife;
        int colorInt;
        Spark(Vector3d pos, Vector3d vel, int life, int colorInt) {
            this.pos = pos;
            this.vel = vel;
            this.life = life;
            this.maxLife = life;
            this.colorInt = colorInt;
        }
        void update() {
            pos = pos.add(vel);
            vel = mul(vel, 0.96);
            life--;
        }
        boolean isDead() { return life <= 0; }
        float alpha() { return (float) life / (float) maxLife; }
    }

    @Subscribe
    public void onRender(WorldEvent e) {
        if (mc.player == null || mc.world == null) return;

        while (lines.size() < MAX_LINES) {
            double ang = rnd.nextDouble() * Math.PI * 2.0;
            double dist = rnd.nextDouble() * SPAWN_RANGE;
            double dx = Math.cos(ang) * dist;
            double dz = Math.sin(ang) * dist;
            double x = mc.player.getPosX() + dx;
            double y = mc.player.getPosY() + (rnd.nextDouble() - 0.5) * 4.0;
            double z = mc.player.getPosZ() + dz;
            Vector3d vel = new Vector3d(rnd.nextDouble() - 0.5, (rnd.nextDouble() - 0.5) * 0.3, rnd.nextDouble() - 0.5);
            vel = normalize(vel);
            vel = mul(vel, SPEED);
            int color = im.expensive.functions.impl.render.HUD.getColor(0, 1);
            int life = LIFE_MIN + rnd.nextInt(LIFE_VAR);
            float thickness = 1.6f + rnd.nextFloat() * 2.4f;
            lines.add(new Line(new Vector3d(x, y, z), vel, color, life, thickness));
        }

        Iterator<Line> lit = lines.iterator();
        while (lit.hasNext()) {
            Line L = lit.next();
            if (sparks.size() < MAX_SPARKS && rnd.nextDouble() < 0.18) {
                Vector3d svel = add(L.vel, new Vector3d((rnd.nextDouble() - 0.5) * 0.4, (rnd.nextDouble() - 0.5) * 0.4, (rnd.nextDouble() - 0.5) * 0.4));
                svel = normalize(svel);
                svel = mul(svel, 0.35 + rnd.nextDouble() * 0.6);
                int spLife = 12 + rnd.nextInt(18);
                sparks.add(new Spark(L.pos, svel, spLife, L.colorInt));
            }
            L.update(rnd);
            if (L.isDead()) lit.remove();
        }

        Iterator<Spark> sit = sparks.iterator();
        while (sit.hasNext()) {
            Spark s = sit.next();
            s.update();
            if (s.isDead()) sit.remove();
        }

        Vector3d camPos = mc.getRenderManager().info.getProjectedView();

        GL11.glPushMatrix();
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
        GL11.glEnable(GL11.GL_LINE_SMOOTH);

        for (Line L : lines) {
            int n = L.trail.size();
            if (n < 2) continue;
            int baseCol = L.colorInt;
            float baseR = ((baseCol >> 16) & 0xFF) / 255f;
            float baseG = ((baseCol >> 8) & 0xFF) / 255f;
            float baseB = (baseCol & 0xFF) / 255f;
            float fadeMaster = L.fade();

            for (int i = 1; i < n; i++) {
                Vector3d p1 = L.trail.get(i - 1);
                Vector3d p2 = L.trail.get(i);
                float t = (float) i / (float) (n - 1);
                float thickness = L.baseThickness * (1.0f - 0.85f * t) + 0.8f;
                float alpha = (1.0f - t * 0.95f) * fadeMaster;
                float satMult = 1.0f - t * 0.6f;
                float brightMult = 0.6f + (1.0f - t) * 0.4f;
                float r = clamp(baseR * satMult * brightMult, 0f, 1f);
                float g = clamp(baseG * satMult * brightMult, 0f, 1f);
                float b = clamp(baseB * satMult * brightMult, 0f, 1f);
                GL11.glLineWidth(Math.max(1.0f, thickness));
                GL11.glBegin(GL11.GL_LINES);
                GL11.glColor4f(r, g, b, alpha);
                GL11.glVertex3d(p1.x - camPos.x, p1.y - camPos.y, p1.z - camPos.z);
                GL11.glVertex3d(p2.x - camPos.x, p2.y - camPos.y, p2.z - camPos.z);
                GL11.glEnd();
            }
        }

        GL11.glPointSize(2.0f);
        GL11.glEnable(GL11.GL_POINT_SMOOTH);
        GL11.glBegin(GL11.GL_POINTS);
        for (Spark s : sparks) {
            float a = s.alpha();
            int c = s.colorInt;
            float rr = ((c >> 16) & 0xFF) / 255f;
            float gg = ((c >> 8) & 0xFF) / 255f;
            float bb = (c & 0xFF) / 255f;
            GL11.glColor4f(Math.min(1f, rr * 1.5f), Math.min(1f, gg * 1.5f), Math.min(1f, bb * 1.5f), a * 0.9f);
            GL11.glVertex3d(s.pos.x - camPos.x, s.pos.y - camPos.y, s.pos.z - camPos.z);
        }
        GL11.glEnd();
        GL11.glDisable(GL11.GL_POINT_SMOOTH);

        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_LINE_SMOOTH);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glPopMatrix();
    }

    private static Vector3d add(Vector3d a, Vector3d b) {
        return new Vector3d(a.x + b.x, a.y + b.y, a.z + b.z);
    }

    private static Vector3d mul(Vector3d v, double s) {
        return new Vector3d(v.x * s, v.y * s, v.z * s);
    }

    private static Vector3d normalize(Vector3d v) {
        double len = Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
        if (len == 0) return new Vector3d(0, 0, 0);
        return new Vector3d(v.x / len, v.y / len, v.z / len);
    }

    private static float clamp(float v, float a, float b) {
        return v < a ? a : Math.min(v, b);
    }
}
это на много круче можно было реализовать
 
это на много круче можно было реализовать
Так реализуй в чем проблема? Думаю, если ты пишешь комментарий о том что это можно лучше реализовать, тогда ты знаешь опенгл, тогда иди реализуй лучше, и сделай перезалив.. Просто я прикола не понимаю, человек новичок и типам таким что-то не нравиться, и если ты даже пишешь лучше реализовать можно было, тогда распиши как бы ты хотел лучше реализовать, а не просто выписывать 8 слов..
 
В целом кайф
 

Похожие темы

Назад
Сверху Снизу