diff --git a/src/main/java/carpet/script/utils/ShapeDispatcher.java b/src/main/java/carpet/script/utils/ShapeDispatcher.java index 5202ddf7..28a8943e 100644 --- a/src/main/java/carpet/script/utils/ShapeDispatcher.java +++ b/src/main/java/carpet/script/utils/ShapeDispatcher.java @@ -393,7 +393,11 @@ public class ShapeDispatcher public static class Sphere extends ExpiringShape { private final Set required = ImmutableSet.of("center", "radius"); - private final Map optional = ImmutableMap.of("width", new NumericValue(2.0), "level", Value.ZERO); + private final Map optional = ImmutableMap.of( + "width", new NumericValue(2.0), + "level", Value.ZERO, + "fill", new NumericValue(0xffffff00) + ); @Override protected Set requiredParams() { return Sets.union(super.requiredParams(), required); } @Override @@ -410,6 +414,9 @@ public class ShapeDispatcher int subdivisions; float lineWidth; + protected float fr, fg, fb, fa; + protected int fillColor; + @Override protected void init(Map options) { @@ -426,6 +433,11 @@ public class ShapeDispatcher subdivisions = Math.max(10, (int)(10*Math.sqrt(radius))); } lineWidth = NumericValue.asNumber(options.getOrDefault("width", optional.get("width"))).getFloat(); + fillColor = NumericValue.asNumber(options.getOrDefault("fill", optional.get("fill"))).getInt(); + this.fr = (float)(fillColor >> 24 & 0xFF) / 255.0F; + this.fg = (float)(fillColor >> 16 & 0xFF) / 255.0F; + this.fb = (float)(fillColor >> 8 & 0xFF) / 255.0F; + this.fa = (float)(fillColor & 0xFF) / 255.0F; } @Override @@ -461,7 +473,7 @@ public class ShapeDispatcher hash = 31*hash + Float.hashCode(radius); hash = 31*hash + level; hash = 31*hash + Float.hashCode(lineWidth); - + if (fa != 0.0) hash = 31*hash + fillColor; return hash; } } @@ -685,7 +697,7 @@ public class ShapeDispatcher public static class FillColorParam extends ColorParam { @Override - public boolean appliesTo(ExpiringShape shape) { return shape instanceof Box; } + public boolean appliesTo(ExpiringShape shape) { return shape instanceof Box || shape instanceof Sphere; } @Override public String identify() { return "fill"; } } @@ -693,7 +705,7 @@ public class ShapeDispatcher public static class FromParam extends Vec3Param { @Override - public boolean appliesTo(ExpiringShape shape) { return (shape instanceof Line) || (shape instanceof Box); } + public boolean appliesTo(ExpiringShape shape) { return shape instanceof Line || shape instanceof Box; } @Override public boolean roundsUpForBlocks() { return false; } @Override diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 8552ca7a..2070567c 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -9,7 +9,6 @@ import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.Entity; import net.minecraft.nbt.CompoundTag; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -50,45 +49,49 @@ public class ShapesRenderer DimensionType dimensionType = iWorld.getDimension().getType(); if (shapes.get(dimensionType).isEmpty()) return; long currentTime = client.world.getTime(); + RenderSystem.disableTexture(); RenderSystem.enableDepthTest(); + RenderSystem.depthFunc(515); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); //RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO); - RenderSystem.shadeModel(7425); + //RenderSystem.shadeModel(7425); + RenderSystem.shadeModel(GL11.GL_FLAT); RenderSystem.enableAlphaTest(); RenderSystem.defaultAlphaFunc(); - Entity entity = this.client.gameRenderer.getCamera().getFocusedEntity(); + //RenderSystem.alphaFunc(GL11.GL_GREATER, 0.005F); + RenderSystem.disableCull(); + RenderSystem.disableLighting(); + RenderSystem.depthMask(false); + RenderSystem.polygonOffset(-3f, -3f); + RenderSystem.enablePolygonOffset(); + //Entity entity = this.client.gameRenderer.getCamera().getFocusedEntity(); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferBuilder = tessellator.getBuffer(); - double d = 0.0D - cameraY; - double e = 256.0D - cameraY; - RenderSystem.disableTexture(); - //RenderSystem.disableBlend(); - double f = (double)(entity.chunkX << 4) - cameraX; - double g = (double)(entity.chunkZ << 4) - cameraZ; + // render synchronized (shapes) { shapes.get(dimensionType).int2ObjectEntrySet().removeIf( entry -> entry.getValue().isExpired(currentTime) ); - shapes.get(dimensionType).values().forEach( - s -> s.render(tessellator, bufferBuilder, (float) cameraX, (float) cameraY, (float) cameraZ) - ); shapes.get(dimensionType).values().forEach( s -> s.render2pass(tessellator, bufferBuilder, (float) cameraX, (float) cameraY, (float) cameraZ) ); + //lines + shapes.get(dimensionType).values().forEach( + s -> s.render(tessellator, bufferBuilder, (float) cameraX, (float) cameraY, (float) cameraZ) + ); } - RenderSystem.lineWidth(1.0F); RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); RenderSystem.enableTexture(); RenderSystem.shadeModel(7424); } public void addShape(CompoundTag tag) { - //CarpetSettings.LOG.error("Received tag: "+tag.asString()); ShapeDispatcher.ExpiringShape shape = ShapeDispatcher.fromTag(tag); if (shape == null) return; BiFunction> shapeFactory; @@ -160,14 +163,13 @@ public class ShapesRenderer @Override public void render(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz) { + if (shape.a == 0.0) return; RenderSystem.lineWidth(shape.lineWidth); - drawBoxWireGLLines(tessellator, bufferBuilder, shape.x1 - cx-renderEpsilon, shape.y1 - cy-renderEpsilon, shape.z1 - cz-renderEpsilon, shape.x2 - cx+renderEpsilon, shape.y2 - cy+renderEpsilon, shape.z2 - cz+renderEpsilon, shape.r, shape.g, shape.b, shape.a, shape.r, shape.g, shape.b ); - tessellator.draw(); } @Override public void render2pass(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz) @@ -211,12 +213,23 @@ public class ShapesRenderer @Override public void render(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz) { + if (shape.a == 0.0) return; RenderSystem.lineWidth(shape.lineWidth); drawSphereWireframe(tessellator, bufferBuilder, shape.cx-cx-renderEpsilon, shape.cy-cy-renderEpsilon, shape.cz-cz-renderEpsilon, shape.radius, shape.subdivisions, shape.r, shape.g, shape.b, shape.a); } + @Override + public void render2pass(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz) + { + if (shape.fa == 0.0) return; + RenderSystem.lineWidth(1.0f); + drawSphereFaces(tessellator, bufferBuilder, + shape.cx-cx-renderEpsilon, shape.cy-cy-renderEpsilon, shape.cz-cz-renderEpsilon, + shape.radius, shape.subdivisions, + shape.fr, shape.fg, shape.fb, shape.fa); + } } // some raw shit @@ -225,10 +238,10 @@ public class ShapesRenderer builder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR); // 3 builder.vertex(x1, y1, z1).color(red1, grn1, blu1, alpha).next(); builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next(); - tessellator.draw(); } - public static void drawBoxWireGLLines(Tessellator tessellator, BufferBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float red1, float grn1, float blu1, float alpha, float red2, float grn2, float blu2) { + public static void drawBoxWireGLLines(Tessellator tessellator, BufferBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float red1, float grn1, float blu1, float alpha, float red2, float grn2, float blu2) + { builder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR); // 3 builder.vertex(x1, y1, z1).color(red1, grn2, blu2, alpha).next(); builder.vertex(x2, y1, z1).color(red1, grn2, blu2, alpha).next(); @@ -254,24 +267,26 @@ public class ShapesRenderer builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next(); builder.vertex(x2, y2, z1).color(red1, grn1, blu1, alpha).next(); builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next(); + tessellator.draw(); } - public static void drawBoxFaces(Tessellator tessellator, BufferBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float red1, float grn1, float blu1, float alpha) { - builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR); // 3 + public static void drawBoxFaces(Tessellator tessellator, BufferBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float red1, float grn1, float blu1, float alpha) + { + builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR); builder.vertex(x1, y1, z1).color(red1, grn1, blu1, alpha).next(); builder.vertex(x2, y1, z1).color(red1, grn1, blu1, alpha).next(); builder.vertex(x2, y2, z1).color(red1, grn1, blu1, alpha).next(); builder.vertex(x1, y2, z1).color(red1, grn1, blu1, alpha).next(); builder.vertex(x1, y1, z2).color(red1, grn1, blu1, alpha).next(); - builder.vertex(x2, y1, z2).color(red1, grn1, blu1, alpha).next(); - builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next(); builder.vertex(x1, y2, z2).color(red1, grn1, blu1, alpha).next(); + builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next(); + builder.vertex(x2, y1, z2).color(red1, grn1, blu1, alpha).next(); builder.vertex(x1, y1, z1).color(red1, grn1, blu1, alpha).next(); - builder.vertex(x1, y1, z2).color(red1, grn1, blu1, alpha).next(); - builder.vertex(x1, y2, z2).color(red1, grn1, blu1, alpha).next(); builder.vertex(x1, y2, z1).color(red1, grn1, blu1, alpha).next(); + builder.vertex(x1, y2, z2).color(red1, grn1, blu1, alpha).next(); + builder.vertex(x1, y1, z2).color(red1, grn1, blu1, alpha).next(); builder.vertex(x2, y1, z1).color(red1, grn1, blu1, alpha).next(); builder.vertex(x2, y1, z2).color(red1, grn1, blu1, alpha).next(); @@ -279,9 +294,9 @@ public class ShapesRenderer builder.vertex(x2, y2, z1).color(red1, grn1, blu1, alpha).next(); builder.vertex(x1, y1, z1).color(red1, grn1, blu1, alpha).next(); - builder.vertex(x2, y1, z1).color(red1, grn1, blu1, alpha).next(); - builder.vertex(x2, y1, z2).color(red1, grn1, blu1, alpha).next(); builder.vertex(x1, y1, z2).color(red1, grn1, blu1, alpha).next(); + builder.vertex(x2, y1, z2).color(red1, grn1, blu1, alpha).next(); + builder.vertex(x2, y1, z1).color(red1, grn1, blu1, alpha).next(); builder.vertex(x1, y2, z1).color(red1, grn1, blu1, alpha).next(); builder.vertex(x2, y2, z1).color(red1, grn1, blu1, alpha).next(); @@ -327,4 +342,31 @@ public class ShapesRenderer } } + + public static void drawSphereFaces(Tessellator tessellator, BufferBuilder builder, + float cx, float cy, float cz, + float r, int subd, + float red, float grn, float blu, float alpha) + { + float pihalf = (float)(Math.PI / 180.0f); + float step = 180f / (subd/2); + for (float i = 0f; i < 359.99f; i += step) + { + float theta = i * pihalf; + float thetaprime = (i + step) * pihalf; + builder.begin(GL11.GL_QUAD_STRIP, VertexFormats.POSITION_COLOR); + for (float j = 0f; j < 179.9f; j += step) + { + float phi = j * pihalf; + float x = r * MathHelper.sin(phi) * MathHelper.cos(theta); + float z = r * MathHelper.sin(phi) * MathHelper.sin(theta); + float y = r * MathHelper.cos(phi); + float xp = r * MathHelper.sin(phi) * MathHelper.cos(thetaprime); + float zp = r * MathHelper.sin(phi) * MathHelper.sin(thetaprime); + builder.vertex(x + cx, y + cy, z + cz).color(red, grn, blu, alpha).next(); + builder.vertex(xp + cx, y + cy, zp + cz).color(red, grn, blu, alpha).next(); + } + tessellator.draw(); + } + } } diff --git a/src/main/resources/assets/carpet/scripts/overlay.sc b/src/main/resources/assets/carpet/scripts/overlay.sc index fb6b5a52..81b42749 100644 --- a/src/main/resources/assets/carpet/scripts/overlay.sc +++ b/src/main/resources/assets/carpet/scripts/overlay.sc @@ -6,7 +6,7 @@ global_renderers = m( l('handler', '__structure_renderer'), l('tasks', m()), l('range', 3), - l('max_pieces', 4) + l('max_pieces', 6) )), l('chunks', m( l('active', false), @@ -94,20 +94,16 @@ __structure_renderer(player_name) -> l(from, to) = structure_data; total_size = _euclidean(from, to); density = max(10, total_size/10); - //particle_box('dust 0 1 1 2', from, to+1, density); - draw_shape('box', 15, 'from', from, 'to', to+1, 'color', 0x00FFFFFF, 'width', 3); + draw_shape('box', 15, 'from', from, 'to', to+1, 'color', 0x00FFFFFF, 'width', 3, 'fill', 0x00FFFF22); structure_pieces = slice(sort_key(structure_pieces, _euclidean_sq((_:2+_:3)/2,ppos)), 0, config:'max_pieces'); for (structure_pieces, l(piece, direction, from, to) = _; - //factor = 1- _i / config:'max_pieces' / 2; - //total_size = _euclidean(from, to); - //density = max(_i+1, total_size/10); - //particle_box(str('dust %.2f %.2f 1 1',factor, factor), from, to+1, density); - r = 255 - 128 * _i/config:'max_pieces'; + r = 255 - floor(128 * _i/config:'max_pieces'); g = r; b = 255; a = 255; color = 256*(b+256*(g+256*r)); // leaving out a - draw_shape('box', 15, 'from', from, 'to', to+1, 'color', color+a, 'fill', color+a/6); + draw_shape('box', 15, 'from', from, 'to', to+1, 'color', color+a); + draw_shape('box', 15, 'from', from, 'to', to+1, 'color', 0xffffff00, 'fill', 0xffffff22); ) ) ); @@ -143,15 +139,6 @@ __chunk_renderer(player_name) -> draw_shape('line', 15, 'from', top_01, 'to', top_00, 'color', color, 'width', 3); draw_shape('line', 15, 'from', top_00, 'to', top_11, 'color', color, 'width', 3); draw_shape('line', 15, 'from', top_01, 'to', top_10, 'color', color, 'width', 3); - - //part = 'dust 0.2 0.8 0.2 2'; - //density = 2+player_distance/2; - //particle_line(part, top_00, top_10, density); - //particle_line(part, top_10, top_11, density); - //particle_line(part, top_11, top_01, density); - //particle_line(part, top_01, top_00, density); - //particle_line(part, top_00, top_11, density); - //particle_line(part, top_01, top_10, density); ) ) )