From ba63e2e2676292ef58f694a63fef662950d9c6db Mon Sep 17 00:00:00 2001 From: ch-yx Date: Thu, 4 Jan 2024 16:52:20 +0800 Subject: [PATCH 01/15] Update ShapesRenderer.java --- src/main/java/carpet/script/utils/ShapesRenderer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 6d3a8c8c0..963543e3b 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -1,4 +1,4 @@ -package carpet.script.utils; +package carpet.script.utils; import carpet.script.CarpetScriptServer; import carpet.script.external.Carpet; From d5b27927c1cc345df348005b859eed58af2e11a8 Mon Sep 17 00:00:00 2001 From: ch-yx Date: Thu, 4 Jan 2024 16:52:20 +0800 Subject: [PATCH 02/15] Update ShapesRenderer.java --- .../carpet/script/utils/ShapeDispatcher.java | 8 ++++++ .../carpet/script/utils/ShapesRenderer.java | 27 +++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/java/carpet/script/utils/ShapeDispatcher.java b/src/main/java/carpet/script/utils/ShapeDispatcher.java index e2b02644d..541d04512 100644 --- a/src/main/java/carpet/script/utils/ShapeDispatcher.java +++ b/src/main/java/carpet/script/utils/ShapeDispatcher.java @@ -306,6 +306,7 @@ private static BiFunction, RegistryAccess, ExpiringShape> cre protected boolean discreteX, discreteY, discreteZ; protected ResourceKey shapeDimension; protected boolean debug; + protected boolean hud; protected ExpiringShape() @@ -373,6 +374,11 @@ protected void init(Map options, RegistryAccess regs) debug = options.get("debug").getBoolean(); } + hud = false; + if (options.containsKey("hud")) + { + debug = options.get("hud").getBoolean(); + } key = 0; followEntity = -1; shapeDimension = ResourceKey.create(Registries.DIMENSION, new ResourceLocation(options.get("dim").getString())); @@ -494,6 +500,7 @@ int vec3dhash(Vec3 vec) "follow", new NumericValue(-1), "line", new NumericValue(2.0), "debug", Value.FALSE, + "hud", Value.FALSE, "fill", new NumericValue(0xffffff00), "snap", new StringValue("xyz") ); @@ -1522,6 +1529,7 @@ public Value validate(java.util.Map options, MinecraftServer serv put("facing", new StringChoiceParam("facing", "player", "camera", "north", "south", "east", "west", "up", "down")); put("doublesided", new BoolParam("doublesided")); put("debug", new BoolParam("debug")); + put("hud", new BoolParam("hud")); }}; protected String id; diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 6d3a8c8c0..bf664c3f0 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -159,7 +159,7 @@ public void render(PoseStack matrices, Camera camera, float partialTick) // lines RenderSystem.lineWidth(0.5F); shapes.get(dimensionType).values().forEach(s -> { - if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)) + if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType) && !s.shape.hud) { s.renderLines(matrices, tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick); } @@ -167,7 +167,30 @@ public void render(PoseStack matrices, Camera camera, float partialTick) // faces RenderSystem.lineWidth(0.1F); shapes.get(dimensionType).values().forEach(s -> { - if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)) + if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType) && !s.shape.hud) + { + s.renderFaces(tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick); + } + }); + RenderSystem.lineWidth(1.0F); + matrixStack.popPose(); + //================== + matrixStack.pushPose(); + //matrixStack.mulPoseMatrix(matrices.last().pose()); + //RenderSystem.applyModelViewMatrix(); + + // lines + RenderSystem.lineWidth(0.5F); + shapes.get(dimensionType).values().forEach(s -> { + if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType) && s.shape.hud) + { + s.renderLines(matrices, tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick); + } + }); + // faces + RenderSystem.lineWidth(0.1F); + shapes.get(dimensionType).values().forEach(s -> { + if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType) && s.shape.hud) { s.renderFaces(tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick); } From fe97dd29f612e43c7f01f36c6a58da0a687865dc Mon Sep 17 00:00:00 2001 From: ch-yx Date: Thu, 4 Jan 2024 18:56:04 +0800 Subject: [PATCH 03/15] emmmmm --- src/main/java/carpet/script/utils/ShapeDispatcher.java | 4 +++- src/main/java/carpet/script/utils/ShapesRenderer.java | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/carpet/script/utils/ShapeDispatcher.java b/src/main/java/carpet/script/utils/ShapeDispatcher.java index 541d04512..09939424f 100644 --- a/src/main/java/carpet/script/utils/ShapeDispatcher.java +++ b/src/main/java/carpet/script/utils/ShapeDispatcher.java @@ -377,7 +377,7 @@ protected void init(Map options, RegistryAccess regs) hud = false; if (options.containsKey("hud")) { - debug = options.get("hud").getBoolean(); + hud = options.get("hud").getBoolean(); } key = 0; followEntity = -1; @@ -469,6 +469,8 @@ protected long calcKey(RegistryAccess regs) hash *= 1099511628211L; hash ^= Boolean.hashCode(debug); hash *= 1099511628211L; + hash ^= Boolean.hashCode(hud); + hash *= 1099511628211L; if (followEntity >= 0) { hash ^= snapTo.hashCode(); diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index b168429d4..9eb5cf81f 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -177,14 +177,14 @@ public void render(PoseStack matrices, Camera camera, float partialTick) //================== matrixStack.pushPose(); //matrixStack.mulPoseMatrix(matrices.last().pose()); - //RenderSystem.applyModelViewMatrix(); + RenderSystem.applyModelViewMatrix(); // lines RenderSystem.lineWidth(0.5F); shapes.get(dimensionType).values().forEach(s -> { if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType) && s.shape.hud) { - s.renderLines(matrices, tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick); + s.renderLines(matrices, tessellator, bufferBuilder, 0, 0, 0, partialTick); } }); // faces @@ -192,7 +192,7 @@ public void render(PoseStack matrices, Camera camera, float partialTick) shapes.get(dimensionType).values().forEach(s -> { if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType) && s.shape.hud) { - s.renderFaces(tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick); + s.renderFaces(tessellator, bufferBuilder, 0, 0, 0, partialTick); } }); RenderSystem.lineWidth(1.0F); From 9acf0920187d62207c5ac4831ffa5b103fc31dcb Mon Sep 17 00:00:00 2001 From: ch-yx Date: Fri, 5 Jan 2024 18:56:00 +0800 Subject: [PATCH 04/15] Update ShapesRenderer.java --- .../carpet/script/utils/ShapesRenderer.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 9eb5cf81f..2c7b33917 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -12,6 +12,7 @@ import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexFormat; +import com.mojang.blaze3d.vertex.VertexSorting; import com.mojang.blaze3d.vertex.VertexFormat.Mode; import com.mojang.math.Axis; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; @@ -21,6 +22,8 @@ import java.util.Map; import java.util.function.BiFunction; +import org.joml.Matrix4f; + import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; @@ -57,6 +60,7 @@ public class ShapesRenderer { + private static final Matrix4f IMATRIX = new Matrix4f(); private final Map, Long2ObjectOpenHashMap>> shapes; private final Map, Long2ObjectOpenHashMap>> labels; private final Minecraft client; @@ -176,8 +180,9 @@ public void render(PoseStack matrices, Camera camera, float partialTick) matrixStack.popPose(); //================== matrixStack.pushPose(); - //matrixStack.mulPoseMatrix(matrices.last().pose()); RenderSystem.applyModelViewMatrix(); + var ori=RenderSystem.getProjectionMatrix(); + RenderSystem.setProjectionMatrix(IMATRIX,VertexSorting.ORTHOGRAPHIC_Z); // lines RenderSystem.lineWidth(0.5F); @@ -196,6 +201,7 @@ public void render(PoseStack matrices, Camera camera, float partialTick) } }); RenderSystem.lineWidth(1.0F); + RenderSystem.setProjectionMatrix(ori,VertexSorting.DISTANCE_TO_ORIGIN); matrixStack.popPose(); RenderSystem.applyModelViewMatrix(); @@ -206,11 +212,26 @@ public void render(PoseStack matrices, Camera camera, float partialTick) entry -> entry.getValue().isExpired(currentTime) ); labels.get(dimensionType).values().forEach(s -> { - if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)) + if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)&& !s.shape.hud) { s.renderLines(matrices, tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick); } }); + //PoseStack matrixStack = RenderSystem.getModelViewStack(); + matrices.pushPose(); + matrices.setIdentity(); + //RenderSystem.applyModelViewMatrix(); + var ori=RenderSystem.getProjectionMatrix(); + RenderSystem.setProjectionMatrix(IMATRIX,VertexSorting.ORTHOGRAPHIC_Z); + labels.get(dimensionType).values().forEach(s -> { + if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)&& s.shape.hud) + { + s.renderLines(matrices, tessellator, bufferBuilder, 0, 0, 0, partialTick); + } + }); + matrices.popPose(); + RenderSystem.applyModelViewMatrix(); + RenderSystem.setProjectionMatrix(ori,VertexSorting.DISTANCE_TO_ORIGIN); } RenderSystem.enableCull(); RenderSystem.depthMask(true); From db5aa8badc31b609095d485d420d63368d12c4cf Mon Sep 17 00:00:00 2001 From: ch-yx Date: Fri, 5 Jan 2024 20:23:07 +0800 Subject: [PATCH 05/15] Update ShapesRenderer.java --- src/main/java/carpet/script/utils/ShapesRenderer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 2c7b33917..9cf91c026 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -60,7 +60,7 @@ public class ShapesRenderer { - private static final Matrix4f IMATRIX = new Matrix4f(); + private static final Matrix4f ORTHOMAT = new Matrix4f().m22(-1); private final Map, Long2ObjectOpenHashMap>> shapes; private final Map, Long2ObjectOpenHashMap>> labels; private final Minecraft client; @@ -182,7 +182,7 @@ public void render(PoseStack matrices, Camera camera, float partialTick) matrixStack.pushPose(); RenderSystem.applyModelViewMatrix(); var ori=RenderSystem.getProjectionMatrix(); - RenderSystem.setProjectionMatrix(IMATRIX,VertexSorting.ORTHOGRAPHIC_Z); + RenderSystem.setProjectionMatrix(ORTHOMAT,VertexSorting.ORTHOGRAPHIC_Z); // lines RenderSystem.lineWidth(0.5F); @@ -222,7 +222,7 @@ public void render(PoseStack matrices, Camera camera, float partialTick) matrices.setIdentity(); //RenderSystem.applyModelViewMatrix(); var ori=RenderSystem.getProjectionMatrix(); - RenderSystem.setProjectionMatrix(IMATRIX,VertexSorting.ORTHOGRAPHIC_Z); + RenderSystem.setProjectionMatrix(ORTHOMAT,VertexSorting.ORTHOGRAPHIC_Z); labels.get(dimensionType).values().forEach(s -> { if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)&& s.shape.hud) { From 2b0694fc376868bcf373dc958bbf2b3118b96eed Mon Sep 17 00:00:00 2001 From: ch-yx Date: Fri, 19 Jan 2024 02:32:25 +0800 Subject: [PATCH 06/15] remove unnecessary part --- src/main/java/carpet/script/utils/ShapesRenderer.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 9cf91c026..b5ae6bace 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -179,7 +179,7 @@ public void render(PoseStack matrices, Camera camera, float partialTick) RenderSystem.lineWidth(1.0F); matrixStack.popPose(); //================== - matrixStack.pushPose(); + RenderSystem.applyModelViewMatrix(); var ori=RenderSystem.getProjectionMatrix(); RenderSystem.setProjectionMatrix(ORTHOMAT,VertexSorting.ORTHOGRAPHIC_Z); @@ -202,8 +202,6 @@ public void render(PoseStack matrices, Camera camera, float partialTick) }); RenderSystem.lineWidth(1.0F); RenderSystem.setProjectionMatrix(ori,VertexSorting.DISTANCE_TO_ORIGIN); - matrixStack.popPose(); - RenderSystem.applyModelViewMatrix(); } if (!labels.isEmpty()) @@ -230,7 +228,7 @@ public void render(PoseStack matrices, Camera camera, float partialTick) } }); matrices.popPose(); - RenderSystem.applyModelViewMatrix(); + //RenderSystem.applyModelViewMatrix(); RenderSystem.setProjectionMatrix(ori,VertexSorting.DISTANCE_TO_ORIGIN); } RenderSystem.enableCull(); From 5594597a05652e18db24042829049bed0fd22e74 Mon Sep 17 00:00:00 2001 From: ch-yx Date: Tue, 9 Jul 2024 04:20:47 +0800 Subject: [PATCH 07/15] Update ShapesRenderer.java --- src/main/java/carpet/script/utils/ShapesRenderer.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 02c014f68..713dd0c6e 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -24,8 +24,6 @@ import java.util.Map; import java.util.function.BiFunction; -import org.joml.Matrix4f; - import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; @@ -195,7 +193,7 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) shapes.get(dimensionType).values().forEach(s -> { if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType) && s.shape.hud) { - s.renderLines(matrices, tessellator, bufferBuilder, 0, 0, 0, partialTick); + s.renderLines(matrices, tesselator, 0, 0, 0, partialTick); } }); // faces @@ -203,7 +201,7 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) shapes.get(dimensionType).values().forEach(s -> { if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType) && s.shape.hud) { - s.renderFaces(tessellator, bufferBuilder, 0, 0, 0, partialTick); + s.renderFaces(tesselator, 0, 0, 0, partialTick); } }); RenderSystem.lineWidth(1.0F); @@ -230,7 +228,7 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) labels.get(dimensionType).values().forEach(s -> { if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)&& s.shape.hud) { - s.renderLines(matrices, tessellator, bufferBuilder, 0, 0, 0, partialTick); + s.renderLines(matrices, tesselator, 0, 0, 0, partialTick); } }); matrices.popPose(); From 2b8b14c601409909b729bbec08f64bc7b86590b0 Mon Sep 17 00:00:00 2001 From: ch-yx Date: Tue, 9 Jul 2024 18:14:08 +0800 Subject: [PATCH 08/15] fix---half --- src/main/java/carpet/script/utils/ShapeDispatcher.java | 2 +- src/main/java/carpet/script/utils/ShapesRenderer.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/carpet/script/utils/ShapeDispatcher.java b/src/main/java/carpet/script/utils/ShapeDispatcher.java index 311797718..4ace6d022 100644 --- a/src/main/java/carpet/script/utils/ShapeDispatcher.java +++ b/src/main/java/carpet/script/utils/ShapeDispatcher.java @@ -1516,7 +1516,7 @@ public Value validate(java.util.Map options, MinecraftServer serv put("points", new PointsParam("points")); put("text", new FormattedTextParam("text")); put("value", new FormattedTextParam("value")); - put("size", new PositiveIntParam("size")); + put("size", new PositiveFloatParam("size")); put("align", new StringChoiceParam("align", "center", "left", "right")); put("block", new BlockParam("block")); diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 713dd0c6e..b02c5f763 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -183,6 +183,8 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) RenderSystem.lineWidth(1.0F); matrixStack.popMatrix(); + matrixStack.pushMatrix(); + matrixStack.identity(); RenderSystem.applyModelViewMatrix(); var ori=RenderSystem.getProjectionMatrix(); @@ -206,6 +208,7 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) }); RenderSystem.lineWidth(1.0F); RenderSystem.setProjectionMatrix(ori,VertexSorting.DISTANCE_TO_ORIGIN); + matrixStack.popMatrix(); } if (!labels.isEmpty()) From ee6f7fdbcf55ebf5af93904a826208ef6a9e5990 Mon Sep 17 00:00:00 2001 From: ch-yx Date: Tue, 9 Jul 2024 18:46:19 +0800 Subject: [PATCH 09/15] looks fine now? --- src/main/java/carpet/script/utils/ShapesRenderer.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index b02c5f763..0697c1092 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -209,6 +209,7 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) RenderSystem.lineWidth(1.0F); RenderSystem.setProjectionMatrix(ori,VertexSorting.DISTANCE_TO_ORIGIN); matrixStack.popMatrix(); + RenderSystem.applyModelViewMatrix(); } if (!labels.isEmpty()) @@ -216,6 +217,12 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) labels.get(dimensionType).long2ObjectEntrySet().removeIf( entry -> entry.getValue().isExpired(currentTime) ); + Matrix4fStack matrixStack = RenderSystem.getModelViewStack(); + matrixStack.pushMatrix(); + matrixStack.identity(); + RenderSystem.applyModelViewMatrix(); + matrices.pushPose(); + matrices.mulPose(modelViewMatrix); labels.get(dimensionType).values().forEach(s -> { if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)&& !s.shape.hud) { @@ -223,7 +230,7 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) } }); //PoseStack matrixStack = RenderSystem.getModelViewStack(); - matrices.pushPose(); + //matrices.pushPose(); matrices.setIdentity(); //RenderSystem.applyModelViewMatrix(); var ori=RenderSystem.getProjectionMatrix(); @@ -237,6 +244,8 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) matrices.popPose(); //RenderSystem.applyModelViewMatrix(); RenderSystem.setProjectionMatrix(ori,VertexSorting.DISTANCE_TO_ORIGIN); + matrixStack.popMatrix(); + RenderSystem.applyModelViewMatrix(); } RenderSystem.enableCull(); RenderSystem.depthMask(true); From 892946ca18434a0bc1e1704daa8bfee960c1197e Mon Sep 17 00:00:00 2001 From: ch-yx Date: Sat, 14 Sep 2024 06:23:16 +0800 Subject: [PATCH 10/15] Update ShapesRenderer.java --- src/main/java/carpet/script/utils/ShapesRenderer.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 0697c1092..fae2a3e9d 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -217,12 +217,6 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) labels.get(dimensionType).long2ObjectEntrySet().removeIf( entry -> entry.getValue().isExpired(currentTime) ); - Matrix4fStack matrixStack = RenderSystem.getModelViewStack(); - matrixStack.pushMatrix(); - matrixStack.identity(); - RenderSystem.applyModelViewMatrix(); - matrices.pushPose(); - matrices.mulPose(modelViewMatrix); labels.get(dimensionType).values().forEach(s -> { if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)&& !s.shape.hud) { @@ -231,6 +225,11 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) }); //PoseStack matrixStack = RenderSystem.getModelViewStack(); //matrices.pushPose(); + Matrix4fStack matrixStack = RenderSystem.getModelViewStack(); + matrixStack.pushMatrix(); + matrixStack.identity(); + RenderSystem.applyModelViewMatrix(); + matrices.pushPose(); matrices.setIdentity(); //RenderSystem.applyModelViewMatrix(); var ori=RenderSystem.getProjectionMatrix(); From 0676d77a6fbae3aef6acc0457aecdafcee50345e Mon Sep 17 00:00:00 2001 From: ch-yx Date: Sat, 14 Sep 2024 07:07:04 +0800 Subject: [PATCH 11/15] update --- src/main/java/carpet/script/utils/ShapesRenderer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index d279868e3..e8f1c6c7a 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -177,7 +177,7 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) matrixStack.pushMatrix(); matrixStack.identity(); - RenderSystem.applyModelViewMatrix(); + //RenderSystem.applyModelViewMatrix(); var ori=RenderSystem.getProjectionMatrix(); RenderSystem.setProjectionMatrix(ORTHOMAT,VertexSorting.ORTHOGRAPHIC_Z); @@ -218,7 +218,7 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) Matrix4fStack matrixStack = RenderSystem.getModelViewStack(); matrixStack.pushMatrix(); matrixStack.identity(); - RenderSystem.applyModelViewMatrix(); + //RenderSystem.applyModelViewMatrix(); matrices.pushPose(); matrices.setIdentity(); //RenderSystem.applyModelViewMatrix(); @@ -234,7 +234,7 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) //RenderSystem.applyModelViewMatrix(); RenderSystem.setProjectionMatrix(ori,VertexSorting.DISTANCE_TO_ORIGIN); matrixStack.popMatrix(); - RenderSystem.applyModelViewMatrix(); + //RenderSystem.applyModelViewMatrix(); } RenderSystem.enableCull(); RenderSystem.depthMask(true); From f6d701e06b3f40ab62fb6ebbd1efd4277cd332e5 Mon Sep 17 00:00:00 2001 From: ch-yx Date: Tue, 17 Sep 2024 17:25:47 +0800 Subject: [PATCH 12/15] Update ShapesRenderer.java --- .../carpet/mixins/FluidRenderingMixin.java | 31 +++++++++++++++++++ .../carpet/script/utils/ShapesRenderer.java | 10 ++++++ src/main/resources/carpet.mixins.json | 1 + 3 files changed, 42 insertions(+) create mode 100644 src/main/java/carpet/mixins/FluidRenderingMixin.java diff --git a/src/main/java/carpet/mixins/FluidRenderingMixin.java b/src/main/java/carpet/mixins/FluidRenderingMixin.java new file mode 100644 index 000000000..e65efce88 --- /dev/null +++ b/src/main/java/carpet/mixins/FluidRenderingMixin.java @@ -0,0 +1,31 @@ +package carpet.mixins; + +import carpet.script.utils.ShapesRenderer; +import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.block.LiquidBlockRenderer; +import org.joml.Vector4f; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(LiquidBlockRenderer.class) +public abstract class FluidRenderingMixin { + @WrapMethod(method = "vertex") + void addingvertex(VertexConsumer vertexConsumer, float f, float g, float h, float i, float j, float k, float l, float m, int n, Operation original) { + var pair=ShapesRenderer.DrawingShape.get(); + if (pair!=null) { + var x = pair.getSecond().getX(); + var y = pair.getSecond().getY(); + var z = pair.getSecond().getZ(); + x = (x & 0xf); + y = (y & 0xf); + z = (z & 0xf); + var vec = new Vector4f(f - x, g - y, h - z, 1); + pair.getFirst().pose().transform(vec); + f = vec.x; + g = vec.y; + h = vec.z; + } + original.call(vertexConsumer, f, g, h, i, j, k, l, m, n); + } +} diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index e8f1c6c7a..67bec7a4d 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -14,6 +14,7 @@ import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexSorting; import com.mojang.blaze3d.vertex.VertexFormat.Mode; +import com.mojang.datafixers.util.Pair; import com.mojang.math.Axis; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; @@ -59,6 +60,8 @@ public class ShapesRenderer private final Map, Long2ObjectOpenHashMap>> labels; private final Minecraft client; + public static ThreadLocal> DrawingShape = new ThreadLocal<>(); + private final Map>> renderedShapes = new HashMap<>() {{ @@ -490,6 +493,13 @@ public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, do } } + var fluidstate = blockState.getFluidState(); + try { + DrawingShape.set(Pair.of(matrices.last(),blockPos)); + client.getBlockRenderer().renderLiquid(blockPos, client.level, immediate.getBuffer(ItemBlockRenderTypes.getRenderLayer(fluidstate)), blockState, fluidstate); + }finally { + DrawingShape.remove(); + } } else { diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index 9fa3de983..7ad7b1b46 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -200,6 +200,7 @@ "ClientPacketListener_customPacketsMixin", "DebugRenderer_scarpetRenderMixin", "LevelRenderer_scarpetRenderMixin", + "FluidRenderingMixin", "ClientCommonPacketListenerImpl_customPacketMixin" From 792bd6345a9982b9b572ed07bd03b1e1f55d2c43 Mon Sep 17 00:00:00 2001 From: ch-yx Date: Wed, 18 Sep 2024 12:10:12 +0800 Subject: [PATCH 13/15] rewrite a mixin --- .../carpet/mixins/FluidRenderingMixin.java | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/main/java/carpet/mixins/FluidRenderingMixin.java b/src/main/java/carpet/mixins/FluidRenderingMixin.java index e65efce88..32586ecf9 100644 --- a/src/main/java/carpet/mixins/FluidRenderingMixin.java +++ b/src/main/java/carpet/mixins/FluidRenderingMixin.java @@ -1,31 +1,29 @@ package carpet.mixins; import carpet.script.utils.ShapesRenderer; -import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.renderer.block.LiquidBlockRenderer; import org.joml.Vector4f; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArgs; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; @Mixin(LiquidBlockRenderer.class) public abstract class FluidRenderingMixin { - @WrapMethod(method = "vertex") - void addingvertex(VertexConsumer vertexConsumer, float f, float g, float h, float i, float j, float k, float l, float m, int n, Operation original) { - var pair=ShapesRenderer.DrawingShape.get(); - if (pair!=null) { - var x = pair.getSecond().getX(); - var y = pair.getSecond().getY(); - var z = pair.getSecond().getZ(); - x = (x & 0xf); - y = (y & 0xf); - z = (z & 0xf); - var vec = new Vector4f(f - x, g - y, h - z, 1); - pair.getFirst().pose().transform(vec); - f = vec.x; - g = vec.y; - h = vec.z; - } - original.call(vertexConsumer, f, g, h, i, j, k, l, m, n); + @ModifyArgs(method = "vertex", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/VertexConsumer;addVertex(FFF)Lcom/mojang/blaze3d/vertex/VertexConsumer;")) + private void injected(Args args) { + var pair = ShapesRenderer.DrawingShape.get(); + if (pair == null) return; + float f = args.get(0); + float g = args.get(1); + float h = args.get(2); + int x = pair.getSecond().getX() & 0xf; + int y = pair.getSecond().getY() & 0xf; + int z = pair.getSecond().getZ() & 0xf; + var vec = new Vector4f(f - x, g - y, h - z, 1); + pair.getFirst().pose().transform(vec); + args.set(0, vec.x); + args.set(1, vec.y); + args.set(2, vec.z); } } From 0d043c86e7a32d8f662f30ed2d0a01b1185b3011 Mon Sep 17 00:00:00 2001 From: ch-yx Date: Tue, 24 Sep 2024 00:56:51 +0800 Subject: [PATCH 14/15] ? --- .../LevelRenderer_scarpetRenderMixin.java | 5 +- .../carpet/script/utils/ShapesRenderer.java | 103 ++++++++++-------- 2 files changed, 61 insertions(+), 47 deletions(-) diff --git a/src/main/java/carpet/mixins/LevelRenderer_scarpetRenderMixin.java b/src/main/java/carpet/mixins/LevelRenderer_scarpetRenderMixin.java index 9672f485f..a649f4932 100644 --- a/src/main/java/carpet/mixins/LevelRenderer_scarpetRenderMixin.java +++ b/src/main/java/carpet/mixins/LevelRenderer_scarpetRenderMixin.java @@ -41,7 +41,10 @@ private void renderScarpetThingsLate(FrameGraphBuilder frameGraphBuilder, Camera { FramePass pass = frameGraphBuilder.addPass("scarpet_shapes"); targets.main = pass.readsAndWrites(targets.main); - pass.executes(() -> CarpetClient.shapes.render(null, camera, f)); + pass.executes(() -> CarpetClient.shapes.render(0, camera, f)); + pass = frameGraphBuilder.addPass("scarpet_shapes-fluid"); + targets.main = pass.readsAndWrites(targets.main); + pass.executes(() -> CarpetClient.shapes.render(1, camera, f)); } } } diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 67bec7a4d..0343d58fd 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -111,7 +111,7 @@ public ShapesRenderer(Minecraft minecraftClient) labels = new HashMap<>(); } - public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) + public void render(int passid, Camera camera, float partialTick) { Runnable token = Carpet.startProfilerSection("Scarpet client"); // posestack is not needed anymore - left as TODO to cleanup later @@ -213,7 +213,7 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) labels.get(dimensionType).values().forEach(s -> { if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)&& !s.shape.hud) { - s.renderLines(matrices, tesselator, cameraX, cameraY, cameraZ, partialTick); + s.renderLines(matrices, tesselator, cameraX, cameraY, cameraZ, partialTick, passid); } }); //PoseStack matrixStack = RenderSystem.getModelViewStack(); @@ -230,7 +230,7 @@ public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) labels.get(dimensionType).values().forEach(s -> { if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)&& s.shape.hud) { - s.renderLines(matrices, tesselator, 0, 0, 0, partialTick); + s.renderLines(matrices, tesselator, 0, 0, 0, partialTick, passid); } }); matrices.popPose(); @@ -311,6 +311,9 @@ public abstract static class RenderedShape> 16 & 0xFF) / 255.0F; - float green = (color >> 8 & 0xFF) / 255.0F; - float blue = (color & 0xFF) / 255.0F; - RenderType type; - if (blockState.getBlock() instanceof LeavesBlock && !Minecraft.useFancyGraphics()) { - type = RenderType.solid(); - } else { - type = ItemBlockRenderTypes.getRenderType(blockState); + var bakedModel = client.getBlockRenderer().getBlockModel(blockState); + int color = client.getBlockColors().getColor(blockState, client.level, blockPos, 0); + //dont know why there is a 0. + //see https://github.com/senseiwells/EssentialClient/blob/4db1f291936f502304791ee323f369c206b3021d/src/main/java/me/senseiwells/essentialclient/utils/render/RenderHelper.java#L464 + float red = (color >> 16 & 0xFF) / 255.0F; + float green = (color >> 8 & 0xFF) / 255.0F; + float blue = (color & 0xFF) / 255.0F; + RenderType type; + if (blockState.getBlock() instanceof LeavesBlock && !Minecraft.useFancyGraphics()) { + type = RenderType.solid(); + } else { + type = ItemBlockRenderTypes.getRenderType(blockState); + } + client.getBlockRenderer().getModelRenderer().renderModel(matrices.last(), immediate.getBuffer(type), blockState, bakedModel, red, green, blue, light, OverlayTexture.NO_OVERLAY); } - client.getBlockRenderer().getModelRenderer().renderModel(matrices.last(), immediate.getBuffer(type), blockState, bakedModel, red, green, blue, light, OverlayTexture.NO_OVERLAY); - } - // draw the block`s entity part - if (BlockEntity == null) - { - if (blockState.getBlock() instanceof EntityBlock eb) + // draw the block`s entity part + if (BlockEntity == null) { - BlockEntity = eb.newBlockEntity(blockPos, blockState); - if (BlockEntity != null) + if (blockState.getBlock() instanceof EntityBlock eb) { - BlockEntity.setLevel(client.level); - if (shape.blockEntity != null) + BlockEntity = eb.newBlockEntity(blockPos, blockState); + if (BlockEntity != null) { - BlockEntity.loadWithComponents(shape.blockEntity, client.level.registryAccess()); + BlockEntity.setLevel(client.level); + if (shape.blockEntity != null) + { + BlockEntity.loadWithComponents(shape.blockEntity, client.level.registryAccess()); + } } } } - } - if (BlockEntity != null) - { - BlockEntityRenderer blockEntityRenderer = client.getBlockEntityRenderDispatcher().getRenderer(BlockEntity); - if (blockEntityRenderer != null) - { - blockEntityRenderer.render(BlockEntity, partialTick, - matrices, immediate, light, OverlayTexture.NO_OVERLAY); + if (BlockEntity != null) + { + BlockEntityRenderer blockEntityRenderer = client.getBlockEntityRenderDispatcher().getRenderer(BlockEntity); + if (blockEntityRenderer != null) + { + blockEntityRenderer.render(BlockEntity, partialTick, + matrices, immediate, light, OverlayTexture.NO_OVERLAY); - } - } - var fluidstate = blockState.getFluidState(); - try { - DrawingShape.set(Pair.of(matrices.last(),blockPos)); - client.getBlockRenderer().renderLiquid(blockPos, client.level, immediate.getBuffer(ItemBlockRenderTypes.getRenderLayer(fluidstate)), blockState, fluidstate); - }finally { - DrawingShape.remove(); + } + } + }else{ + var fluidstate = blockState.getFluidState(); + try { + DrawingShape.set(Pair.of(matrices.last(),blockPos)); + client.getBlockRenderer().renderLiquid(blockPos, client.level, immediate.getBuffer(ItemBlockRenderTypes.getRenderLayer(fluidstate)), blockState, fluidstate); + }finally { + DrawingShape.remove(); + } } } else @@ -518,6 +524,11 @@ public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, do } + @Override + public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, double cz, float partialTick) { + + } + @Override public boolean stageDeux() { From d769ebeb0d0fcd5b5cab63ff4b2da9b0aab4fc9a Mon Sep 17 00:00:00 2001 From: ch-yx Date: Fri, 8 Nov 2024 04:50:03 +0800 Subject: [PATCH 15/15] update --- src/main/java/carpet/script/utils/ShapesRenderer.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 0343d58fd..f23bf5f88 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -4,6 +4,7 @@ import carpet.script.external.Carpet; import carpet.script.utils.shapes.ShapeDirection; +import com.mojang.blaze3d.ProjectionType; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.BufferUploader; @@ -55,7 +56,7 @@ public class ShapesRenderer { - private static final Matrix4f ORTHOMAT = new Matrix4f().m22(-1); + private static final Matrix4f ORTHOMAT = new Matrix4f().m22(-1);//need to check if it should be that, or a simple identity matrix. private final Map, Long2ObjectOpenHashMap>> shapes; private final Map, Long2ObjectOpenHashMap>> labels; private final Minecraft client; @@ -182,7 +183,7 @@ public void render(int passid, Camera camera, float partialTick) //RenderSystem.applyModelViewMatrix(); var ori=RenderSystem.getProjectionMatrix(); - RenderSystem.setProjectionMatrix(ORTHOMAT,VertexSorting.ORTHOGRAPHIC_Z); + RenderSystem.setProjectionMatrix(ORTHOMAT, ProjectionType.ORTHOGRAPHIC); // lines RenderSystem.lineWidth(0.5F); @@ -201,7 +202,7 @@ public void render(int passid, Camera camera, float partialTick) } }); RenderSystem.lineWidth(1.0F); - RenderSystem.setProjectionMatrix(ori,VertexSorting.DISTANCE_TO_ORIGIN); + RenderSystem.setProjectionMatrix(ori,ProjectionType.PERSPECTIVE); matrixStack.popMatrix(); } @@ -226,7 +227,7 @@ public void render(int passid, Camera camera, float partialTick) matrices.setIdentity(); //RenderSystem.applyModelViewMatrix(); var ori=RenderSystem.getProjectionMatrix(); - RenderSystem.setProjectionMatrix(ORTHOMAT,VertexSorting.ORTHOGRAPHIC_Z); + RenderSystem.setProjectionMatrix(ORTHOMAT,ProjectionType.ORTHOGRAPHIC); labels.get(dimensionType).values().forEach(s -> { if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)&& s.shape.hud) { @@ -235,7 +236,7 @@ public void render(int passid, Camera camera, float partialTick) }); matrices.popPose(); //RenderSystem.applyModelViewMatrix(); - RenderSystem.setProjectionMatrix(ori,VertexSorting.DISTANCE_TO_ORIGIN); + RenderSystem.setProjectionMatrix(ori,ProjectionType.PERSPECTIVE); matrixStack.popMatrix(); //RenderSystem.applyModelViewMatrix(); }