Исходник Particles Expensive Ready

Начинающий
Статус
Оффлайн
Регистрация
3 Авг 2022
Сообщения
246
Реакции[?]
2
Поинты[?]
2K
Не знаю кому он нужен но может быть кому что пригодиться
Пожалуйста, авторизуйтесь для просмотра ссылки.


code:
package ru.expensive.features.impl.render;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import ru.expensive.events.Event;
import ru.expensive.events.impl.player.EventUpdate;
import ru.expensive.features.Category;
import ru.expensive.features.Feature;
import ru.expensive.features.FeatureInfo;
import ru.expensive.features.settings.impl.ModeSetting;
import ru.expensive.features.settings.impl.SliderSetting;
import ru.expensive.utils.math.MathUtil;
import ru.expensive.utils.render.ColorUtil;
import ru.expensive.utils.render.RenderUtil;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldVertexBufferUploader;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.math.vector.Vector3f;
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;

@FeatureInfo(name = "Particles", type = Category.Render)
public class Particles extends Feature {

private final ModeSetting mode = new ModeSetting("Mode", "SnowFlake", "SnowFlake", "Stars", "Hearts", "Dollars", "Bloom");
private final SliderSetting count = new SliderSetting("Count", 100, 20, 800, 1);
private final SliderSetting size = new SliderSetting("Size", 1f, 0.1f, 6.0f, 0.1f);
private static final ArrayList<ParticleBase> particles = new ArrayList<>();

public Particles() {
addSettings(mode, count, size);
}

@Override
public void onEvent(Event event) {
if (event instanceof EventUpdate) {
particles.removeIf(ParticleBase::tick);

for (int j = particles.size(); j < count.getValue().floatValue(); j++) {
particles.add(new ParticleBase((float) (mc.player.getPosX() + MathUtil.random(-48f, 48f)), (float) (mc.player.getPosY() + MathUtil.random(2, 48f)), (float) (mc.player.getPosZ() + MathUtil.random(-48f, 48f)), MathUtil.random(-0.4f, 0.4f), MathUtil.random(-0.1f, 0.1f), MathUtil.random(-0.4f, 0.4f)));
}
}
}

public static void onPreRender3D(MatrixStack matrixStack) {
matrixStack.push();
RenderSystem.enableBlend();
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
RenderSystem.enableDepthTest();
RenderSystem.depthMask(false);
BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX_LIGHTMAP);
particles.forEach(p -> p.render(bufferBuilder));
bufferBuilder.finishDrawing();
WorldVertexBufferUploader.draw(bufferBuilder);
RenderSystem.depthMask(true);
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.disableDepthTest();
RenderSystem.disableBlend();
matrixStack.pop();
}

