Skip to content

Commit

Permalink
added deathscreen coords
Browse files Browse the repository at this point in the history
add to screen
  • Loading branch information
The2019 committed Dec 3, 2023
1 parent 25fd45e commit 33de3d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void addWaypoint(BlockPos pos, String name) {
public static void renderWaypoints() {
WorldRenderEvents.END.register(context -> {
for (BlockPos pos : waypoints.keySet()) {
renderWaypoint(context.matrixStack(), pos, waypoints.get(pos));
renderWaypoint(context, pos, waypoints.get(pos));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
package net.The2019.NewBase.render.waypoints;

import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
import org.joml.Matrix4f;
import org.lwjgl.opengl.GL11;

public class WaypointRender {
private static final MinecraftClient mc = MinecraftClient.getInstance();

public static void renderWaypoint(MatrixStack matrixStack, BlockPos pos, String name) {
Vec3d camera = mc.gameRenderer.getCamera().getPos();
public static void renderWaypoint(WorldRenderContext context, BlockPos pos, String name) {
Camera camera = context.camera();

Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
Vec3d targetPosition = new Vec3d(0, 100, 0);
Vec3d transformedPosition = targetPosition.subtract(camera.getPos());
MatrixStack matrixStack = context.matrixStack();

double x = pos.getX() - camera.x;
double y = pos.getY() - camera.y;
double z = pos.getZ() - camera.z;

matrixStack.push();
matrixStack.translate(x, y, z);
matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch()));
matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(camera.getYaw() + 180.0F));
matrixStack.translate(transformedPosition.x, transformedPosition.y, transformedPosition.z);

Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
Matrix4f positionMatrix = matrixStack.peek().getPositionMatrix();

RenderSystem.depthFunc(GL11.GL_ALWAYS);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.setShader(GameRenderer::getPositionTexProgram);

matrixStack.push();

buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
buffer.vertex(positionMatrix, 0, 1, 0).color(1.0f, 1.0f, 1.0f, 1.0f).next();
// Add more vertices for your shape as needed
Expand All @@ -42,10 +48,11 @@ public static void renderWaypoint(MatrixStack matrixStack, BlockPos pos, String

// Render text
TextRenderer textRenderer = mc.textRenderer;
float textX = (float) (pos.getX() - camera.x);
float textY = (float) (pos.getY() - camera.y);
float textX = (float) (pos.getX() - camera.getBlockPos().getX());
float textY = (float) (pos.getY() - camera.getBlockPos().getY());
textRenderer.draw(Text.literal(name), textX, textY, 1, false, positionMatrix, mc.getBufferBuilders().getOutlineVertexConsumers(), TextRenderer.TextLayerType.NORMAL, 1, 1);

RenderSystem.disableBlend();
RenderSystem.depthFunc(GL11.GL_LEQUAL);
}
}

0 comments on commit 33de3d8

Please sign in to comment.