100 lines
4.7 KiB
Java
100 lines
4.7 KiB
Java
package com.example.pvpmod.util;
|
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
|
import com.mojang.blaze3d.vertex.*;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.renderer.GameRenderer;
|
|
import net.minecraft.client.renderer.MultiBufferSource;
|
|
import net.minecraft.network.chat.Component;
|
|
import org.joml.Matrix4f;
|
|
|
|
public class RenderUtil {
|
|
|
|
public static void drawESPBox(PoseStack poseStack, double x, double y, double z, double width, double height, int color) {
|
|
poseStack.pushPose();
|
|
poseStack.translate(x - width/2, y, z - width/2);
|
|
|
|
float red = ((color >> 16) & 0xFF) / 255.0f;
|
|
float green = ((color >> 8) & 0xFF) / 255.0f;
|
|
float blue = (color & 0xFF) / 255.0f;
|
|
float alpha = ((color >> 24) & 0xFF) / 255.0f;
|
|
|
|
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
|
RenderSystem.enableBlend();
|
|
RenderSystem.defaultBlendFunc();
|
|
RenderSystem.disableDepthTest();
|
|
|
|
Tesselator tesselator = Tesselator.getInstance();
|
|
BufferBuilder buffer = tesselator.getBuilder();
|
|
Matrix4f matrix = poseStack.last().pose();
|
|
|
|
// Draw outline
|
|
buffer.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR);
|
|
|
|
// Bottom face
|
|
buffer.vertex(matrix, 0, 0, 0).color(red, green, blue, alpha).endVertex();
|
|
buffer.vertex(matrix, (float)width, 0, 0).color(red, green, blue, alpha).endVertex();
|
|
|
|
buffer.vertex(matrix, (float)width, 0, 0).color(red, green, blue, alpha).endVertex();
|
|
buffer.vertex(matrix, (float)width, 0, (float)width).color(red, green, blue, alpha).endVertex();
|
|
|
|
buffer.vertex(matrix, (float)width, 0, (float)width).color(red, green, blue, alpha).endVertex();
|
|
buffer.vertex(matrix, 0, 0, (float)width).color(red, green, blue, alpha).endVertex();
|
|
|
|
buffer.vertex(matrix, 0, 0, (float)width).color(red, green, blue, alpha).endVertex();
|
|
buffer.vertex(matrix, 0, 0, 0).color(red, green, blue, alpha).endVertex();
|
|
|
|
// Top face
|
|
buffer.vertex(matrix, 0, (float)height, 0).color(red, green, blue, alpha).endVertex();
|
|
buffer.vertex(matrix, (float)width, (float)height, 0).color(red, green, blue, alpha).endVertex();
|
|
|
|
buffer.vertex(matrix, (float)width, (float)height, 0).color(red, green, blue, alpha).endVertex();
|
|
buffer.vertex(matrix, (float)width, (float)height, (float)width).color(red, green, blue, alpha).endVertex();
|
|
|
|
buffer.vertex(matrix, (float)width, (float)height, (float)width).color(red, green, blue, alpha).endVertex();
|
|
buffer.vertex(matrix, 0, (float)height, (float)width).color(red, green, blue, alpha).endVertex();
|
|
|
|
buffer.vertex(matrix, 0, (float)height, (float)width).color(red, green, blue, alpha).endVertex();
|
|
buffer.vertex(matrix, 0, (float)height, 0).color(red, green, blue, alpha).endVertex();
|
|
|
|
// Vertical lines
|
|
buffer.vertex(matrix, 0, 0, 0).color(red, green, blue, alpha).endVertex();
|
|
buffer.vertex(matrix, 0, (float)height, 0).color(red, green, blue, alpha).endVertex();
|
|
|
|
buffer.vertex(matrix, (float)width, 0, 0).color(red, green, blue, alpha).endVertex();
|
|
buffer.vertex(matrix, (float)width, (float)height, 0).color(red, green, blue, alpha).endVertex();
|
|
|
|
buffer.vertex(matrix, (float)width, 0, (float)width).color(red, green, blue, alpha).endVertex();
|
|
buffer.vertex(matrix, (float)width, (float)height, (float)width).color(red, green, blue, alpha).endVertex();
|
|
|
|
buffer.vertex(matrix, 0, 0, (float)width).color(red, green, blue, alpha).endVertex();
|
|
buffer.vertex(matrix, 0, (float)height, (float)width).color(red, green, blue, alpha).endVertex();
|
|
|
|
tesselator.end();
|
|
|
|
RenderSystem.enableDepthTest();
|
|
RenderSystem.disableBlend();
|
|
|
|
poseStack.popPose();
|
|
}
|
|
|
|
public static void drawNameTag(PoseStack poseStack, String text, double x, double y, double z, int color) {
|
|
Minecraft mc = Minecraft.getInstance();
|
|
|
|
poseStack.pushPose();
|
|
poseStack.translate(x, y, z);
|
|
poseStack.mulPose(mc.gameRenderer.getMainCamera().rotation());
|
|
poseStack.scale(-0.025f, -0.025f, 0.025f);
|
|
|
|
Matrix4f matrix = poseStack.last().pose();
|
|
|
|
MultiBufferSource.BufferSource bufferSource = mc.renderBuffers().bufferSource();
|
|
|
|
int textWidth = mc.font.width(text);
|
|
mc.font.drawInBatch(text, -textWidth / 2.0f, 0, color, false, matrix, bufferSource, false, 0, 15728880);
|
|
|
|
bufferSource.endBatch();
|
|
|
|
poseStack.popPose();
|
|
}
|
|
} |