public class ParticleBase {

protected float prevposX, prevposY, prevposZ, posX, posY, posZ, motionX, motionY, motionZ;
protected int age, maxAge;

public ParticleBase(float posX, float posY, float posZ, float motionX, float motionY, float motionZ) {
this.posX = posX;
this.posY = posY;
this.posZ = posZ;
prevposX = posX;
prevposY = posY;
prevposZ = posZ;
this.motionX = motionX;
this.motionY = motionY;
this.motionZ = motionZ;
age = (int) MathUtil.random(100, 300);
maxAge = age;
}

public boolean tick() {
if (mc.player.getDistanceSq(posX, posY, posZ) > 4096) age -= 8;
else age--;

if (age < 0)
return true;

prevposX = posX;
prevposY = posY;
prevposZ = posZ;

posX += motionX;
posY += motionY;
posZ += motionZ;

motionX *= 0.9f;
motionY *= 0.9f;
motionZ *= 0.9f;

motionY -= 0.001f;

return false;
}

public void render(BufferBuilder bufferBuilder) {
if (mode.is("Bloom")) {
mc.getTextureManager().bindTexture(new ResourceLocation("expensive/images/firefly.png"));
} else if (mode.is("SnowFlake")) {
mc.getTextureManager().bindTexture(new ResourceLocation("expensive/images/snowflake.png"));
} else if (mode.is("Dollars")) {
mc.getTextureManager().bindTexture(new ResourceLocation("expensive/images/dollar.png"));
} else if (mode.is("Hearts")) {
mc.getTextureManager().bindTexture(new ResourceLocation("expensive/images/heart.png"));
} else if (mode.is("Stars")) {
mc.getTextureManager().bindTexture(new ResourceLocation("expensive/images/star.png"));
}

ActiveRenderInfo camera = mc.gameRenderer.getActiveRenderInfo();
int color = ColorUtil.getColorStyle(age * 2);
Vector3d pos = RenderUtil.interpolatePos(prevposX, prevposY, prevposZ, posX, posY, posZ);

MatrixStack matrices = new MatrixStack();
matrices.rotate(Vector3f.XP.rotationDegrees(camera.getPitch()));
matrices.rotate(Vector3f.YP.rotationDegrees(camera.getYaw() + 180.0F));
matrices.translate(pos.x, pos.y, pos.z);
matrices.rotate(Vector3f.YP.rotationDegrees(-camera.getYaw()));
matrices.rotate(Vector3f.XP.rotationDegrees(camera.getPitch()));

Matrix4f matrix1 = matrices.getLast().getMatrix();

bufferBuilder.pos(matrix1, 0, -size.getValue().floatValue(), 0).color(color).tex(0, 1 - 0.01f).lightmap(0, 240).endVertex();
bufferBuilder.pos(matrix1, -size.getValue().floatValue(), -size.getValue().floatValue(), 0).color(color).tex(1, 1 - 0.01f).lightmap(0, 240).endVertex();
bufferBuilder.pos(matrix1, -size.getValue().floatValue(), 0, 0).color(color).tex(1, 0).lightmap(0, 240).endVertex();
bufferBuilder.pos(matrix1, 0, 0, 0).color(color).tex(0, 0).lightmap(0, 240).endVertex();
}
}
}
}
 
Начинающий
Статус
Оффлайн
Регистрация
22 Янв 2024
Сообщения
79
Реакции[?]
0
Поинты[?]
0
Не знаю кому он нужен но может быть кому что пригодиться
Пожалуйста, авторизуйтесь для просмотра ссылки.


code:
package ru.expensive.features.impl.render;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import ru.expensive.events.Event;
import ru.expensive.events.impl.player.EventUpdate;
import ru.expensive.features.Category;
import ru.expensive.features.Feature;
import ru.expensive.features.FeatureInfo;
import ru.expensive.features.settings.impl.ModeSetting;
import ru.expensive.features.settings.impl.SliderSetting;
import ru.expensive.utils.math.MathUtil;
import ru.expensive.utils.render.ColorUtil;
import ru.expensive.utils.render.RenderUtil;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldVertexBufferUploader;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.math.vector.Vector3f;
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;

@FeatureInfo(name = "Particles", type = Category.Render)
public class Particles extends Feature {

private final ModeSetting mode = new ModeSetting("Mode", "SnowFlake", "SnowFlake", "Stars", "Hearts", "Dollars", "Bloom");
private final SliderSetting count = new SliderSetting("Count", 100, 20, 800, 1);
private final SliderSetting size = new SliderSetting("Size", 1f, 0.1f, 6.0f, 0.1f);
private static final ArrayList<ParticleBase> particles = new ArrayList<>();

public Particles() {
addSettings(mode, count, size);
}

@Override
public void onEvent(Event event) {
if (event instanceof EventUpdate) {
particles.removeIf(ParticleBase::tick);

for (int j = particles.size(); j < count.getValue().floatValue(); j++) {
particles.add(new ParticleBase((float) (mc.player.getPosX() + MathUtil.random(-48f, 48f)), (float) (mc.player.getPosY() + MathUtil.random(2, 48f)), (float) (mc.player.getPosZ() + MathUtil.random(-48f, 48f)), MathUtil.random(-0.4f, 0.4f), MathUtil.random(-0.1f, 0.1f), MathUtil.random(-0.4f, 0.4f)));
}
}
}

public static void onPreRender3D(MatrixStack matrixStack) {
matrixStack.push();
RenderSystem.enableBlend();
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
RenderSystem.enableDepthTest();
RenderSystem.depthMask(false);
BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX_LIGHTMAP);
particles.forEach(p -> p.render(bufferBuilder));
bufferBuilder.finishDrawing();
WorldVertexBufferUploader.draw(bufferBuilder);
RenderSystem.depthMask(true);
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.disableDepthTest();
RenderSystem.disableBlend();
matrixStack.pop();
}

public class ParticleBase {

protected float prevposX, prevposY, prevposZ, posX, posY, posZ, motionX, motionY, motionZ;
protected int age, maxAge;

public ParticleBase(float posX, float posY, float posZ, float motionX, float motionY, float motionZ) {
this.posX = posX;
this.posY = posY;
this.posZ = posZ;
prevposX = posX;
prevposY = posY;
prevposZ = posZ;
this.motionX = motionX;
this.motionY = motionY;
this.motionZ = motionZ;
age = (int) MathUtil.random(100, 300);
maxAge = age;
}

public boolean tick() {
if (mc.player.getDistanceSq(posX, posY, posZ) > 4096) age -= 8;
else age--;

if (age < 0)
return true;

prevposX = posX;
prevposY = posY;
prevposZ = posZ;

posX += motionX;
posY += motionY;
posZ += motionZ;

motionX *= 0.9f;
motionY *= 0.9f;
motionZ *= 0.9f;

motionY -= 0.001f;

return false;
}

public void render(BufferBuilder bufferBuilder) {
if (mode.is("Bloom")) {
mc.getTextureManager().bindTexture(new ResourceLocation("expensive/images/firefly.png"));
} else if (mode.is("SnowFlake")) {
mc.getTextureManager().bindTexture(new ResourceLocation("expensive/images/snowflake.png"));
} else if (mode.is("Dollars")) {
mc.getTextureManager().bindTexture(new ResourceLocation("expensive/images/dollar.png"));
} else if (mode.is("Hearts")) {
mc.getTextureManager().bindTexture(new ResourceLocation("expensive/images/heart.png"));
} else if (mode.is("Stars")) {
mc.getTextureManager().bindTexture(new ResourceLocation("expensive/images/star.png"));
}

ActiveRenderInfo camera = mc.gameRenderer.getActiveRenderInfo();
int color = ColorUtil.getColorStyle(age * 2);
Vector3d pos = RenderUtil.interpolatePos(prevposX, prevposY, prevposZ, posX, posY, posZ);

MatrixStack matrices = new MatrixStack();
matrices.rotate(Vector3f.XP.rotationDegrees(camera.getPitch()));
matrices.rotate(Vector3f.YP.rotationDegrees(camera.getYaw() + 180.0F));
matrices.translate(pos.x, pos.y, pos.z);
matrices.rotate(Vector3f.YP.rotationDegrees(-camera.getYaw()));
matrices.rotate(Vector3f.XP.rotationDegrees(camera.getPitch()));

Matrix4f matrix1 = matrices.getLast().getMatrix();

bufferBuilder.pos(matrix1, 0, -size.getValue().floatValue(), 0).color(color).tex(0, 1 - 0.01f).lightmap(0, 240).endVertex();
bufferBuilder.pos(matrix1, -size.getValue().floatValue(), -size.getValue().floatValue(), 0).color(color).tex(1, 1 - 0.01f).lightmap(0, 240).endVertex();
bufferBuilder.pos(matrix1, -size.getValue().floatValue(), 0, 0).color(color).tex(1, 0).lightmap(0, 240).endVertex();
bufferBuilder.pos(matrix1, 0, 0, 0).color(color).tex(0, 0).lightmap(0, 240).endVertex();
}
}
}
}
ss pls!
 
Сверху Снизу