This commit is contained in:
gnembon committed 2025-02-05 21:45:23 +01:00
1 parent 85803cecbb
commit 7c73a9344c
9 files changed
+62 -44

No files matched your search

@@ -6,11 +6,12 @@ import carpet.script.utils.shapes.ShapeDirection;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.blaze3d.vertex.ByteBufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.MeshData;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexBuffer;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat.Mode;
import com.mojang.math.Axis;
@@ -617,6 +618,14 @@ public class ShapesRenderer
}
}
private static void drawWithShader(MeshData mesh) {
VertexBuffer buffre = mesh.drawState().format().getImmediateDrawVertexBuffer();
buffre.bind();
buffre.upload(mesh);
buffre.drawWithShader(RenderSystem.getModelViewMatrix(), RenderSystem.getProjectionMatrix(), RenderSystem.getShader());
}
public static class RenderedPolyface extends RenderedShape<ShapeDispatcher.Polyface>
{
private static final VertexFormat.Mode[] faceIndices = new VertexFormat.Mode[]{
@@ -654,7 +663,7 @@ public class ShapesRenderer
}
builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.fr, shape.fg, shape.fb, shape.fa);
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
RenderSystem.disableCull();
RenderSystem.depthMask(false);
@@ -690,7 +699,7 @@ public class ShapesRenderer
builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a);
}
builder.addVertex((float) (vec0.x() - cx), (float) (vec0.y() - cy), (float) (vec0.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a);
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
if (shape.inneredges)
{
BufferBuilder builderr = tesselator.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR);
@@ -705,7 +714,7 @@ public class ShapesRenderer
builderr.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a);
builderr.addVertex((float) (vec0.x() - cx), (float) (vec0.y() - cy), (float) (vec0.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a);
}
BufferUploader.drawWithShader(builderr.buildOrThrow());
drawWithShader(builderr.buildOrThrow());
}
return;
}
@@ -750,7 +759,7 @@ public class ShapesRenderer
builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a);
}
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
return;
}
if (shape.mode == 4)
@@ -784,7 +793,7 @@ public class ShapesRenderer
builder.addVertex((float) (vecC.x() - cx), (float) (vecC.y() - cy), (float) (vecC.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a);
builder.addVertex((float) (vecA.x() - cx), (float) (vecA.y() - cy), (float) (vecA.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a);
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
}
}
@@ -873,7 +882,7 @@ public class ShapesRenderer
BufferBuilder builder = tesselator.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR);
builder.addVertex(x1, y1, z1).setColor(red1, grn1, blu1, alpha);
builder.addVertex(x2, y2, z2).setColor(red1, grn1, blu1, alpha);
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
public static void drawBoxWireGLLines(
@@ -926,7 +935,7 @@ public class ShapesRenderer
builder.addVertex(x2, y2, z1).setColor(red1, grn1, blu1, alpha);
builder.addVertex(x2, y2, z2).setColor(red1, grn1, blu1, alpha);
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
public static void drawBoxFaces(
@@ -987,7 +996,7 @@ public class ShapesRenderer
builder.addVertex(x1, y2, z2).setColor(red1, grn1, blu1, alpha);
}
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
public static void drawCylinderWireframe(Tesselator tesselator,
@@ -1020,7 +1029,7 @@ public class ShapesRenderer
float z = r * Mth.sin(theta);
builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha);
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
if (!isFlat)
@@ -1038,7 +1047,7 @@ public class ShapesRenderer
builder.addVertex(cx + x, cy + h, cz - z).setColor(red, grn, blu, alpha);
builder.addVertex(cx - x, cy + h, cz + z).setColor(red, grn, blu, alpha);
builder.addVertex(cx - x, cy + 0, cz + z).setColor(red, grn, blu, alpha);
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
}
else
@@ -1052,7 +1061,7 @@ public class ShapesRenderer
builder.addVertex(cx - x, cy, cz + z).setColor(red, grn, blu, alpha);
builder.addVertex(cx + x, cy, cz - z).setColor(red, grn, blu, alpha);
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
}
@@ -1070,7 +1079,7 @@ public class ShapesRenderer
float y = r * Mth.sin(theta);
builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha);
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
if (!isFlat)
@@ -1087,7 +1096,7 @@ public class ShapesRenderer
builder.addVertex(cx + 0, cy + y, cz - z).setColor(red, grn, blu, alpha);
builder.addVertex(cx + h, cy + y, cz - z).setColor(red, grn, blu, alpha);
builder.addVertex(cx + h, cy - y, cz + z).setColor(red, grn, blu, alpha);
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
}
else
@@ -1101,7 +1110,7 @@ public class ShapesRenderer
builder.addVertex(cx, cy - y, cz + z).setColor(red, grn, blu, alpha);
builder.addVertex(cx, cy + y, cz - z).setColor(red, grn, blu, alpha);
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
}
else if (axis == Direction.Axis.Z)
@@ -1118,7 +1127,7 @@ public class ShapesRenderer
float x = r * Mth.sin(theta);
builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha);
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
if (!isFlat)
{
@@ -1134,7 +1143,7 @@ public class ShapesRenderer
builder.addVertex(cx - x, cy + y, cz + 0).setColor(red, grn, blu, alpha);
builder.addVertex(cx - x, cy + y, cz + h).setColor(red, grn, blu, alpha);
builder.addVertex(cx + x, cy - y, cz + h).setColor(red, grn, blu, alpha);
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
}
else
@@ -1148,7 +1157,7 @@ public class ShapesRenderer
builder.addVertex(cx + x, cy - y, cz).setColor(red, grn, blu, alpha);
builder.addVertex(cx - x, cy + y, cz).setColor(red, grn, blu, alpha);
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
}
@@ -1175,7 +1184,7 @@ public class ShapesRenderer
float z = r * Mth.sin(theta);
builder.addVertex(x + cx, cy, z + cz).setColor(red, grn, blu, alpha);
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
if (!isFlat)
{
BufferBuilder builderr = tesselator.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR);
@@ -1187,7 +1196,7 @@ public class ShapesRenderer
float z = r * Mth.sin(theta);
builderr.addVertex(x + cx, cy + h, z + cz).setColor(red, grn, blu, alpha);
}
BufferUploader.drawWithShader(builderr.buildOrThrow());
drawWithShader(builderr.buildOrThrow());
BufferBuilder builderrr = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); // quad strip to quads
float xp = r * 1;
@@ -1204,7 +1213,7 @@ public class ShapesRenderer
xp = x;
zp = z;
}
BufferUploader.drawWithShader(builderrr.buildOrThrow());
drawWithShader(builderrr.buildOrThrow());
}
}
@@ -1219,7 +1228,7 @@ public class ShapesRenderer
float z = r * Mth.sin(theta);
builder.addVertex(cx, cy + y, z + cz).setColor(red, grn, blu, alpha);
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
if (!isFlat)
{
BufferBuilder builderr = tesselator.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR);
@@ -1231,7 +1240,7 @@ public class ShapesRenderer
float z = r * Mth.sin(theta);
builderr.addVertex(cx + h, cy + y, cz + z).setColor(red, grn, blu, alpha);
}
BufferUploader.drawWithShader(builderr.buildOrThrow());
drawWithShader(builderr.buildOrThrow());
BufferBuilder builderrr = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); // quad strip to quads
float yp = r * 1;
@@ -1248,7 +1257,7 @@ public class ShapesRenderer
yp = y;
zp = z;
}
BufferUploader.drawWithShader(builderrr.buildOrThrow());
drawWithShader(builderrr.buildOrThrow());
}
}
else if (axis == Direction.Axis.Z)
@@ -1262,7 +1271,7 @@ public class ShapesRenderer
float y = r * Mth.sin(theta);
builder.addVertex(x + cx, cy + y, cz).setColor(red, grn, blu, alpha);
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
if (!isFlat)
{
BufferBuilder builderr = tesselator.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR);
@@ -1274,7 +1283,7 @@ public class ShapesRenderer
float y = r * Mth.sin(theta);
builderr.addVertex(x + cx, cy + y, cz + h).setColor(red, grn, blu, alpha);
}
BufferUploader.drawWithShader(builderr.buildOrThrow());
drawWithShader(builderr.buildOrThrow());
BufferBuilder builderrr = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); // quad strip to quads
float xp = r;
@@ -1291,7 +1300,7 @@ public class ShapesRenderer
xp = x;
yp = y;
}
BufferUploader.drawWithShader(builderrr.buildOrThrow());
drawWithShader(builderrr.buildOrThrow());
}
}
}
@@ -1316,7 +1325,7 @@ public class ShapesRenderer
float y = r * Mth.cos(phi);
builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha);
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
for (int j = 0; j <= num_steps180; j++)
{
@@ -1331,7 +1340,7 @@ public class ShapesRenderer
float y = r * Mth.cos(phi);
builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha);
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
}
@@ -1373,7 +1382,7 @@ public class ShapesRenderer
zbp = zp;
yp = y;
}
BufferUploader.drawWithShader(builder.buildOrThrow());
drawWithShader(builder.buildOrThrow());
}
}
}
@@ -700,7 +700,7 @@ public class EntityValue extends Value
return Value.NULL;
});
put("selected_slot", (e, a) -> e instanceof Player p ? new NumericValue(p.getInventory().selected) : Value.NULL);
put("selected_slot", (e, a) -> e instanceof Player p ? new NumericValue(p.getInventory().getSelectedSlot()) : Value.NULL);
put("active_block", (e, a) -> {
if (e instanceof ServerPlayer sp)