Skip to content

Commit

Permalink
fabric-1.19.4: added GameRendererMixin for lb rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
kurrycat committed May 23, 2023
1 parent 761121a commit f5fb19a
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

public class EventHandler {
/**
* @param key The GLFW key code. See {@link net.minecraft.client.util.InputUtil}.
* @param key The GLFW key code. See {@link net.minecraft.client.util.InputUtil}.
* @param scanCode
* @param action The action, where 0 = unpressed, 1 = pressed, 2 = held.
* @param action The action, where 0 = unpressed, 1 = pressed, 2 = held.
*/
public void onKey(int key, int scanCode, int action) {
if (action == 1) {
Expand Down Expand Up @@ -43,6 +43,13 @@ public void onInGameOverlayRender(MatrixStack matrices, float tickDelta) {
API.Events.onRenderOverlay();
}

public void onRenderWorldOverlay(MatrixStack matrixStack, float tickDelta) {
MPKMod.INSTANCE.matrixStack = matrixStack;
matrixStack.push();
API.Events.onRenderWorldOverlay(tickDelta);
matrixStack.pop();
}

public void onClientTickStart(MinecraftClient mc) {
API.Events.onTickStart();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import org.joml.Matrix4f;

import java.awt.*;
import java.util.*;
import java.util.List;
import java.util.*;

public class FunctionCompatibility implements FunctionHolder,
SoundManager.Interface,
Expand All @@ -45,7 +46,7 @@ public List<BoundingBox3D> getCollisionBoundingBoxes(Vector3D blockPosVector) {
final Vector3D blockPosVec = blockPosVector.copy();
BlockPos blockPos = new BlockPos(blockPosVec.getXI(), blockPosVec.getYI(), blockPosVec.getZI());

if(MinecraftClient.getInstance().world == null)
if (MinecraftClient.getInstance().world == null)
return null;

ArrayList<BoundingBox3D> boundingBoxes = new ArrayList<>();
Expand Down Expand Up @@ -119,50 +120,60 @@ public void drawBox(BoundingBox3D bb, Color color, float partialTicks) {

RenderSystem.applyModelViewMatrix();

RenderSystem.enableBlend();
RenderSystem.enableDepthTest();
RenderSystem.setShader(GameRenderer::getPositionColorProgram);

Tessellator tessellator = Tessellator.getInstance();
BufferBuilder builder = tessellator.getBuffer();

RenderSystem.enableBlend();

RenderSystem.lineWidth(1.0F);

Vec3d pos = MinecraftClient.getInstance().gameRenderer.getCamera().getPos();
bb = bb.move(-pos.x, -pos.y, -pos.z);

MPKMod.INSTANCE.matrixStack.translate(-pos.x, -pos.y, -pos.z);
//bb = bb.move(-pos.x, -pos.y, -pos.z);

Matrix4f posMat = MPKMod.INSTANCE.matrixStack.peek().getPositionMatrix();

float minX = (float) bb.minX();
float minY = (float) bb.minY();
float minZ = (float) bb.minZ();
float maxX = (float) bb.maxX();
float maxY = (float) bb.maxY();
float maxZ = (float) bb.maxZ();

builder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);

builder.vertex(bb.minX(), bb.maxY(), bb.minZ()).color(r, g, b, a).next();
builder.vertex(bb.maxX(), bb.maxY(), bb.minZ()).color(r, g, b, a).next();
builder.vertex(bb.maxX(), bb.minY(), bb.minZ()).color(r, g, b, a).next();
builder.vertex(bb.minX(), bb.minY(), bb.minZ()).color(r, g, b, a).next();
builder.vertex(posMat, minX, maxY, minZ).color(r, g, b, a).next();
builder.vertex(posMat, maxX, maxY, minZ).color(r, g, b, a).next();
builder.vertex(posMat, maxX, minY, minZ).color(r, g, b, a).next();
builder.vertex(posMat, minX, minY, minZ).color(r, g, b, a).next();

builder.vertex(bb.minX(), bb.minY(), bb.maxZ()).color(r, g, b, a).next();
builder.vertex(bb.maxX(), bb.minY(), bb.maxZ()).color(r, g, b, a).next();
builder.vertex(bb.maxX(), bb.maxY(), bb.maxZ()).color(r, g, b, a).next();
builder.vertex(bb.minX(), bb.maxY(), bb.maxZ()).color(r, g, b, a).next();
builder.vertex(posMat, minX, minY, maxZ).color(r, g, b, a).next();
builder.vertex(posMat, maxX, minY, maxZ).color(r, g, b, a).next();
builder.vertex(posMat, maxX, maxY, maxZ).color(r, g, b, a).next();
builder.vertex(posMat, minX, maxY, maxZ).color(r, g, b, a).next();

builder.vertex(bb.minX(), bb.minY(), bb.minZ()).color(r, g, b, a).next();
builder.vertex(bb.maxX(), bb.minY(), bb.minZ()).color(r, g, b, a).next();
builder.vertex(bb.maxX(), bb.minY(), bb.maxZ()).color(r, g, b, a).next();
builder.vertex(bb.minX(), bb.minY(), bb.maxZ()).color(r, g, b, a).next();
builder.vertex(posMat, minX, minY, minZ).color(r, g, b, a).next();
builder.vertex(posMat, maxX, minY, minZ).color(r, g, b, a).next();
builder.vertex(posMat, maxX, minY, maxZ).color(r, g, b, a).next();
builder.vertex(posMat, minX, minY, maxZ).color(r, g, b, a).next();

builder.vertex(bb.minX(), bb.maxY(), bb.maxZ()).color(r, g, b, a).next();
builder.vertex(bb.maxX(), bb.maxY(), bb.maxZ()).color(r, g, b, a).next();
builder.vertex(bb.maxX(), bb.maxY(), bb.minZ()).color(r, g, b, a).next();
builder.vertex(bb.minX(), bb.maxY(), bb.minZ()).color(r, g, b, a).next();
builder.vertex(posMat, minX, maxY, maxZ).color(r, g, b, a).next();
builder.vertex(posMat, maxX, maxY, maxZ).color(r, g, b, a).next();
builder.vertex(posMat, maxX, maxY, minZ).color(r, g, b, a).next();
builder.vertex(posMat, minX, maxY, minZ).color(r, g, b, a).next();

builder.vertex(bb.minX(), bb.minY(), bb.maxZ()).color(r, g, b, a).next();
builder.vertex(bb.minX(), bb.maxY(), bb.maxZ()).color(r, g, b, a).next();
builder.vertex(bb.minX(), bb.maxY(), bb.minZ()).color(r, g, b, a).next();
builder.vertex(bb.minX(), bb.minY(), bb.minZ()).color(r, g, b, a).next();
builder.vertex(posMat, minX, minY, maxZ).color(r, g, b, a).next();
builder.vertex(posMat, minX, maxY, maxZ).color(r, g, b, a).next();
builder.vertex(posMat, minX, maxY, minZ).color(r, g, b, a).next();
builder.vertex(posMat, minX, minY, minZ).color(r, g, b, a).next();

builder.vertex(bb.maxX(), bb.minY(), bb.minZ()).color(r, g, b, a).next();
builder.vertex(bb.maxX(), bb.maxY(), bb.minZ()).color(r, g, b, a).next();
builder.vertex(bb.maxX(), bb.maxY(), bb.maxZ()).color(r, g, b, a).next();
builder.vertex(bb.maxX(), bb.minY(), bb.maxZ()).color(r, g, b, a).next();
builder.vertex(posMat, maxX, minY, minZ).color(r, g, b, a).next();
builder.vertex(posMat, maxX, maxY, minZ).color(r, g, b, a).next();
builder.vertex(posMat, maxX, maxY, maxZ).color(r, g, b, a).next();
builder.vertex(posMat, maxX, minY, maxZ).color(r, g, b, a).next();

tessellator.draw();

Expand All @@ -174,19 +185,19 @@ public void drawBox(BoundingBox3D bb, Color color, float partialTicks) {
*/
public void drawRect(Vector2D pos, Vector2D size, Color color) {
Screen.fill(
matrixStack,
pos.getXI(),
pos.getYI(),
pos.getXI() + size.getXI(),
pos.getYI() + size.getYI(),
color.getRGB()
matrixStack,
pos.getXI(),
pos.getYI(),
pos.getXI() + size.getXI(),
pos.getYI() + size.getYI(),
color.getRGB()
);
}

public Vector2D getScaledSize() {
return new Vector2D(
MinecraftClient.getInstance().getWindow().getScaledWidth(),
MinecraftClient.getInstance().getWindow().getScaledHeight()
MinecraftClient.getInstance().getWindow().getScaledWidth(),
MinecraftClient.getInstance().getWindow().getScaledHeight()
);
}

Expand All @@ -199,8 +210,8 @@ public void drawString(String text, Vector2D pos, Color color, boolean shadow) {

public Vector2D getStringSize(String text) {
return new Vector2D(
MinecraftClient.getInstance().textRenderer.getWidth(text),
MinecraftClient.getInstance().textRenderer.fontHeight
MinecraftClient.getInstance().textRenderer.getWidth(text),
MinecraftClient.getInstance().textRenderer.fontHeight
);
}

Expand All @@ -222,7 +233,7 @@ public String getFPS() {

public void displayGuiScreen(MPKGuiScreen screen) {
MinecraftClient.getInstance().setScreen(
screen == null
screen == null
? null
: new io.github.kurrycat.mpkmod.compatibility.fabric_1_19_4.MPKGuiScreen(screen));
}
Expand Down Expand Up @@ -252,7 +263,7 @@ public void startSection(String name) {
}

public void endStartSection(String name) {
MinecraftClient.getInstance().getProfiler().push(name);
MinecraftClient.getInstance().getProfiler().swap(name);
}

public void endSection() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.kurrycat.mpkmod.compatibility.fabric_1_19_4.mixin;

import io.github.kurrycat.mpkmod.compatibility.fabric_1_19_4.MPKMod;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = GameRenderer.class)
public class GameRendererMixin {
@Inject(at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V", args = "ldc=hand"), method = "renderWorld")
public void render(float tickDelta, long limitTime, MatrixStack matrix, CallbackInfo info) {
MPKMod.INSTANCE.eventHandler.onRenderWorldOverlay(matrix, tickDelta);
}
}
3 changes: 2 additions & 1 deletion fabric-1.19.4/src/main/resources/mpkmod.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
],
"client": [
"KeyboardMixin",
"MinecraftClientMixin"
"MinecraftClientMixin",
"GameRendererMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit f5fb19a

Please sign in to comment.