Начинающий
- Статус
- Оффлайн
- Регистрация
- 25 Окт 2024
- Сообщения
- 35
- Реакции
- 0
- Выберите загрузчик игры
- Fabric
вот что то более менее
ss:
а вот как в рокстаре(no ad)
кодик:
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();
}
}
}
а вот как в рокстаре(no ad)
Последнее редактирование: