Подведи собственные итоги года совместно с YOUGAME и забери ценные призы! Перейти

Часть функционала SkeletonEsp 3.1 Ready

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
22 Июн 2024
Сообщения
14
Реакции
0
Выберите загрузчик игры
  1. Vanilla
Java:
Expand Collapse Copy
package im.babka.functions.impl.render;

import com.google.common.eventbus.Subscribe;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import im.babka.command.friends.FriendStorage;
import im.babka.events.EventDisplay;
import im.babka.functions.api.Category;
import im.babka.functions.api.Function;
import im.babka.functions.api.FunctionRegister;
import im.babka.functions.settings.impl.ColorSetting;
import im.babka.utils.math.MathUtil;
import im.babka.utils.projections.ProjectionUtil;
import im.babka.utils.render.ColorUtils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.math.vector.Vector3d;
import org.lwjgl.opengl.GL11;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import static net.minecraft.client.renderer.WorldRenderer.frustum;

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

public ColorSetting color = new ColorSetting("Color", ColorUtils.rgb(255, 255, 255));

public SkeletonEsp() {
addSettings(color);
    }

private final HashMap<PlayerEntity, Vector3d[]> pointsMap = new HashMap<>();

@Subscribe
    public void onDisplay(EventDisplay e) {
if (mc.world == null || e.getType() != EventDisplay.Type.PRE) return;

pointsMap.clear();

float partial = e.getPartialTicks();

for (PlayerEntity player : mc.world.getPlayers()) {
if (player == mc.player) continue;
if (!player.isAlive()) continue;
if (!isInView(player)) continue;

            Vector3d[] pts = calcPoints(player, partial);
if (pts != null) pointsMap.put(player, pts);
        }

        renderSkeletons(e.getMatrixStack());
    }

private Vector3d[] calcPoints(PlayerEntity p, float partial) {
double x = MathUtil.interpolate(p.getPosX(), p.lastTickPosX, partial);
double y = MathUtil.interpolate(p.getPosY(), p.lastTickPosY, partial);
double z = MathUtil.interpolate(p.getPosZ(), p.lastTickPosZ, partial);

        AxisAlignedBB bb = p.getBoundingBox();
double width = bb.maxX - bb.minX;
double height = bb.maxY - bb.minY;

double centerX = x;
double baseY = y;
double centerZ = z;

double headY = baseY + p.getEyeHeight();
double shoulderY = baseY + 1.35;
double hipY = baseY + 0.75;

float yaw = (p.prevRotationYaw + (p.rotationYaw - p.prevRotationYaw) * partial);

double yawRad = Math.toRadians(yaw);
double sinYaw = Math.sin(yawRad);
double cosYaw = Math.cos(yawRad);

double forwardX = -sinYaw;
double forwardZ = cosYaw;

float prevSwingAmount = getPrevLimbSwingAmount(p);
float swingAmount = getLimbSwingAmount(p);
float interpolatedSwingAmount = prevSwingAmount + (swingAmount - prevSwingAmount) * partial;

float limbSwingPos = getLimbSwing(p) + partial;

double armOffset = 0.375;
double legOffset = 0.125;
double armLength = 0.75;
double legLength = 0.75;

Vector3d head = new Vector3d(centerX, headY, centerZ);
Vector3d body = new Vector3d(centerX, shoulderY, centerZ);
Vector3d hip = new Vector3d(centerX, hipY, centerZ);

double leftShoulderX = centerX + (armOffset * cosYaw);
double leftShoulderZ = centerZ + (armOffset * sinYaw);
Vector3d leftShoulder = new Vector3d(leftShoulderX, shoulderY, leftShoulderZ);

double rightShoulderX = centerX - (armOffset * cosYaw);
double rightShoulderZ = centerZ - (armOffset * sinYaw);
Vector3d rightShoulder = new Vector3d(rightShoulderX, shoulderY, rightShoulderZ);

float leftArmXRot = MathHelper.cos(limbSwingPos * 0.6662F) * 2.0F * interpolatedSwingAmount * 0.5F;
double leftCosRot = Math.cos(leftArmXRot);
double leftSinRot = Math.sin(leftArmXRot);
double leftRelY = -armLength * leftCosRot;
double leftRelF = armLength * leftSinRot;
        Vector3d leftHand = leftShoulder.add(forwardX * leftRelF, leftRelY, forwardZ * leftRelF);

float rightArmXRot = MathHelper.cos(limbSwingPos * 0.6662F + (float) Math.PI) * 2.0F * interpolatedSwingAmount * 0.5F;
double rightCosRot = Math.cos(rightArmXRot);
double rightSinRot = Math.sin(rightArmXRot);
double rightRelY = -armLength * rightCosRot;
double rightRelF = armLength * rightSinRot;
        Vector3d rightHand = rightShoulder.add(forwardX * rightRelF, rightRelY, forwardZ * rightRelF);

double leftHipX = centerX + (legOffset * cosYaw);
double leftHipZ = centerZ + (legOffset * sinYaw);
Vector3d leftHip = new Vector3d(leftHipX, hipY, leftHipZ);

double rightHipX = centerX - (legOffset * cosYaw);
double rightHipZ = centerZ - (legOffset * sinYaw);
Vector3d rightHip = new Vector3d(rightHipX, hipY, rightHipZ);

float leftLegXRot = MathHelper.cos(limbSwingPos * 0.6662F + (float) Math.PI) * 1.4F * interpolatedSwingAmount * 0.5F;
double leftLegCosRot = Math.cos(leftLegXRot);
double leftLegSinRot = Math.sin(leftLegXRot);
double leftLegRelY = -legLength * leftLegCosRot;
double leftLegRelF = legLength * leftLegSinRot;
        Vector3d leftFoot = leftHip.add(forwardX * leftLegRelF, leftLegRelY, forwardZ * leftLegRelF);

float rightLegXRot = MathHelper.cos(limbSwingPos * 0.6662F) * 1.4F * interpolatedSwingAmount * 0.5F;
double rightLegCosRot = Math.cos(rightLegXRot);
double rightLegSinRot = Math.sin(rightLegXRot);
double rightLegRelY = -legLength * rightLegCosRot;
double rightLegRelF = legLength * rightLegSinRot;
        Vector3d rightFoot = rightHip.add(forwardX * rightLegRelF, rightLegRelY, forwardZ * rightLegRelF);

return new Vector3d[]{head, body, hip, leftShoulder, rightShoulder, leftHip, rightHip, leftHand, rightHand, leftFoot, rightFoot};
    }

