Начинающий
- Статус
- Оффлайн
- Регистрация
- 9 Май 2023
- Сообщения
- 222
- Реакции
- 6
- Выберите загрузчик игры
- Fabric
Ну даже хз, что сказать. Просто KillEffects как в рокстаре 
ss прикрепил
Update - попросили добавить EntityDeathEvent

ss прикрепил
Update - попросили добавить EntityDeathEvent
xz:
package zenith.zov.client.modules.impl.render;
import com.darkmagician6.eventapi.EventTarget;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.BuiltBuffer;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import zenith.zov.Zenith;
import zenith.zov.base.animations.base.Animation;
import zenith.zov.base.animations.base.Easing;
import zenith.zov.base.events.impl.game.EntityDeathEvent;
import zenith.zov.base.events.impl.render.EventRender3D;
import zenith.zov.client.modules.api.Category;
import zenith.zov.client.modules.api.Module;
import zenith.zov.client.modules.api.ModuleAnnotation;
import zenith.zov.client.modules.api.setting.impl.BooleanSetting;
import zenith.zov.client.modules.api.setting.impl.ColorSetting;
import zenith.zov.client.modules.api.setting.impl.ModeSetting;
import zenith.zov.utility.math.MathUtility;
import zenith.zov.utility.render.DrawUtility;
import zenith.zov.utility.render.RenderUtility;
import zenith.zov.utility.render.display.base.color.ColorRGBA;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CopyOnWriteArrayList;
@ModuleAnnotation(name = "Kill Effects", category = Category.RENDER, description = "Эффекты при убийстве")
public final class KillEffects extends Module {
public static final KillEffects INSTANCE = new KillEffects();
private final List<DeathEffect> effects = new CopyOnWriteArrayList<>();
private final List<Particle> particles = new CopyOnWriteArrayList<>();
private static final Random random = new Random();
private final ModeSetting mode = new ModeSetting("Режим", "Молния", "Частицы");
private final BooleanSetting gravity = new BooleanSetting("Гравитация", true, () -> mode.is("Частицы"));
private final ColorSetting color = new ColorSetting("Цвет", 100, 150, 255, 255);
private KillEffects() {
}
@EventTarget
public void onEntityDeath(EntityDeathEvent event) {
if (!event.getEntity().isRemoved() && event.getEntity() instanceof LivingEntity living) {
ColorRGBA c = color.getColor();
if (mode.is("Молния")) {
effects.add(new DeathEffect(living.getPos(), c));
} else if (mode.is("Частицы")) {
spawnParticles(living, c);
}
}
}
@EventTarget
public void on3DRender(EventRender3D event) {
MatrixStack ms = event.getMatrix();
Camera camera = mc.gameRenderer.getCamera();
Vec3d cameraPos = camera.getPos();
ms.push();
RenderSystem.enableBlend();
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE);
RenderSystem.enableDepthTest();
RenderSystem.disableCull();
RenderSystem.depthMask(false);
Identifier id = Identifier.of("zenith", "icons/glow.png");
RenderSystem.setShaderTexture(0, id);
RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX_COLOR);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder builder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
for (DeathEffect effect : this.effects) {
effect.render(builder, ms, camera);
}
for (Particle particle : this.particles) {
if (!particle.isDead()) {
particle.update();
particle.render(builder, ms, camera);
}
}
BuiltBuffer builtBuffer = builder.endNullable();
if (builtBuffer != null) {
BufferRenderer.drawWithGlobalProgram(builtBuffer);
}
this.particles.removeIf(Particle::isDead);
this.effects.removeIf(DeathEffect::isFinished);
RenderSystem.depthMask(true);
RenderSystem.setShaderTexture(0, 0);
RenderSystem.disableBlend();
RenderSystem.enableCull();
RenderSystem.disableDepthTest();
ms.pop();
}
private void spawnParticles(LivingEntity entity, ColorRGBA color) {
Vec3d pos = entity.getPos();
float width = entity.getWidth();
float height = entity.getHeight();
float yaw = (float) Math.toRadians(-entity.prevYaw + 90.0f);
boolean hasGravity = this.gravity.isEnabled();
int count = 194;
float hOffset = height - 0.2f;
float spread = width * 0.4f;
this.spawnSphere(pos.add(0.0, hOffset, 0.0), spread, count / 10, yaw, color, hasGravity);
this.spawnBody(pos, width * 0.4f, height * 0.85f, width * 0.4f, width * 0.2f, yaw, count / 4, color, hasGravity);
for (int i = -1; i <= 1; i += 2) {
Vec3d armPos = new Vec3d(Math.sin(yaw) * width * 0.5 * i, height * 0.75f, Math.cos(yaw) * width * 0.5 * i);
this.spawnLimb(pos.add(armPos), width * 0.4f, width * 0.15f, yaw, count / 8, color, hasGravity);
Vec3d legPos = new Vec3d(Math.sin(yaw) * width * 0.15 * i, height * 0.4f, Math.cos(yaw) * width * 0.15 * i);
this.spawnLimb(pos.add(legPos), height * 0.45f, width * 0.15f, yaw, count / 6, color, hasGravity);
}
}
private void spawnSphere(Vec3d pos, float radius, int count, float yaw, ColorRGBA color, boolean hasGravity) {
for (int i = 0; i < count; ++i) {
float angle1 = random.nextFloat() * (float) Math.PI * 2.0f;
float angle2 = (float) Math.acos(2.0f * random.nextFloat() - 1.0f);
float r = radius * (float) Math.cbrt(random.nextFloat());
float px = r * (float) (Math.sin(angle2) * Math.cos(angle1));
float py = r * (float) (Math.sin(angle2) * Math.sin(angle1));
float pz = r * (float) Math.cos(angle2);
float speedBase = hasGravity ? 0.02f : 0.008f;
float vx = (random.nextFloat() - 0.5f) * speedBase;
float vy = hasGravity ? 0.03f + random.nextFloat() * 0.04f : (random.nextFloat() - 0.5f) * 0.008f;
float vz = (random.nextFloat() - 0.5f) * speedBase;
this.particles.add(new Particle(pos, px, py, pz, vx, vy, vz, color, hasGravity));
}
}
private void spawnBody(Vec3d pos, float radiusX, float height, float radiusZ, float spread, float yaw, int count, ColorRGBA color, boolean hasGravity) {
for (int i = 0; i < count; ++i) {
float ox = (random.nextFloat() - 0.5f) * radiusX * 2.0f;
float oy = random.nextFloat() * height;
float oz = (random.nextFloat() - 0.5f) * spread * 2.0f;
float px = (float) ((double) ox * Math.cos(yaw) - (double) oz * Math.sin(yaw));
float pz = (float) ((double) ox * Math.sin(yaw) + (double) oz * Math.cos(yaw));
float speedBase = hasGravity ? 0.025f : 0.01f;
float vx = (random.nextFloat() - 0.5f) * speedBase;
float vy = hasGravity ? 0.04f + random.nextFloat() * 0.05f : (random.nextFloat() - 0.5f) * 0.01f;
float vz = (random.nextFloat() - 0.5f) * speedBase;
this.particles.add(new Particle(pos, px, oy, pz, vx, vy, vz, color, hasGravity));
}
}
private void spawnLimb(Vec3d pos, float height, float radius, float yaw, int count, ColorRGBA color, boolean hasGravity) {
for (int i = 0; i < count; ++i) {
float oy = -random.nextFloat() * height;
float ox = (random.nextFloat() - 0.5f) * radius * 2.0f;
float oz = (random.nextFloat() - 0.5f) * radius * 2.0f;
float speedBase = hasGravity ? 0.018f : 0.006f;
float vx = (random.nextFloat() - 0.5f) * speedBase;
float vy = hasGravity ? 0.025f + random.nextFloat() * 0.035f : (random.nextFloat() - 0.5f) * 0.006f;
float vz = (random.nextFloat() - 0.5f) * speedBase;
this.particles.add(new Particle(pos, ox, oy, oz, vx, vy, vz, color, hasGravity));
}
}
class Particle {
double x, y, z;
float vx, vy, vz;
long startTime, lastUpdate;
float gravityFactor;
long lifeTime;
boolean hasGravity;
float friction;
ColorRGBA color;
static final float size = 0.5f;
Particle(Vec3d origin, float ox, float oy, float oz, float vx, float vy, float vz, ColorRGBA color, boolean hasGravity) {
this.x = origin.x + ox;
this.y = origin.y + oy;
this.z = origin.z + oz;
this.color = color;
this.startTime = this.lastUpdate = System.currentTimeMillis();
this.hasGravity = hasGravity;
this.gravityFactor = 0.005f + random.nextFloat() * 0.005f;
this.lifeTime = 1508 + random.nextInt(1508);
this.friction = hasGravity ? 0.999f : 0.995f;
float spread = hasGravity ? 0.04f : 0.03f;
this.vx = (random.nextFloat() - 0.5f) * spread;
this.vy = hasGravity ? 0.025f + random.nextFloat() * 0.035f : (random.nextFloat() - 0.5f) * 0.03f;
this.vz = (random.nextFloat() - 0.5f) * spread;
}
void update() {
float bounceFriction = 0.5f;
long current = System.currentTimeMillis();
float delta = (float) (current - this.lastUpdate) / 16.67f;
this.lastUpdate = current;
if (delta > 5.0f) delta = 5.0f;
if (this.hasGravity) {
this.vy -= this.gravityFactor * delta;
}
float drag = (float) Math.pow(this.friction, delta);
this.vx *= drag;
this.vy *= drag;
this.vz *= drag;
double nextX = this.x + (this.vx * delta);
double nextY = this.y + (this.vy * delta);
double nextZ = this.z + (this.vz * delta);
if (this.hasGravity && mc.world != null) {
if (!mc.world.getBlockState(BlockPos.ofFloored(this.x, nextY - 0.05, this.z)).isAir()) {
this.vy = -this.vy * bounceFriction;
nextY = this.y;
}
if (!mc.world.getBlockState(BlockPos.ofFloored(nextX, this.y, this.z)).isAir()) {
this.vx = -this.vx * bounceFriction;
nextX = this.x;
}
if (!mc.world.getBlockState(BlockPos.ofFloored(this.x, this.y, nextZ)).isAir()) {
this.vz = -this.vz * bounceFriction;
nextZ = this.z;
}
}
if (Math.abs(this.vy) <= 1.0E-4f) {
this.vx = 0.0f;
this.vz = 0.0f;
}
this.x = nextX;
this.y = nextY;
this.z = nextZ;
}
float getAlpha() {
float progress = MathHelper.clamp((float) (System.currentTimeMillis() - this.startTime) / this.lifeTime, 0.0f, 1.0f);
return 1.0f - progress;
}
boolean isDead() {
return System.currentTimeMillis() - this.startTime > this.lifeTime;
}
void render(BufferBuilder builder, MatrixStack ms, Camera camera) {
float innerSize = 0.1f;
float alpha = this.getAlpha();
ms.push();
RenderUtility.prepareMatrices(ms, new Vec3d(this.x, this.y, this.z));
ms.multiply(camera.getRotation());
DrawUtility.drawImage(ms, builder, -innerSize / 2.0f, -innerSize / 2.0f, 0.0, innerSize, innerSize, this.color.withAlpha(255 * 0.9f * alpha));
ms.pop();
}
}
static class DeathEffect {
final Vec3d pos;
final ColorRGBA color;
final Animation animation = new Animation(300L, 0.0f, Easing.FIGMA_EASE_IN_OUT);
final Animation fadeAnimation = new Animation(600L, 0.0f, Easing.FIGMA_EASE_IN_OUT);
final List<Vec3d> poses = new ArrayList<>();
boolean fadingOut = false;
public DeathEffect(Vec3d pos, ColorRGBA color) {
this.pos = pos;
this.color = color;
Vec3d lastPos = pos;
for (int i = 0; i < 200; i++) {
poses.add(lastPos = lastPos.add(
MathUtility.random(-0.25f, 0.25f),
0.25,
MathUtility.random(-0.25f, 0.25f)
));
}
}
boolean isFinished() {
return fadingOut && fadeAnimation.getValue() >= 0.99f;
}
void render(BufferBuilder builder, MatrixStack ms, Camera camera) {
animation.setEasing(Easing.BOUNCE_IN);
animation.setDuration(500L);
animation.update(true);
if (animation.getValue() >= 0.99f && !fadingOut) {
fadingOut = true;
}
fadeAnimation.setEasing(Easing.FIGMA_EASE_IN_OUT);
fadeAnimation.setDuration(250L);
fadeAnimation.update(fadingOut);
float appearAlpha = animation.getValue();
float fadeAlpha = 1.0f - fadeAnimation.getValue();
float finalAlpha = appearAlpha * fadeAlpha;
if (finalAlpha <= 0.001f) return;
for (Vec3d pos : poses) {
float size = (float)(1.0 + 3.0 * (pos.y - this.pos.y) / 50.0);
ms.push();
RenderUtility.prepareMatrices(ms, pos);
ms.multiply(camera.getRotation());
DrawUtility.drawImage(
ms,
builder,
-size / 2.0f,
-size / 2.0f,
0.0,
size,
size,
color.withAlpha(255.0f * finalAlpha * 0.4f)
);
ms.pop();
}
}
}
}
Event:
package zenith.zov.base.events.impl.game;
import com.darkmagician6.eventapi.events.Event;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import org.jetbrains.annotations.Nullable;
@Getter
@RequiredArgsConstructor
public class EntityDeathEvent implements Event {
private final LivingEntity entity;
private final DamageSource source;
@Nullable
public LivingEntity getKillerEntity() {
return entity.getPrimeAdversary();
}
}
Вложения
Последнее редактирование: