Merge branch 'master' into 1.16

This commit is contained in:
gnembon committed 2020-06-10 12:31:00 -03:00
commit 2912fd2936
3 files changed
+248 -19

No files matched your search

+10 -1
View File
@@ -88,13 +88,22 @@ Available shapes:
* `from` - triple coordinates, entity, or block value indicating one corner of the box * `from` - triple coordinates, entity, or block value indicating one corner of the box
* `to` - other corner, same format as `from` * `to` - other corner, same format as `from`
* `'sphere'` - draws a sphere * `'sphere'`:
* Required attributes: * Required attributes:
* `center` - center of the sphere * `center` - center of the sphere
* `radius` - radius of the sphere * `radius` - radius of the sphere
* Optional attributes: * Optional attributes:
* `level` - level of details, or grid size. The more the denser your sphere. Default level of 0, means that the * `level` - level of details, or grid size. The more the denser your sphere. Default level of 0, means that the
level of detail will be selected automatically based on radius. level of detail will be selected automatically based on radius.
* `'cylinder'`:
* Required attributes:
* `center` - center of the base
* `radius` - radius of the base circle
* Optional attributes:
* `axis` - cylinder direction, one of `'x'`, `'y'`, `'z'` defaults to `'y'`
* `height` - height of the cyllinder, defaults to `0`, so flat disk. Can be negative.
* `level` - level of details, see `'sphere'`.
### `create_marker(text, pos, rotation?, block?)` ### `create_marker(text, pos, rotation?, block?)`
@@ -716,7 +716,7 @@ public class ShapeDispatcher
put("center", new Vec3Param("center", false)); put("center", new Vec3Param("center", false));
put("radius", new PositiveFloatParam("radius")); put("radius", new PositiveFloatParam("radius"));
put("level", new PositiveIntParam("level")); put("level", new PositiveIntParam("level"));
put("height", new NonNegativeFloatParam("height")); put("height", new FloatParam("height"));
put("axis", new StringChoiceParam("axis", "x", "y", "z")); put("axis", new StringChoiceParam("axis", "x", "y", "z"));
put("points", new PointsParam("points")); put("points", new PointsParam("points"));
}}; }};
@@ -790,6 +790,15 @@ public class ShapeDispatcher
return value; return value;
} }
} }
public static class FloatParam extends NumericParam
{
protected FloatParam(String id) { super(id); }
@Override
public Value decode(Tag tag) { return new NumericValue(((FloatTag)tag).getFloat()); }
@Override
public Tag toTag(Value value) { return FloatTag.of(NumericValue.asNumber(value, id).getFloat()); }
}
public static abstract class PositiveParam extends NumericParam public static abstract class PositiveParam extends NumericParam
{ {
protected PositiveParam(String id) { super(id); } protected PositiveParam(String id) { super(id); }
@@ -847,6 +856,9 @@ public class ShapeDispatcher
} }
} }
public static class Vec3Param extends Param public static class Vec3Param extends Param
{ {
private boolean roundsUpForBlocks; private boolean roundsUpForBlocks;
@@ -261,8 +261,8 @@ public class ShapesRenderer
Vec3d vc = shape.relativiseRender(client.world, shape.center, partialTick); Vec3d vc = shape.relativiseRender(client.world, shape.center, partialTick);
RenderSystem.lineWidth(shape.lineWidth); RenderSystem.lineWidth(shape.lineWidth);
drawSphereWireframe(tessellator, bufferBuilder, drawSphereWireframe(tessellator, bufferBuilder,
(float)(vc.x-cx-renderEpsilon), (float)(vc.y-cy-renderEpsilon), (float)(vc.z-cz-renderEpsilon), (float)(vc.x-cx), (float)(vc.y-cy), (float)(vc.z-cz),
shape.radius, shape.subdivisions, (float)(shape.radius+renderEpsilon), shape.subdivisions,
shape.r, shape.g, shape.b, shape.a); shape.r, shape.g, shape.b, shape.a);
} }
@Override @Override
@@ -272,8 +272,8 @@ public class ShapesRenderer
Vec3d vc = shape.relativiseRender(client.world, shape.center, partialTick); Vec3d vc = shape.relativiseRender(client.world, shape.center, partialTick);
RenderSystem.lineWidth(1.0f); RenderSystem.lineWidth(1.0f);
drawSphereFaces(tessellator, bufferBuilder, drawSphereFaces(tessellator, bufferBuilder,
(float)(vc.x-cx-renderEpsilon), (float)(vc.y-cy-renderEpsilon), (float)(vc.z-cz-renderEpsilon), (float)(vc.x-cx), (float)(vc.y-cy), (float)(vc.z-cz),
shape.radius, shape.subdivisions, (float)(shape.radius+renderEpsilon), shape.subdivisions,
shape.fr, shape.fg, shape.fb, shape.fa); shape.fr, shape.fg, shape.fb, shape.fa);
} }
} }
@@ -290,21 +290,26 @@ public class ShapesRenderer
if (shape.a == 0.0) return; if (shape.a == 0.0) return;
Vec3d vc = shape.relativiseRender(client.world, shape.center, partialTick); Vec3d vc = shape.relativiseRender(client.world, shape.center, partialTick);
RenderSystem.lineWidth(shape.lineWidth); RenderSystem.lineWidth(shape.lineWidth);
double dir = MathHelper.sign(shape.height);
drawCylinderWireframe(tessellator, bufferBuilder, drawCylinderWireframe(tessellator, bufferBuilder,
(float)(vc.x-cx-renderEpsilon), (float)(vc.y-cy-renderEpsilon), (float)(vc.z-cz-renderEpsilon), (float) (vc.x - cx - dir * renderEpsilon), (float) (vc.y - cy - dir * renderEpsilon), (float) (vc.z - cz - dir * renderEpsilon),
shape.radius, shape.height, shape.axis, shape.subdivisions, (float) (shape.radius + renderEpsilon), (float) (shape.height + 2*dir*renderEpsilon), shape.axis,
shape.subdivisions, shape.radius == 0,
shape.r, shape.g, shape.b, shape.a); shape.r, shape.g, shape.b, shape.a);
} }
@Override @Override
public void renderFaces(Tessellator tessellator, BufferBuilder bufferBuilder, double cx, double cy, double cz, float partialTick) public void renderFaces(Tessellator tessellator, BufferBuilder bufferBuilder, double cx, double cy, double cz, float partialTick)
{ {
if (shape.fa == 0.0) return; if (shape.fa == 0.0) return;
//Vec3d vc = shape.relativiseRender(client.world, shape.center, partialTick); Vec3d vc = shape.relativiseRender(client.world, shape.center, partialTick);
//RenderSystem.lineWidth(1.0f); RenderSystem.lineWidth(1.0f);
//drawSphereFaces(tessellator, bufferBuilder, double dir = MathHelper.sign(shape.height);
// (float)(vc.x-cx-renderEpsilon), (float)(vc.y-cy-renderEpsilon), (float)(vc.z-cz-renderEpsilon), drawCylinderFaces(tessellator, bufferBuilder,
// shape.radius, shape.subdivisions, (float) (vc.x - cx - dir * renderEpsilon), (float) (vc.y - cy - dir * renderEpsilon), (float) (vc.z - cz - dir * renderEpsilon),
// shape.fr, shape.fg, shape.fb, shape.fa); (float) (shape.radius + renderEpsilon), (float) (shape.height + 2*dir*renderEpsilon), shape.axis,
shape.subdivisions, shape.radius == 0,
shape.fr, shape.fg, shape.fb, shape.fa);
} }
} }
@@ -433,15 +438,19 @@ public class ShapesRenderer
public static void drawCylinderWireframe(Tessellator tessellator, BufferBuilder builder, public static void drawCylinderWireframe(Tessellator tessellator, BufferBuilder builder,
float cx, float cy, float cz, float cx, float cy, float cz,
float r, float h, Direction.Axis axis, int subd, float r, float h, Direction.Axis axis, int subd, boolean isFlat,
float red, float grn, float blu, float alpha) float red, float grn, float blu, float alpha)
{ {
float step = (float)Math.PI / (subd/2); float step = (float)Math.PI / (subd/2);
int num_steps180 = (int)(Math.PI / step)+1; int num_steps180 = (int)(Math.PI / step)+1;
int num_steps360 = (int)(2*Math.PI / step); int num_steps360 = (int)(2*Math.PI / step);
int hsteps = (h>0) ? ((int)Math.ceil(h / (step*r))+1) : 1; int hsteps = 1;
float hstep = (h>0) ? (h / (hsteps-1)) : 1; float hstep = 1.0f;
// draw base if (!isFlat)
{
hsteps = (int) Math.ceil(MathHelper.abs(h) / (step * r)) + 1;
hstep = h / (hsteps - 1);
}// draw base
if (axis == Direction.Axis.Y) if (axis == Direction.Axis.Y)
{ {
@@ -460,7 +469,7 @@ public class ShapesRenderer
tessellator.draw(); tessellator.draw();
} }
if (h > 0) if (!isFlat)
{ {
for (int i = 0; i <= num_steps180; i++) for (int i = 0; i <= num_steps180; i++)
{ {
@@ -477,6 +486,19 @@ public class ShapesRenderer
tessellator.draw(); tessellator.draw();
} }
} }
else
{
builder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR);
for (int i = 0; i <= num_steps180; i++)
{
float theta = step * i;
float x = r * MathHelper.cos(theta);
float z = r * MathHelper.sin(theta);
builder.vertex(cx - x, cy, cz + z).color(red, grn, blu, alpha).next();
builder.vertex(cx + x, cy, cz - z).color(red, grn, blu, alpha).next();
}
tessellator.draw();
}
} }
else if (axis == Direction.Axis.X) else if (axis == Direction.Axis.X)
@@ -495,6 +517,37 @@ public class ShapesRenderer
} }
tessellator.draw(); tessellator.draw();
} }
if (!isFlat)
{
for (int i = 0; i <= num_steps180; i++)
{
builder.begin(GL11.GL_LINE_LOOP, VertexFormats.POSITION_COLOR);
float theta = step * i;
float y = r * MathHelper.cos(theta);
float z = r * MathHelper.sin(theta);
builder.vertex(cx + 0, cy - y, cz + z).color(red, grn, blu, alpha).next();
builder.vertex(cx + 0, cy + y, cz - z).color(red, grn, blu, alpha).next();
builder.vertex(cx + h, cy + y, cz - z).color(red, grn, blu, alpha).next();
builder.vertex(cx + h, cy - y, cz + z).color(red, grn, blu, alpha).next();
tessellator.draw();
}
}
else
{
builder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR);
for (int i = 0; i <= num_steps180; i++)
{
float theta = step * i;
float y = r * MathHelper.cos(theta);
float z = r * MathHelper.sin(theta);
builder.vertex(cx, cy - y, cz + z).color(red, grn, blu, alpha).next();
builder.vertex(cx, cy + y, cz - z).color(red, grn, blu, alpha).next();
}
tessellator.draw();
}
} }
else if (axis == Direction.Axis.Z) else if (axis == Direction.Axis.Z)
{ {
@@ -512,6 +565,161 @@ public class ShapesRenderer
} }
tessellator.draw(); tessellator.draw();
} }
if (!isFlat)
{
for (int i = 0; i <= num_steps180; i++)
{
builder.begin(GL11.GL_LINE_LOOP, VertexFormats.POSITION_COLOR);
float theta = step * i;
float x = r * MathHelper.cos(theta);
float y = r * MathHelper.sin(theta);
builder.vertex(cx + x, cy - y, cz + 0).color(red, grn, blu, alpha).next();
builder.vertex(cx - x, cy + y, cz + 0).color(red, grn, blu, alpha).next();
builder.vertex(cx - x, cy + y, cz + h).color(red, grn, blu, alpha).next();
builder.vertex(cx + x, cy - y, cz + h).color(red, grn, blu, alpha).next();
tessellator.draw();
}
}
else
{
builder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR);
for (int i = 0; i <= num_steps180; i++)
{
float theta = step * i;
float x = r * MathHelper.cos(theta);
float y = r * MathHelper.sin(theta);
builder.vertex(cx + x, cy - y, cz).color(red, grn, blu, alpha).next();
builder.vertex(cx - x, cy + y, cz).color(red, grn, blu, alpha).next();
}
tessellator.draw();
}
}
}
public static void drawCylinderFaces(Tessellator tessellator, BufferBuilder builder,
float cx, float cy, float cz,
float r, float h, Direction.Axis axis, int subd, boolean isFlat,
float red, float grn, float blu, float alpha)
{
float step = (float)Math.PI / (subd/2);
int num_steps180 = (int)(Math.PI / step)+1;
int num_steps360 = (int)(2*Math.PI / step)+1;
if (axis == Direction.Axis.Y)
{
builder.begin(GL11.GL_TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
builder.vertex(cx, cy, cz).color(red, grn, blu, alpha).next();
for (int i = 0; i <= num_steps360; i++)
{
float theta = step * i;
float x = r * MathHelper.cos(theta);
float z = r * MathHelper.sin(theta);
builder.vertex(x + cx, cy, z + cz).color(red, grn, blu, alpha).next();
}
tessellator.draw();
if (!isFlat)
{
builder.begin(GL11.GL_TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
builder.vertex(cx, cy+h, cz).color(red, grn, blu, alpha).next();
for (int i = 0; i <= num_steps360; i++)
{
float theta = step * i;
float x = r * MathHelper.cos(theta);
float z = r * MathHelper.sin(theta);
builder.vertex(x + cx, cy+h, z + cz).color(red, grn, blu, alpha).next();
}
tessellator.draw();
builder.begin(GL11.GL_QUAD_STRIP, VertexFormats.POSITION_COLOR);
for (int i = 0; i <= num_steps360; i++)
{
float theta = step * i;
float x = r * MathHelper.cos(theta);
float z = r * MathHelper.sin(theta);
builder.vertex(cx + x, cy + 0, cz + z).color(red, grn, blu, alpha).next();
builder.vertex(cx + x, cy + h, cz + z).color(red, grn, blu, alpha).next();
}
tessellator.draw();
}
}
else if (axis == Direction.Axis.X)
{
builder.begin(GL11.GL_TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
builder.vertex(cx, cy, cz).color(red, grn, blu, alpha).next();
for (int i = 0; i <= num_steps360; i++)
{
float theta = step * i;
float y = r * MathHelper.cos(theta);
float z = r * MathHelper.sin(theta);
builder.vertex(cx, cy + y, z + cz).color(red, grn, blu, alpha).next();
}
tessellator.draw();
if (!isFlat)
{
builder.begin(GL11.GL_TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
builder.vertex(cx+h, cy, cz).color(red, grn, blu, alpha).next();
for (int i = 0; i <= num_steps360; i++)
{
float theta = step * i;
float y = r * MathHelper.cos(theta);
float z = r * MathHelper.sin(theta);
builder.vertex(cx+h, cy + y, cz + z).color(red, grn, blu, alpha).next();
}
tessellator.draw();
builder.begin(GL11.GL_QUAD_STRIP, VertexFormats.POSITION_COLOR);
for (int i = 0; i <= num_steps360; i++)
{
float theta = step * i;
float y = r * MathHelper.cos(theta);
float z = r * MathHelper.sin(theta);
builder.vertex(cx + 0, cy + y, cz + z).color(red, grn, blu, alpha).next();
builder.vertex(cx + h, cy + y, cz + z).color(red, grn, blu, alpha).next();
}
tessellator.draw();
}
}
else if (axis == Direction.Axis.Z)
{
builder.begin(GL11.GL_TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
builder.vertex(cx, cy, cz).color(red, grn, blu, alpha).next();
for (int i = 0; i <= num_steps360; i++)
{
float theta = step * i;
float x = r * MathHelper.cos(theta);
float y = r * MathHelper.sin(theta);
builder.vertex(x + cx, cy+y, cz).color(red, grn, blu, alpha).next();
}
tessellator.draw();
if (!isFlat)
{
builder.begin(GL11.GL_TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
builder.vertex(cx, cy, cz+h).color(red, grn, blu, alpha).next();
for (int i = 0; i <= num_steps360; i++)
{
float theta = step * i;
float x = r * MathHelper.cos(theta);
float y = r * MathHelper.sin(theta);
builder.vertex(x + cx, cy+y, cz+h).color(red, grn, blu, alpha).next();
}
tessellator.draw();
builder.begin(GL11.GL_QUAD_STRIP, VertexFormats.POSITION_COLOR);
for (int i = 0; i <= num_steps360; i++)
{
float theta = step * i;
float x = r * MathHelper.cos(theta);
float y = r * MathHelper.sin(theta);
builder.vertex(cx + x, cy + y, cz + 0).color(red, grn, blu, alpha).next();
builder.vertex(cx + x, cy + y, cz + h).color(red, grn, blu, alpha).next();
}
tessellator.draw();
}
} }
} }