private void renderSkeletons(MatrixStack matrixStack) {
RenderSystem.disableTexture();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();

GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glLineWidth(1.5f);

int clr = 0xFFFFFFFF;
try {
clr = color.get();
} catch (Exception ignored) {}

for (Map.Entry<PlayerEntity, Vector3d[]> e : pointsMap.entrySet()) {
            PlayerEntity p = e.getKey();
            Vector3d[] pts = e.getValue();

int useColor = FriendStorage.isFriend(p.getName().getString()) ? ColorUtils.rgb(144,238,144) : clr;

Vector2f head2 = ProjectionUtil.project(pts[0].x, pts[0].y, pts[0].z);
Vector2f body2 = ProjectionUtil.project(pts[1].x, pts[1].y, pts[1].z);
Vector2f hip2 = ProjectionUtil.project(pts[2].x, pts[2].y, pts[2].z);
Vector2f leftShoulder2 = ProjectionUtil.project(pts[3].x, pts[3].y, pts[3].z);
Vector2f rightShoulder2 = ProjectionUtil.project(pts[4].x, pts[4].y, pts[4].z);
Vector2f leftHip2 = ProjectionUtil.project(pts[5].x, pts[5].y, pts[5].z);
Vector2f rightHip2 = ProjectionUtil.project(pts[6].x, pts[6].y, pts[6].z);
Vector2f leftHand2 = ProjectionUtil.project(pts[7].x, pts[7].y, pts[7].z);
Vector2f rightHand2 = ProjectionUtil.project(pts[8].x, pts[8].y, pts[8].z);
Vector2f leftFoot2 = ProjectionUtil.project(pts[9].x, pts[9].y, pts[9].z);
Vector2f rightFoot2 = ProjectionUtil.project(pts[10].x, pts[10].y, pts[10].z);

if (isInvalid(head2) || isInvalid(body2) || isInvalid(hip2) || isInvalid(leftShoulder2) || isInvalid(rightShoulder2) || isInvalid(leftHip2) || isInvalid(rightHip2) || isInvalid(leftHand2) || isInvalid(rightHand2) || isInvalid(leftFoot2) || isInvalid(rightFoot2))
continue;

            AxisAlignedBB bb = p.getBoundingBox();
double height = bb.maxY - bb.minY;
double headSize = height / 32.0 * 8.0;
double headHalf = headSize / 2;
AxisAlignedBB headBB = new AxisAlignedBB(bb.minX + (bb.maxX - bb.minX) / 2 - headHalf, bb.maxY - headSize, bb.minZ + (bb.maxZ - bb.minZ) / 2 - headHalf,
bb.minX + (bb.maxX - bb.minX) / 2 + headHalf, bb.maxY, bb.minZ + (bb.maxZ - bb.minZ) / 2 + headHalf);

Vector3d[] corners = new Vector3d[]{
new Vector3d(headBB.minX, headBB.minY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.minY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.minY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.minY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.maxY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.maxY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.maxY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.maxY, headBB.maxZ)
            };

float left = Float.MAX_VALUE;
float right = Float.MIN_VALUE;
float top = Float.MAX_VALUE;
float bottom = Float.MIN_VALUE;

boolean valid = true;
for (Vector3d corner : corners) {
Vector2f proj = ProjectionUtil.project(corner.x, corner.y, corner.z);
if (isInvalid(proj)) {
valid = false;
break;
                }
left = Math.min(left, proj.x);
right = Math.max(right, proj.x);
top = Math.min(top, proj.y);
bottom = Math.max(bottom, proj.y);
            }

if (!valid) continue;

GL11.glBegin(GL11.GL_LINES);
            setGLColor(useColor);

GL11.glVertex2f(head2.x, head2.y);
GL11.glVertex2f(body2.x, body2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(hip2.x, hip2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(leftShoulder2.x, leftShoulder2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(rightShoulder2.x, rightShoulder2.y);

GL11.glVertex2f(hip2.x, hip2.y);
GL11.glVertex2f(leftHip2.x, leftHip2.y);

GL11.glVertex2f(hip2.x, hip2.y);
GL11.glVertex2f(rightHip2.x, rightHip2.y);

GL11.glVertex2f(leftShoulder2.x, leftShoulder2.y);
GL11.glVertex2f(leftHand2.x, leftHand2.y);

GL11.glVertex2f(rightShoulder2.x, rightShoulder2.y);
GL11.glVertex2f(rightHand2.x, rightHand2.y);

GL11.glVertex2f(leftHip2.x, leftHip2.y);
GL11.glVertex2f(leftFoot2.x, leftFoot2.y);

GL11.glVertex2f(rightHip2.x, rightHip2.y);
GL11.glVertex2f(rightFoot2.x, rightFoot2.y);

GL11.glVertex2f(left, top);
GL11.glVertex2f(right, top);

GL11.glVertex2f(right, top);
GL11.glVertex2f(right, bottom);

GL11.glVertex2f(right, bottom);
GL11.glVertex2f(left, bottom);

GL11.glVertex2f(left, bottom);
GL11.glVertex2f(left, top);

GL11.glEnd();
        }

GL11.glPopAttrib();

RenderSystem.disableBlend();
RenderSystem.enableTexture();
    }

private boolean isInvalid(Vector2f v) {
if (v == null) return true;
return Float.isNaN(v.x) || Float.isNaN(v.y) || v.x == Float.NEGATIVE_INFINITY || v.y == Float.NEGATIVE_INFINITY;
    }

private void setGLColor(int c) {
float a = ((c >> 24) & 0xFF) / 255f;
float r = ((c >> 16) & 0xFF) / 255f;
float g = ((c >> 8) & 0xFF) / 255f;
float b = (c & 0xFF) / 255f;
GL11.glColor4f(r, g, b, a == 0f ? 1f : a);
    }

public boolean isInView(net.minecraft.entity.Entity ent) {
if (mc.getRenderViewEntity() == null) return false;
frustum.setCameraPosition(mc.getRenderManager().info.getProjectedView().x, mc.getRenderManager().info.getProjectedView().y, mc.getRenderManager().info.getProjectedView().z);
return frustum.isBoundingBoxInFrustum(ent.getBoundingBox()) || ent.ignoreFrustumCheck;
    }

private float getLimbSwingAmount(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("limbSwingAmount");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }

private float getPrevLimbSwingAmount(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("prevLimbSwingAmount");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }

private float getLimbSwing(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("limbSwing");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }
}
 

Вложения

  • 1766521420716.png
    1766521420716.png
    236.1 KB · Просмотры: 184
Java:
Expand Collapse Copy
package im.babka.functions.impl.render;

import com.google.common.eventbus.Subscribe;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import im.babka.command.friends.FriendStorage;
import im.babka.events.EventDisplay;
import im.babka.functions.api.Category;
import im.babka.functions.api.Function;
import im.babka.functions.api.FunctionRegister;
import im.babka.functions.settings.impl.ColorSetting;
import im.babka.utils.math.MathUtil;
import im.babka.utils.projections.ProjectionUtil;
import im.babka.utils.render.ColorUtils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.math.vector.Vector3d;
import org.lwjgl.opengl.GL11;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import static net.minecraft.client.renderer.WorldRenderer.frustum;

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

public ColorSetting color = new ColorSetting("Color", ColorUtils.rgb(255, 255, 255));

public SkeletonEsp() {
addSettings(color);
    }

private final HashMap<PlayerEntity, Vector3d[]> pointsMap = new HashMap<>();

@Subscribe
    public void onDisplay(EventDisplay e) {
if (mc.world == null || e.getType() != EventDisplay.Type.PRE) return;

pointsMap.clear();

float partial = e.getPartialTicks();

for (PlayerEntity player : mc.world.getPlayers()) {
if (player == mc.player) continue;
if (!player.isAlive()) continue;
if (!isInView(player)) continue;

            Vector3d[] pts = calcPoints(player, partial);
if (pts != null) pointsMap.put(player, pts);
        }

        renderSkeletons(e.getMatrixStack());
    }

private Vector3d[] calcPoints(PlayerEntity p, float partial) {
double x = MathUtil.interpolate(p.getPosX(), p.lastTickPosX, partial);
double y = MathUtil.interpolate(p.getPosY(), p.lastTickPosY, partial);
double z = MathUtil.interpolate(p.getPosZ(), p.lastTickPosZ, partial);

        AxisAlignedBB bb = p.getBoundingBox();
double width = bb.maxX - bb.minX;
double height = bb.maxY - bb.minY;

double centerX = x;
double baseY = y;
double centerZ = z;

double headY = baseY + p.getEyeHeight();
double shoulderY = baseY + 1.35;
double hipY = baseY + 0.75;

float yaw = (p.prevRotationYaw + (p.rotationYaw - p.prevRotationYaw) * partial);

double yawRad = Math.toRadians(yaw);
double sinYaw = Math.sin(yawRad);
double cosYaw = Math.cos(yawRad);

double forwardX = -sinYaw;
double forwardZ = cosYaw;

float prevSwingAmount = getPrevLimbSwingAmount(p);
float swingAmount = getLimbSwingAmount(p);
float interpolatedSwingAmount = prevSwingAmount + (swingAmount - prevSwingAmount) * partial;

float limbSwingPos = getLimbSwing(p) + partial;

double armOffset = 0.375;
double legOffset = 0.125;
double armLength = 0.75;
double legLength = 0.75;

Vector3d head = new Vector3d(centerX, headY, centerZ);
Vector3d body = new Vector3d(centerX, shoulderY, centerZ);
Vector3d hip = new Vector3d(centerX, hipY, centerZ);

double leftShoulderX = centerX + (armOffset * cosYaw);
double leftShoulderZ = centerZ + (armOffset * sinYaw);
Vector3d leftShoulder = new Vector3d(leftShoulderX, shoulderY, leftShoulderZ);

double rightShoulderX = centerX - (armOffset * cosYaw);
double rightShoulderZ = centerZ - (armOffset * sinYaw);
Vector3d rightShoulder = new Vector3d(rightShoulderX, shoulderY, rightShoulderZ);

float leftArmXRot = MathHelper.cos(limbSwingPos * 0.6662F) * 2.0F * interpolatedSwingAmount * 0.5F;
double leftCosRot = Math.cos(leftArmXRot);
double leftSinRot = Math.sin(leftArmXRot);
double leftRelY = -armLength * leftCosRot;
double leftRelF = armLength * leftSinRot;
        Vector3d leftHand = leftShoulder.add(forwardX * leftRelF, leftRelY, forwardZ * leftRelF);

float rightArmXRot = MathHelper.cos(limbSwingPos * 0.6662F + (float) Math.PI) * 2.0F * interpolatedSwingAmount * 0.5F;
double rightCosRot = Math.cos(rightArmXRot);
double rightSinRot = Math.sin(rightArmXRot);
double rightRelY = -armLength * rightCosRot;
double rightRelF = armLength * rightSinRot;
        Vector3d rightHand = rightShoulder.add(forwardX * rightRelF, rightRelY, forwardZ * rightRelF);

double leftHipX = centerX + (legOffset * cosYaw);
double leftHipZ = centerZ + (legOffset * sinYaw);
Vector3d leftHip = new Vector3d(leftHipX, hipY, leftHipZ);

double rightHipX = centerX - (legOffset * cosYaw);
double rightHipZ = centerZ - (legOffset * sinYaw);
Vector3d rightHip = new Vector3d(rightHipX, hipY, rightHipZ);

float leftLegXRot = MathHelper.cos(limbSwingPos * 0.6662F + (float) Math.PI) * 1.4F * interpolatedSwingAmount * 0.5F;
double leftLegCosRot = Math.cos(leftLegXRot);
double leftLegSinRot = Math.sin(leftLegXRot);
double leftLegRelY = -legLength * leftLegCosRot;
double leftLegRelF = legLength * leftLegSinRot;
        Vector3d leftFoot = leftHip.add(forwardX * leftLegRelF, leftLegRelY, forwardZ * leftLegRelF);

float rightLegXRot = MathHelper.cos(limbSwingPos * 0.6662F) * 1.4F * interpolatedSwingAmount * 0.5F;
double rightLegCosRot = Math.cos(rightLegXRot);
double rightLegSinRot = Math.sin(rightLegXRot);
double rightLegRelY = -legLength * rightLegCosRot;
double rightLegRelF = legLength * rightLegSinRot;
        Vector3d rightFoot = rightHip.add(forwardX * rightLegRelF, rightLegRelY, forwardZ * rightLegRelF);

return new Vector3d[]{head, body, hip, leftShoulder, rightShoulder, leftHip, rightHip, leftHand, rightHand, leftFoot, rightFoot};
    }

private void renderSkeletons(MatrixStack matrixStack) {
RenderSystem.disableTexture();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();

GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glLineWidth(1.5f);

int clr = 0xFFFFFFFF;
try {
clr = color.get();
} catch (Exception ignored) {}

for (Map.Entry<PlayerEntity, Vector3d[]> e : pointsMap.entrySet()) {
            PlayerEntity p = e.getKey();
            Vector3d[] pts = e.getValue();

int useColor = FriendStorage.isFriend(p.getName().getString()) ? ColorUtils.rgb(144,238,144) : clr;

Vector2f head2 = ProjectionUtil.project(pts[0].x, pts[0].y, pts[0].z);
Vector2f body2 = ProjectionUtil.project(pts[1].x, pts[1].y, pts[1].z);
Vector2f hip2 = ProjectionUtil.project(pts[2].x, pts[2].y, pts[2].z);
Vector2f leftShoulder2 = ProjectionUtil.project(pts[3].x, pts[3].y, pts[3].z);
Vector2f rightShoulder2 = ProjectionUtil.project(pts[4].x, pts[4].y, pts[4].z);
Vector2f leftHip2 = ProjectionUtil.project(pts[5].x, pts[5].y, pts[5].z);
Vector2f rightHip2 = ProjectionUtil.project(pts[6].x, pts[6].y, pts[6].z);
Vector2f leftHand2 = ProjectionUtil.project(pts[7].x, pts[7].y, pts[7].z);
Vector2f rightHand2 = ProjectionUtil.project(pts[8].x, pts[8].y, pts[8].z);
Vector2f leftFoot2 = ProjectionUtil.project(pts[9].x, pts[9].y, pts[9].z);
Vector2f rightFoot2 = ProjectionUtil.project(pts[10].x, pts[10].y, pts[10].z);

if (isInvalid(head2) || isInvalid(body2) || isInvalid(hip2) || isInvalid(leftShoulder2) || isInvalid(rightShoulder2) || isInvalid(leftHip2) || isInvalid(rightHip2) || isInvalid(leftHand2) || isInvalid(rightHand2) || isInvalid(leftFoot2) || isInvalid(rightFoot2))
continue;

            AxisAlignedBB bb = p.getBoundingBox();
double height = bb.maxY - bb.minY;
double headSize = height / 32.0 * 8.0;
double headHalf = headSize / 2;
AxisAlignedBB headBB = new AxisAlignedBB(bb.minX + (bb.maxX - bb.minX) / 2 - headHalf, bb.maxY - headSize, bb.minZ + (bb.maxZ - bb.minZ) / 2 - headHalf,
bb.minX + (bb.maxX - bb.minX) / 2 + headHalf, bb.maxY, bb.minZ + (bb.maxZ - bb.minZ) / 2 + headHalf);

Vector3d[] corners = new Vector3d[]{
new Vector3d(headBB.minX, headBB.minY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.minY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.minY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.minY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.maxY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.maxY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.maxY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.maxY, headBB.maxZ)
            };

float left = Float.MAX_VALUE;
float right = Float.MIN_VALUE;
float top = Float.MAX_VALUE;
float bottom = Float.MIN_VALUE;

boolean valid = true;
for (Vector3d corner : corners) {
Vector2f proj = ProjectionUtil.project(corner.x, corner.y, corner.z);
if (isInvalid(proj)) {
valid = false;
break;
                }
left = Math.min(left, proj.x);
right = Math.max(right, proj.x);
top = Math.min(top, proj.y);
bottom = Math.max(bottom, proj.y);
            }

if (!valid) continue;

GL11.glBegin(GL11.GL_LINES);
            setGLColor(useColor);

GL11.glVertex2f(head2.x, head2.y);
GL11.glVertex2f(body2.x, body2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(hip2.x, hip2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(leftShoulder2.x, leftShoulder2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(rightShoulder2.x, rightShoulder2.y);

GL11.glVertex2f(hip2.x, hip2.y);
GL11.glVertex2f(leftHip2.x, leftHip2.y);

GL11.glVertex2f(hip2.x, hip2.y);
GL11.glVertex2f(rightHip2.x, rightHip2.y);

GL11.glVertex2f(leftShoulder2.x, leftShoulder2.y);
GL11.glVertex2f(leftHand2.x, leftHand2.y);

GL11.glVertex2f(rightShoulder2.x, rightShoulder2.y);
GL11.glVertex2f(rightHand2.x, rightHand2.y);

GL11.glVertex2f(leftHip2.x, leftHip2.y);
GL11.glVertex2f(leftFoot2.x, leftFoot2.y);

GL11.glVertex2f(rightHip2.x, rightHip2.y);
GL11.glVertex2f(rightFoot2.x, rightFoot2.y);

GL11.glVertex2f(left, top);
GL11.glVertex2f(right, top);

GL11.glVertex2f(right, top);
GL11.glVertex2f(right, bottom);

GL11.glVertex2f(right, bottom);
GL11.glVertex2f(left, bottom);

GL11.glVertex2f(left, bottom);
GL11.glVertex2f(left, top);

GL11.glEnd();
        }

GL11.glPopAttrib();

RenderSystem.disableBlend();
RenderSystem.enableTexture();
    }

private boolean isInvalid(Vector2f v) {
if (v == null) return true;
return Float.isNaN(v.x) || Float.isNaN(v.y) || v.x == Float.NEGATIVE_INFINITY || v.y == Float.NEGATIVE_INFINITY;
    }

private void setGLColor(int c) {
float a = ((c >> 24) & 0xFF) / 255f;
float r = ((c >> 16) & 0xFF) / 255f;
float g = ((c >> 8) & 0xFF) / 255f;
float b = (c & 0xFF) / 255f;
GL11.glColor4f(r, g, b, a == 0f ? 1f : a);
    }

public boolean isInView(net.minecraft.entity.Entity ent) {
if (mc.getRenderViewEntity() == null) return false;
frustum.setCameraPosition(mc.getRenderManager().info.getProjectedView().x, mc.getRenderManager().info.getProjectedView().y, mc.getRenderManager().info.getProjectedView().z);
return frustum.isBoundingBoxInFrustum(ent.getBoundingBox()) || ent.ignoreFrustumCheck;
    }

private float getLimbSwingAmount(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("limbSwingAmount");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }

private float getPrevLimbSwingAmount(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("prevLimbSwingAmount");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }

private float getLimbSwing(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("limbSwing");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }
}
ну ета абаюдна
 
Java:
Expand Collapse Copy
package im.babka.functions.impl.render;

import com.google.common.eventbus.Subscribe;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import im.babka.command.friends.FriendStorage;
import im.babka.events.EventDisplay;
import im.babka.functions.api.Category;
import im.babka.functions.api.Function;
import im.babka.functions.api.FunctionRegister;
import im.babka.functions.settings.impl.ColorSetting;
import im.babka.utils.math.MathUtil;
import im.babka.utils.projections.ProjectionUtil;
import im.babka.utils.render.ColorUtils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.math.vector.Vector3d;
import org.lwjgl.opengl.GL11;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import static net.minecraft.client.renderer.WorldRenderer.frustum;

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

public ColorSetting color = new ColorSetting("Color", ColorUtils.rgb(255, 255, 255));

public SkeletonEsp() {
addSettings(color);
    }

private final HashMap<PlayerEntity, Vector3d[]> pointsMap = new HashMap<>();

@Subscribe
    public void onDisplay(EventDisplay e) {
if (mc.world == null || e.getType() != EventDisplay.Type.PRE) return;

pointsMap.clear();

float partial = e.getPartialTicks();

for (PlayerEntity player : mc.world.getPlayers()) {
if (player == mc.player) continue;
if (!player.isAlive()) continue;
if (!isInView(player)) continue;

            Vector3d[] pts = calcPoints(player, partial);
if (pts != null) pointsMap.put(player, pts);
        }

        renderSkeletons(e.getMatrixStack());
    }

private Vector3d[] calcPoints(PlayerEntity p, float partial) {
double x = MathUtil.interpolate(p.getPosX(), p.lastTickPosX, partial);
double y = MathUtil.interpolate(p.getPosY(), p.lastTickPosY, partial);
double z = MathUtil.interpolate(p.getPosZ(), p.lastTickPosZ, partial);

        AxisAlignedBB bb = p.getBoundingBox();
double width = bb.maxX - bb.minX;
double height = bb.maxY - bb.minY;

double centerX = x;
double baseY = y;
double centerZ = z;

double headY = baseY + p.getEyeHeight();
double shoulderY = baseY + 1.35;
double hipY = baseY + 0.75;

float yaw = (p.prevRotationYaw + (p.rotationYaw - p.prevRotationYaw) * partial);

double yawRad = Math.toRadians(yaw);
double sinYaw = Math.sin(yawRad);
double cosYaw = Math.cos(yawRad);

double forwardX = -sinYaw;
double forwardZ = cosYaw;

float prevSwingAmount = getPrevLimbSwingAmount(p);
float swingAmount = getLimbSwingAmount(p);
float interpolatedSwingAmount = prevSwingAmount + (swingAmount - prevSwingAmount) * partial;

float limbSwingPos = getLimbSwing(p) + partial;

double armOffset = 0.375;
double legOffset = 0.125;
double armLength = 0.75;
double legLength = 0.75;

Vector3d head = new Vector3d(centerX, headY, centerZ);
Vector3d body = new Vector3d(centerX, shoulderY, centerZ);
Vector3d hip = new Vector3d(centerX, hipY, centerZ);

double leftShoulderX = centerX + (armOffset * cosYaw);
double leftShoulderZ = centerZ + (armOffset * sinYaw);
Vector3d leftShoulder = new Vector3d(leftShoulderX, shoulderY, leftShoulderZ);

double rightShoulderX = centerX - (armOffset * cosYaw);
double rightShoulderZ = centerZ - (armOffset * sinYaw);
Vector3d rightShoulder = new Vector3d(rightShoulderX, shoulderY, rightShoulderZ);

float leftArmXRot = MathHelper.cos(limbSwingPos * 0.6662F) * 2.0F * interpolatedSwingAmount * 0.5F;
double leftCosRot = Math.cos(leftArmXRot);
double leftSinRot = Math.sin(leftArmXRot);
double leftRelY = -armLength * leftCosRot;
double leftRelF = armLength * leftSinRot;
        Vector3d leftHand = leftShoulder.add(forwardX * leftRelF, leftRelY, forwardZ * leftRelF);

float rightArmXRot = MathHelper.cos(limbSwingPos * 0.6662F + (float) Math.PI) * 2.0F * interpolatedSwingAmount * 0.5F;
double rightCosRot = Math.cos(rightArmXRot);
double rightSinRot = Math.sin(rightArmXRot);
double rightRelY = -armLength * rightCosRot;
double rightRelF = armLength * rightSinRot;
        Vector3d rightHand = rightShoulder.add(forwardX * rightRelF, rightRelY, forwardZ * rightRelF);

double leftHipX = centerX + (legOffset * cosYaw);
double leftHipZ = centerZ + (legOffset * sinYaw);
Vector3d leftHip = new Vector3d(leftHipX, hipY, leftHipZ);

double rightHipX = centerX - (legOffset * cosYaw);
double rightHipZ = centerZ - (legOffset * sinYaw);
Vector3d rightHip = new Vector3d(rightHipX, hipY, rightHipZ);

float leftLegXRot = MathHelper.cos(limbSwingPos * 0.6662F + (float) Math.PI) * 1.4F * interpolatedSwingAmount * 0.5F;
double leftLegCosRot = Math.cos(leftLegXRot);
double leftLegSinRot = Math.sin(leftLegXRot);
double leftLegRelY = -legLength * leftLegCosRot;
double leftLegRelF = legLength * leftLegSinRot;
        Vector3d leftFoot = leftHip.add(forwardX * leftLegRelF, leftLegRelY, forwardZ * leftLegRelF);

float rightLegXRot = MathHelper.cos(limbSwingPos * 0.6662F) * 1.4F * interpolatedSwingAmount * 0.5F;
double rightLegCosRot = Math.cos(rightLegXRot);
double rightLegSinRot = Math.sin(rightLegXRot);
double rightLegRelY = -legLength * rightLegCosRot;
double rightLegRelF = legLength * rightLegSinRot;
        Vector3d rightFoot = rightHip.add(forwardX * rightLegRelF, rightLegRelY, forwardZ * rightLegRelF);

return new Vector3d[]{head, body, hip, leftShoulder, rightShoulder, leftHip, rightHip, leftHand, rightHand, leftFoot, rightFoot};
    }

private void renderSkeletons(MatrixStack matrixStack) {
RenderSystem.disableTexture();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();

GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glLineWidth(1.5f);

int clr = 0xFFFFFFFF;
try {
clr = color.get();
} catch (Exception ignored) {}

for (Map.Entry<PlayerEntity, Vector3d[]> e : pointsMap.entrySet()) {
            PlayerEntity p = e.getKey();
            Vector3d[] pts = e.getValue();

int useColor = FriendStorage.isFriend(p.getName().getString()) ? ColorUtils.rgb(144,238,144) : clr;

Vector2f head2 = ProjectionUtil.project(pts[0].x, pts[0].y, pts[0].z);
Vector2f body2 = ProjectionUtil.project(pts[1].x, pts[1].y, pts[1].z);
Vector2f hip2 = ProjectionUtil.project(pts[2].x, pts[2].y, pts[2].z);
Vector2f leftShoulder2 = ProjectionUtil.project(pts[3].x, pts[3].y, pts[3].z);
Vector2f rightShoulder2 = ProjectionUtil.project(pts[4].x, pts[4].y, pts[4].z);
Vector2f leftHip2 = ProjectionUtil.project(pts[5].x, pts[5].y, pts[5].z);
Vector2f rightHip2 = ProjectionUtil.project(pts[6].x, pts[6].y, pts[6].z);
Vector2f leftHand2 = ProjectionUtil.project(pts[7].x, pts[7].y, pts[7].z);
Vector2f rightHand2 = ProjectionUtil.project(pts[8].x, pts[8].y, pts[8].z);
Vector2f leftFoot2 = ProjectionUtil.project(pts[9].x, pts[9].y, pts[9].z);
Vector2f rightFoot2 = ProjectionUtil.project(pts[10].x, pts[10].y, pts[10].z);

if (isInvalid(head2) || isInvalid(body2) || isInvalid(hip2) || isInvalid(leftShoulder2) || isInvalid(rightShoulder2) || isInvalid(leftHip2) || isInvalid(rightHip2) || isInvalid(leftHand2) || isInvalid(rightHand2) || isInvalid(leftFoot2) || isInvalid(rightFoot2))
continue;

            AxisAlignedBB bb = p.getBoundingBox();
double height = bb.maxY - bb.minY;
double headSize = height / 32.0 * 8.0;
double headHalf = headSize / 2;
AxisAlignedBB headBB = new AxisAlignedBB(bb.minX + (bb.maxX - bb.minX) / 2 - headHalf, bb.maxY - headSize, bb.minZ + (bb.maxZ - bb.minZ) / 2 - headHalf,
bb.minX + (bb.maxX - bb.minX) / 2 + headHalf, bb.maxY, bb.minZ + (bb.maxZ - bb.minZ) / 2 + headHalf);

Vector3d[] corners = new Vector3d[]{
new Vector3d(headBB.minX, headBB.minY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.minY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.minY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.minY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.maxY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.maxY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.maxY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.maxY, headBB.maxZ)
            };

float left = Float.MAX_VALUE;
float right = Float.MIN_VALUE;
float top = Float.MAX_VALUE;
float bottom = Float.MIN_VALUE;

boolean valid = true;
for (Vector3d corner : corners) {
Vector2f proj = ProjectionUtil.project(corner.x, corner.y, corner.z);
if (isInvalid(proj)) {
valid = false;
break;
                }
left = Math.min(left, proj.x);
right = Math.max(right, proj.x);
top = Math.min(top, proj.y);
bottom = Math.max(bottom, proj.y);
            }

if (!valid) continue;

GL11.glBegin(GL11.GL_LINES);
            setGLColor(useColor);

GL11.glVertex2f(head2.x, head2.y);
GL11.glVertex2f(body2.x, body2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(hip2.x, hip2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(leftShoulder2.x, leftShoulder2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(rightShoulder2.x, rightShoulder2.y);

GL11.glVertex2f(hip2.x, hip2.y);
GL11.glVertex2f(leftHip2.x, leftHip2.y);

GL11.glVertex2f(hip2.x, hip2.y);
GL11.glVertex2f(rightHip2.x, rightHip2.y);

GL11.glVertex2f(leftShoulder2.x, leftShoulder2.y);
GL11.glVertex2f(leftHand2.x, leftHand2.y);

GL11.glVertex2f(rightShoulder2.x, rightShoulder2.y);
GL11.glVertex2f(rightHand2.x, rightHand2.y);

GL11.glVertex2f(leftHip2.x, leftHip2.y);
GL11.glVertex2f(leftFoot2.x, leftFoot2.y);

GL11.glVertex2f(rightHip2.x, rightHip2.y);
GL11.glVertex2f(rightFoot2.x, rightFoot2.y);

GL11.glVertex2f(left, top);
GL11.glVertex2f(right, top);

GL11.glVertex2f(right, top);
GL11.glVertex2f(right, bottom);

GL11.glVertex2f(right, bottom);
GL11.glVertex2f(left, bottom);

GL11.glVertex2f(left, bottom);
GL11.glVertex2f(left, top);

GL11.glEnd();
        }

GL11.glPopAttrib();

RenderSystem.disableBlend();
RenderSystem.enableTexture();
    }

private boolean isInvalid(Vector2f v) {
if (v == null) return true;
return Float.isNaN(v.x) || Float.isNaN(v.y) || v.x == Float.NEGATIVE_INFINITY || v.y == Float.NEGATIVE_INFINITY;
    }

private void setGLColor(int c) {
float a = ((c >> 24) & 0xFF) / 255f;
float r = ((c >> 16) & 0xFF) / 255f;
float g = ((c >> 8) & 0xFF) / 255f;
float b = (c & 0xFF) / 255f;
GL11.glColor4f(r, g, b, a == 0f ? 1f : a);
    }

public boolean isInView(net.minecraft.entity.Entity ent) {
if (mc.getRenderViewEntity() == null) return false;
frustum.setCameraPosition(mc.getRenderManager().info.getProjectedView().x, mc.getRenderManager().info.getProjectedView().y, mc.getRenderManager().info.getProjectedView().z);
return frustum.isBoundingBoxInFrustum(ent.getBoundingBox()) || ent.ignoreFrustumCheck;
    }

private float getLimbSwingAmount(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("limbSwingAmount");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }

private float getPrevLimbSwingAmount(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("prevLimbSwingAmount");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }

private float getLimbSwing(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("limbSwing");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }
}
/del мусор
 
Java:
Expand Collapse Copy
package im.babka.functions.impl.render;

import com.google.common.eventbus.Subscribe;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import im.babka.command.friends.FriendStorage;
import im.babka.events.EventDisplay;
import im.babka.functions.api.Category;
import im.babka.functions.api.Function;
import im.babka.functions.api.FunctionRegister;
import im.babka.functions.settings.impl.ColorSetting;
import im.babka.utils.math.MathUtil;
import im.babka.utils.projections.ProjectionUtil;
import im.babka.utils.render.ColorUtils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.math.vector.Vector3d;
import org.lwjgl.opengl.GL11;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import static net.minecraft.client.renderer.WorldRenderer.frustum;

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

public ColorSetting color = new ColorSetting("Color", ColorUtils.rgb(255, 255, 255));

public SkeletonEsp() {
addSettings(color);
    }

private final HashMap<PlayerEntity, Vector3d[]> pointsMap = new HashMap<>();

@Subscribe
    public void onDisplay(EventDisplay e) {
if (mc.world == null || e.getType() != EventDisplay.Type.PRE) return;

pointsMap.clear();

float partial = e.getPartialTicks();

for (PlayerEntity player : mc.world.getPlayers()) {
if (player == mc.player) continue;
if (!player.isAlive()) continue;
if (!isInView(player)) continue;

            Vector3d[] pts = calcPoints(player, partial);
if (pts != null) pointsMap.put(player, pts);
        }

        renderSkeletons(e.getMatrixStack());
    }

private Vector3d[] calcPoints(PlayerEntity p, float partial) {
double x = MathUtil.interpolate(p.getPosX(), p.lastTickPosX, partial);
double y = MathUtil.interpolate(p.getPosY(), p.lastTickPosY, partial);
double z = MathUtil.interpolate(p.getPosZ(), p.lastTickPosZ, partial);

        AxisAlignedBB bb = p.getBoundingBox();
double width = bb.maxX - bb.minX;
double height = bb.maxY - bb.minY;

double centerX = x;
double baseY = y;
double centerZ = z;

double headY = baseY + p.getEyeHeight();
double shoulderY = baseY + 1.35;
double hipY = baseY + 0.75;

float yaw = (p.prevRotationYaw + (p.rotationYaw - p.prevRotationYaw) * partial);

double yawRad = Math.toRadians(yaw);
double sinYaw = Math.sin(yawRad);
double cosYaw = Math.cos(yawRad);

double forwardX = -sinYaw;
double forwardZ = cosYaw;

float prevSwingAmount = getPrevLimbSwingAmount(p);
float swingAmount = getLimbSwingAmount(p);
float interpolatedSwingAmount = prevSwingAmount + (swingAmount - prevSwingAmount) * partial;

float limbSwingPos = getLimbSwing(p) + partial;

double armOffset = 0.375;
double legOffset = 0.125;
double armLength = 0.75;
double legLength = 0.75;

Vector3d head = new Vector3d(centerX, headY, centerZ);
Vector3d body = new Vector3d(centerX, shoulderY, centerZ);
Vector3d hip = new Vector3d(centerX, hipY, centerZ);

double leftShoulderX = centerX + (armOffset * cosYaw);
double leftShoulderZ = centerZ + (armOffset * sinYaw);
Vector3d leftShoulder = new Vector3d(leftShoulderX, shoulderY, leftShoulderZ);

double rightShoulderX = centerX - (armOffset * cosYaw);
double rightShoulderZ = centerZ - (armOffset * sinYaw);
Vector3d rightShoulder = new Vector3d(rightShoulderX, shoulderY, rightShoulderZ);

float leftArmXRot = MathHelper.cos(limbSwingPos * 0.6662F) * 2.0F * interpolatedSwingAmount * 0.5F;
double leftCosRot = Math.cos(leftArmXRot);
double leftSinRot = Math.sin(leftArmXRot);
double leftRelY = -armLength * leftCosRot;
double leftRelF = armLength * leftSinRot;
        Vector3d leftHand = leftShoulder.add(forwardX * leftRelF, leftRelY, forwardZ * leftRelF);

float rightArmXRot = MathHelper.cos(limbSwingPos * 0.6662F + (float) Math.PI) * 2.0F * interpolatedSwingAmount * 0.5F;
double rightCosRot = Math.cos(rightArmXRot);
double rightSinRot = Math.sin(rightArmXRot);
double rightRelY = -armLength * rightCosRot;
double rightRelF = armLength * rightSinRot;
        Vector3d rightHand = rightShoulder.add(forwardX * rightRelF, rightRelY, forwardZ * rightRelF);

double leftHipX = centerX + (legOffset * cosYaw);
double leftHipZ = centerZ + (legOffset * sinYaw);
Vector3d leftHip = new Vector3d(leftHipX, hipY, leftHipZ);

double rightHipX = centerX - (legOffset * cosYaw);
double rightHipZ = centerZ - (legOffset * sinYaw);
Vector3d rightHip = new Vector3d(rightHipX, hipY, rightHipZ);

float leftLegXRot = MathHelper.cos(limbSwingPos * 0.6662F + (float) Math.PI) * 1.4F * interpolatedSwingAmount * 0.5F;
double leftLegCosRot = Math.cos(leftLegXRot);
double leftLegSinRot = Math.sin(leftLegXRot);
double leftLegRelY = -legLength * leftLegCosRot;
double leftLegRelF = legLength * leftLegSinRot;
        Vector3d leftFoot = leftHip.add(forwardX * leftLegRelF, leftLegRelY, forwardZ * leftLegRelF);

float rightLegXRot = MathHelper.cos(limbSwingPos * 0.6662F) * 1.4F * interpolatedSwingAmount * 0.5F;
double rightLegCosRot = Math.cos(rightLegXRot);
double rightLegSinRot = Math.sin(rightLegXRot);
double rightLegRelY = -legLength * rightLegCosRot;
double rightLegRelF = legLength * rightLegSinRot;
        Vector3d rightFoot = rightHip.add(forwardX * rightLegRelF, rightLegRelY, forwardZ * rightLegRelF);

return new Vector3d[]{head, body, hip, leftShoulder, rightShoulder, leftHip, rightHip, leftHand, rightHand, leftFoot, rightFoot};
    }

private void renderSkeletons(MatrixStack matrixStack) {
RenderSystem.disableTexture();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();

GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glLineWidth(1.5f);

int clr = 0xFFFFFFFF;
try {
clr = color.get();
} catch (Exception ignored) {}

for (Map.Entry<PlayerEntity, Vector3d[]> e : pointsMap.entrySet()) {
            PlayerEntity p = e.getKey();
            Vector3d[] pts = e.getValue();

int useColor = FriendStorage.isFriend(p.getName().getString()) ? ColorUtils.rgb(144,238,144) : clr;

Vector2f head2 = ProjectionUtil.project(pts[0].x, pts[0].y, pts[0].z);
Vector2f body2 = ProjectionUtil.project(pts[1].x, pts[1].y, pts[1].z);
Vector2f hip2 = ProjectionUtil.project(pts[2].x, pts[2].y, pts[2].z);
Vector2f leftShoulder2 = ProjectionUtil.project(pts[3].x, pts[3].y, pts[3].z);
Vector2f rightShoulder2 = ProjectionUtil.project(pts[4].x, pts[4].y, pts[4].z);
Vector2f leftHip2 = ProjectionUtil.project(pts[5].x, pts[5].y, pts[5].z);
Vector2f rightHip2 = ProjectionUtil.project(pts[6].x, pts[6].y, pts[6].z);
Vector2f leftHand2 = ProjectionUtil.project(pts[7].x, pts[7].y, pts[7].z);
Vector2f rightHand2 = ProjectionUtil.project(pts[8].x, pts[8].y, pts[8].z);
Vector2f leftFoot2 = ProjectionUtil.project(pts[9].x, pts[9].y, pts[9].z);
Vector2f rightFoot2 = ProjectionUtil.project(pts[10].x, pts[10].y, pts[10].z);

if (isInvalid(head2) || isInvalid(body2) || isInvalid(hip2) || isInvalid(leftShoulder2) || isInvalid(rightShoulder2) || isInvalid(leftHip2) || isInvalid(rightHip2) || isInvalid(leftHand2) || isInvalid(rightHand2) || isInvalid(leftFoot2) || isInvalid(rightFoot2))
continue;

            AxisAlignedBB bb = p.getBoundingBox();
double height = bb.maxY - bb.minY;
double headSize = height / 32.0 * 8.0;
double headHalf = headSize / 2;
AxisAlignedBB headBB = new AxisAlignedBB(bb.minX + (bb.maxX - bb.minX) / 2 - headHalf, bb.maxY - headSize, bb.minZ + (bb.maxZ - bb.minZ) / 2 - headHalf,
bb.minX + (bb.maxX - bb.minX) / 2 + headHalf, bb.maxY, bb.minZ + (bb.maxZ - bb.minZ) / 2 + headHalf);

Vector3d[] corners = new Vector3d[]{
new Vector3d(headBB.minX, headBB.minY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.minY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.minY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.minY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.maxY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.maxY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.maxY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.maxY, headBB.maxZ)
            };

float left = Float.MAX_VALUE;
float right = Float.MIN_VALUE;
float top = Float.MAX_VALUE;
float bottom = Float.MIN_VALUE;

boolean valid = true;
for (Vector3d corner : corners) {
Vector2f proj = ProjectionUtil.project(corner.x, corner.y, corner.z);
if (isInvalid(proj)) {
valid = false;
break;
                }
left = Math.min(left, proj.x);
right = Math.max(right, proj.x);
top = Math.min(top, proj.y);
bottom = Math.max(bottom, proj.y);
            }

if (!valid) continue;

GL11.glBegin(GL11.GL_LINES);
            setGLColor(useColor);

GL11.glVertex2f(head2.x, head2.y);
GL11.glVertex2f(body2.x, body2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(hip2.x, hip2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(leftShoulder2.x, leftShoulder2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(rightShoulder2.x, rightShoulder2.y);

GL11.glVertex2f(hip2.x, hip2.y);
GL11.glVertex2f(leftHip2.x, leftHip2.y);

GL11.glVertex2f(hip2.x, hip2.y);
GL11.glVertex2f(rightHip2.x, rightHip2.y);

GL11.glVertex2f(leftShoulder2.x, leftShoulder2.y);
GL11.glVertex2f(leftHand2.x, leftHand2.y);

GL11.glVertex2f(rightShoulder2.x, rightShoulder2.y);
GL11.glVertex2f(rightHand2.x, rightHand2.y);

GL11.glVertex2f(leftHip2.x, leftHip2.y);
GL11.glVertex2f(leftFoot2.x, leftFoot2.y);

GL11.glVertex2f(rightHip2.x, rightHip2.y);
GL11.glVertex2f(rightFoot2.x, rightFoot2.y);

GL11.glVertex2f(left, top);
GL11.glVertex2f(right, top);

GL11.glVertex2f(right, top);
GL11.glVertex2f(right, bottom);

GL11.glVertex2f(right, bottom);
GL11.glVertex2f(left, bottom);

GL11.glVertex2f(left, bottom);
GL11.glVertex2f(left, top);

GL11.glEnd();
        }

GL11.glPopAttrib();

RenderSystem.disableBlend();
RenderSystem.enableTexture();
    }

private boolean isInvalid(Vector2f v) {
if (v == null) return true;
return Float.isNaN(v.x) || Float.isNaN(v.y) || v.x == Float.NEGATIVE_INFINITY || v.y == Float.NEGATIVE_INFINITY;
    }

private void setGLColor(int c) {
float a = ((c >> 24) & 0xFF) / 255f;
float r = ((c >> 16) & 0xFF) / 255f;
float g = ((c >> 8) & 0xFF) / 255f;
float b = (c & 0xFF) / 255f;
GL11.glColor4f(r, g, b, a == 0f ? 1f : a);
    }

public boolean isInView(net.minecraft.entity.Entity ent) {
if (mc.getRenderViewEntity() == null) return false;
frustum.setCameraPosition(mc.getRenderManager().info.getProjectedView().x, mc.getRenderManager().info.getProjectedView().y, mc.getRenderManager().info.getProjectedView().z);
return frustum.isBoundingBoxInFrustum(ent.getBoundingBox()) || ent.ignoreFrustumCheck;
    }

private float getLimbSwingAmount(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("limbSwingAmount");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }

private float getPrevLimbSwingAmount(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("prevLimbSwingAmount");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }

private float getLimbSwing(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("limbSwing");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }
}
/del убогие, в срц монотона лучше
 
Java:
Expand Collapse Copy
package im.babka.functions.impl.render;

import com.google.common.eventbus.Subscribe;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import im.babka.command.friends.FriendStorage;
import im.babka.events.EventDisplay;
import im.babka.functions.api.Category;
import im.babka.functions.api.Function;
import im.babka.functions.api.FunctionRegister;
import im.babka.functions.settings.impl.ColorSetting;
import im.babka.utils.math.MathUtil;
import im.babka.utils.projections.ProjectionUtil;
import im.babka.utils.render.ColorUtils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.math.vector.Vector3d;
import org.lwjgl.opengl.GL11;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import static net.minecraft.client.renderer.WorldRenderer.frustum;

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

public ColorSetting color = new ColorSetting("Color", ColorUtils.rgb(255, 255, 255));

public SkeletonEsp() {
addSettings(color);
    }

private final HashMap<PlayerEntity, Vector3d[]> pointsMap = new HashMap<>();

@Subscribe
    public void onDisplay(EventDisplay e) {
if (mc.world == null || e.getType() != EventDisplay.Type.PRE) return;

pointsMap.clear();

float partial = e.getPartialTicks();

for (PlayerEntity player : mc.world.getPlayers()) {
if (player == mc.player) continue;
if (!player.isAlive()) continue;
if (!isInView(player)) continue;

            Vector3d[] pts = calcPoints(player, partial);
if (pts != null) pointsMap.put(player, pts);
        }

        renderSkeletons(e.getMatrixStack());
    }

private Vector3d[] calcPoints(PlayerEntity p, float partial) {
double x = MathUtil.interpolate(p.getPosX(), p.lastTickPosX, partial);
double y = MathUtil.interpolate(p.getPosY(), p.lastTickPosY, partial);
double z = MathUtil.interpolate(p.getPosZ(), p.lastTickPosZ, partial);

        AxisAlignedBB bb = p.getBoundingBox();
double width = bb.maxX - bb.minX;
double height = bb.maxY - bb.minY;

double centerX = x;
double baseY = y;
double centerZ = z;

double headY = baseY + p.getEyeHeight();
double shoulderY = baseY + 1.35;
double hipY = baseY + 0.75;

float yaw = (p.prevRotationYaw + (p.rotationYaw - p.prevRotationYaw) * partial);

double yawRad = Math.toRadians(yaw);
double sinYaw = Math.sin(yawRad);
double cosYaw = Math.cos(yawRad);

double forwardX = -sinYaw;
double forwardZ = cosYaw;

float prevSwingAmount = getPrevLimbSwingAmount(p);
float swingAmount = getLimbSwingAmount(p);
float interpolatedSwingAmount = prevSwingAmount + (swingAmount - prevSwingAmount) * partial;

float limbSwingPos = getLimbSwing(p) + partial;

double armOffset = 0.375;
double legOffset = 0.125;
double armLength = 0.75;
double legLength = 0.75;

Vector3d head = new Vector3d(centerX, headY, centerZ);
Vector3d body = new Vector3d(centerX, shoulderY, centerZ);
Vector3d hip = new Vector3d(centerX, hipY, centerZ);

double leftShoulderX = centerX + (armOffset * cosYaw);
double leftShoulderZ = centerZ + (armOffset * sinYaw);
Vector3d leftShoulder = new Vector3d(leftShoulderX, shoulderY, leftShoulderZ);

double rightShoulderX = centerX - (armOffset * cosYaw);
double rightShoulderZ = centerZ - (armOffset * sinYaw);
Vector3d rightShoulder = new Vector3d(rightShoulderX, shoulderY, rightShoulderZ);

float leftArmXRot = MathHelper.cos(limbSwingPos * 0.6662F) * 2.0F * interpolatedSwingAmount * 0.5F;
double leftCosRot = Math.cos(leftArmXRot);
double leftSinRot = Math.sin(leftArmXRot);
double leftRelY = -armLength * leftCosRot;
double leftRelF = armLength * leftSinRot;
        Vector3d leftHand = leftShoulder.add(forwardX * leftRelF, leftRelY, forwardZ * leftRelF);

float rightArmXRot = MathHelper.cos(limbSwingPos * 0.6662F + (float) Math.PI) * 2.0F * interpolatedSwingAmount * 0.5F;
double rightCosRot = Math.cos(rightArmXRot);
double rightSinRot = Math.sin(rightArmXRot);
double rightRelY = -armLength * rightCosRot;
double rightRelF = armLength * rightSinRot;
        Vector3d rightHand = rightShoulder.add(forwardX * rightRelF, rightRelY, forwardZ * rightRelF);

double leftHipX = centerX + (legOffset * cosYaw);
double leftHipZ = centerZ + (legOffset * sinYaw);
Vector3d leftHip = new Vector3d(leftHipX, hipY, leftHipZ);

double rightHipX = centerX - (legOffset * cosYaw);
double rightHipZ = centerZ - (legOffset * sinYaw);
Vector3d rightHip = new Vector3d(rightHipX, hipY, rightHipZ);

float leftLegXRot = MathHelper.cos(limbSwingPos * 0.6662F + (float) Math.PI) * 1.4F * interpolatedSwingAmount * 0.5F;
double leftLegCosRot = Math.cos(leftLegXRot);
double leftLegSinRot = Math.sin(leftLegXRot);
double leftLegRelY = -legLength * leftLegCosRot;
double leftLegRelF = legLength * leftLegSinRot;
        Vector3d leftFoot = leftHip.add(forwardX * leftLegRelF, leftLegRelY, forwardZ * leftLegRelF);

float rightLegXRot = MathHelper.cos(limbSwingPos * 0.6662F) * 1.4F * interpolatedSwingAmount * 0.5F;
double rightLegCosRot = Math.cos(rightLegXRot);
double rightLegSinRot = Math.sin(rightLegXRot);
double rightLegRelY = -legLength * rightLegCosRot;
double rightLegRelF = legLength * rightLegSinRot;
        Vector3d rightFoot = rightHip.add(forwardX * rightLegRelF, rightLegRelY, forwardZ * rightLegRelF);

return new Vector3d[]{head, body, hip, leftShoulder, rightShoulder, leftHip, rightHip, leftHand, rightHand, leftFoot, rightFoot};
    }

private void renderSkeletons(MatrixStack matrixStack) {
RenderSystem.disableTexture();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();

GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glLineWidth(1.5f);

int clr = 0xFFFFFFFF;
try {
clr = color.get();
} catch (Exception ignored) {}

for (Map.Entry<PlayerEntity, Vector3d[]> e : pointsMap.entrySet()) {
            PlayerEntity p = e.getKey();
            Vector3d[] pts = e.getValue();

int useColor = FriendStorage.isFriend(p.getName().getString()) ? ColorUtils.rgb(144,238,144) : clr;

Vector2f head2 = ProjectionUtil.project(pts[0].x, pts[0].y, pts[0].z);
Vector2f body2 = ProjectionUtil.project(pts[1].x, pts[1].y, pts[1].z);
Vector2f hip2 = ProjectionUtil.project(pts[2].x, pts[2].y, pts[2].z);
Vector2f leftShoulder2 = ProjectionUtil.project(pts[3].x, pts[3].y, pts[3].z);
Vector2f rightShoulder2 = ProjectionUtil.project(pts[4].x, pts[4].y, pts[4].z);
Vector2f leftHip2 = ProjectionUtil.project(pts[5].x, pts[5].y, pts[5].z);
Vector2f rightHip2 = ProjectionUtil.project(pts[6].x, pts[6].y, pts[6].z);
Vector2f leftHand2 = ProjectionUtil.project(pts[7].x, pts[7].y, pts[7].z);
Vector2f rightHand2 = ProjectionUtil.project(pts[8].x, pts[8].y, pts[8].z);
Vector2f leftFoot2 = ProjectionUtil.project(pts[9].x, pts[9].y, pts[9].z);
Vector2f rightFoot2 = ProjectionUtil.project(pts[10].x, pts[10].y, pts[10].z);

if (isInvalid(head2) || isInvalid(body2) || isInvalid(hip2) || isInvalid(leftShoulder2) || isInvalid(rightShoulder2) || isInvalid(leftHip2) || isInvalid(rightHip2) || isInvalid(leftHand2) || isInvalid(rightHand2) || isInvalid(leftFoot2) || isInvalid(rightFoot2))
continue;

            AxisAlignedBB bb = p.getBoundingBox();
double height = bb.maxY - bb.minY;
double headSize = height / 32.0 * 8.0;
double headHalf = headSize / 2;
AxisAlignedBB headBB = new AxisAlignedBB(bb.minX + (bb.maxX - bb.minX) / 2 - headHalf, bb.maxY - headSize, bb.minZ + (bb.maxZ - bb.minZ) / 2 - headHalf,
bb.minX + (bb.maxX - bb.minX) / 2 + headHalf, bb.maxY, bb.minZ + (bb.maxZ - bb.minZ) / 2 + headHalf);

Vector3d[] corners = new Vector3d[]{
new Vector3d(headBB.minX, headBB.minY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.minY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.minY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.minY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.maxY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.maxY, headBB.minZ),
new Vector3d(headBB.maxX, headBB.maxY, headBB.maxZ),
new Vector3d(headBB.minX, headBB.maxY, headBB.maxZ)
            };

float left = Float.MAX_VALUE;
float right = Float.MIN_VALUE;
float top = Float.MAX_VALUE;
float bottom = Float.MIN_VALUE;

boolean valid = true;
for (Vector3d corner : corners) {
Vector2f proj = ProjectionUtil.project(corner.x, corner.y, corner.z);
if (isInvalid(proj)) {
valid = false;
break;
                }
left = Math.min(left, proj.x);
right = Math.max(right, proj.x);
top = Math.min(top, proj.y);
bottom = Math.max(bottom, proj.y);
            }

if (!valid) continue;

GL11.glBegin(GL11.GL_LINES);
            setGLColor(useColor);

GL11.glVertex2f(head2.x, head2.y);
GL11.glVertex2f(body2.x, body2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(hip2.x, hip2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(leftShoulder2.x, leftShoulder2.y);

GL11.glVertex2f(body2.x, body2.y);
GL11.glVertex2f(rightShoulder2.x, rightShoulder2.y);

GL11.glVertex2f(hip2.x, hip2.y);
GL11.glVertex2f(leftHip2.x, leftHip2.y);

GL11.glVertex2f(hip2.x, hip2.y);
GL11.glVertex2f(rightHip2.x, rightHip2.y);

GL11.glVertex2f(leftShoulder2.x, leftShoulder2.y);
GL11.glVertex2f(leftHand2.x, leftHand2.y);

GL11.glVertex2f(rightShoulder2.x, rightShoulder2.y);
GL11.glVertex2f(rightHand2.x, rightHand2.y);

GL11.glVertex2f(leftHip2.x, leftHip2.y);
GL11.glVertex2f(leftFoot2.x, leftFoot2.y);

GL11.glVertex2f(rightHip2.x, rightHip2.y);
GL11.glVertex2f(rightFoot2.x, rightFoot2.y);

GL11.glVertex2f(left, top);
GL11.glVertex2f(right, top);

GL11.glVertex2f(right, top);
GL11.glVertex2f(right, bottom);

GL11.glVertex2f(right, bottom);
GL11.glVertex2f(left, bottom);

GL11.glVertex2f(left, bottom);
GL11.glVertex2f(left, top);

GL11.glEnd();
        }

GL11.glPopAttrib();

RenderSystem.disableBlend();
RenderSystem.enableTexture();
    }

private boolean isInvalid(Vector2f v) {
if (v == null) return true;
return Float.isNaN(v.x) || Float.isNaN(v.y) || v.x == Float.NEGATIVE_INFINITY || v.y == Float.NEGATIVE_INFINITY;
    }

private void setGLColor(int c) {
float a = ((c >> 24) & 0xFF) / 255f;
float r = ((c >> 16) & 0xFF) / 255f;
float g = ((c >> 8) & 0xFF) / 255f;
float b = (c & 0xFF) / 255f;
GL11.glColor4f(r, g, b, a == 0f ? 1f : a);
    }

public boolean isInView(net.minecraft.entity.Entity ent) {
if (mc.getRenderViewEntity() == null) return false;
frustum.setCameraPosition(mc.getRenderManager().info.getProjectedView().x, mc.getRenderManager().info.getProjectedView().y, mc.getRenderManager().info.getProjectedView().z);
return frustum.isBoundingBoxInFrustum(ent.getBoundingBox()) || ent.ignoreFrustumCheck;
    }

private float getLimbSwingAmount(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("limbSwingAmount");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }

private float getPrevLimbSwingAmount(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("prevLimbSwingAmount");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }

private float getLimbSwing(PlayerEntity p) {
try {
Field f = net.minecraft.entity.LivingEntity.class.getDeclaredField("limbSwing");
f.setAccessible(true);
return (float) f.get(p);
} catch (Exception ignored) {
return 0;
        }
    }
}
дерьмо
 
Назад
Сверху Снизу