Начинающий
- Статус
- Оффлайн
- Регистрация
- 9 Окт 2021
- Сообщения
- 6
- Реакции
- 0
- Выберите загрузчик игры
- OptiFine
SS:
Сам код:
Сам код:
LineWorld:
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);
}
}