Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline Patterns feature and pattern rendering refactor-ish #764

Merged
merged 5 commits into from
Oct 25, 2024

Conversation

SamsTheNerd
Copy link
Member

See #708 for details. This is (mostly) the same but cleaned up into fewer commits.

@SamsTheNerd SamsTheNerd requested a review from Alwinfy September 29, 2024 20:44
@@ -73,6 +94,7 @@ public Component display(Tag tag) {
return Component.translatable("hexcasting.spelldata.entity.whoknows");
}
var nameJson = ctag.getString("name");
// return Component.literal(nameJson);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vestigial debug statement?

Comment on lines +182 to +183
Component.literal(bob.toString()).withStyle(ChatFormatting.WHITE))
.withStyle(ChatFormatting.GOLD);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent change?

Comment on lines +61 to +63
RenderType layer = RenderType.entityCutout(this.getTextureLocation(wallScroll));

var verts = bufSource.getBuffer(layer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did layer get extracted into a variable here?

Comment on lines +128 to +134
var tangent = p2.add(p1.negated()).normalized().scale(width * 0.5f);
var normal = new Vec2(-tangent.y, tangent.x);

var jlow = joinOffsets[i];
var jhigh = joinOffsets[i + 1];

var p1Down = p1.add(tangent.scale(Math.max(0f, jlow))).add(normal);
var p1Up = p1.add(tangent.scale(Math.max(0f, -jlow))).add(normal.negated());
var p2Down = p2.add(tangent.scale(Math.max(0f, jhigh)).negated()).add(normal);
var p2Up = p2.add(tangent.scale(Math.max(0f, -jhigh)).negated()).add(normal.negated());

// Draw the chamfer hexagon as two trapezoids
// the points are in different orders to keep clockwise
vertexCol(mat, normalMat, light, verts, color, p1);
vertexCol(mat, normalMat, light, verts, color, p2);
vertexCol(mat, normalMat, light, verts, color, p2Up);
vertexCol(mat, normalMat, light, verts, color, p1Up);

vertexCol(mat, normalMat, light, verts, color, p1);
vertexCol(mat, normalMat, light, verts, color, p1Down);
vertexCol(mat, normalMat, light, verts, color, p2Down);
vertexCol(mat, normalMat, light, verts, color, p2);

if (i > 0) {
var sangle = joinAngles[i];
var angle = Math.abs(sangle);
var rnormal = normal.negated();
var joinSteps = Mth.ceil(angle * 180 / (RenderLib.CAP_THETA * Mth.PI));
if (joinSteps < 1) continue;

if (sangle < 0) {
var prevVert = new Vec2(p1.x - rnormal.x, p1.y - rnormal.y);
for (var j = 1; j <= joinSteps; j++) {
var fan = RenderLib.rotate(rnormal, -sangle * ((float) j / joinSteps));
var fanShift = new Vec2(p1.x - fan.x, p1.y - fan.y);

vertexCol(mat, normalMat, light, verts, color, p1);
vertexCol(mat, normalMat, light, verts, color, p1);
vertexCol(mat, normalMat, light, verts, color, fanShift);
vertexCol(mat, normalMat, light, verts, color, prevVert);
prevVert = fanShift;
}
} else {
var startFan = RenderLib.rotate(normal, -sangle);
var prevVert = new Vec2(p1.x - startFan.x, p1.y - startFan.y);
for (var j = joinSteps - 1; j >= 0; j--) {
var fan = RenderLib.rotate(normal, -sangle * ((float) j / joinSteps));
var fanShift = new Vec2(p1.x - fan.x, p1.y - fan.y);

vertexCol(mat, normalMat, light, verts, color, p1);
vertexCol(mat, normalMat, light, verts, color, p1);
vertexCol(mat, normalMat, light, verts, color, fanShift);
vertexCol(mat, normalMat, light, verts, color, prevVert);
prevVert = fanShift;
}
}
}
}

for (var pair : new Vec2[][]{
{points.get(0), points.get(1)},
{points.get(points.size() - 1), points.get(points.size() - 2)}
}) {
var point = pair[0];
var prev = pair[1];

var tangent = point.add(prev.negated()).normalized().scale(0.5f * width);
var normal = new Vec2(-tangent.y, tangent.x);
var joinSteps = Mth.ceil(180f / RenderLib.CAP_THETA);
for (int j = joinSteps; j > 0; j--) {
var fan0 = RenderLib.rotate(normal, -Mth.PI * ((float) j / joinSteps));
var fan1 = RenderLib.rotate(normal, -Mth.PI * ((float) (j - 1) / joinSteps));

vertexCol(mat, normalMat, light, verts, color, point);
vertexCol(mat, normalMat, light, verts, color, point);
vertexCol(mat, normalMat, light, verts, color, point.add(fan1));
vertexCol(mat, normalMat, light, verts, color, point.add(fan0));
}
}
}

private static void theCoolerDrawSpot(Matrix4f mat, Matrix3f normal, int light, VertexConsumer verts,
Vec2 point, float radius, int color) {
var fracOfCircle = 6;
for (int i = 0; i < fracOfCircle; i++) {
// We do need rects, irritatingly
// so we do fake triangles
vertexCol(mat, normal, light, verts, color, point);
vertexCol(mat, normal, light, verts, color, point);
for (int j = 0; j <= 1; j++) {
var theta = (i - j) / (float) fracOfCircle * Mth.TWO_PI;
var rx = Mth.cos(theta) * radius + point.x;
var ry = Mth.sin(theta) * radius + point.y;
vertexCol(mat, normal, light, verts, color, new Vec2(rx, ry));
}
}
.color(0xffffffff)
.uv(u, v).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light)
.normal(normal, nx, ny, nz)
.endVertex();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent changes(again)

Comment on lines +145 to +148
// TODO did we want to un-hardcode this for accessibility reasons ?
public static boolean shouldDoStrokeGradient(){
return Screen.hasControlDown();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe switch this over to sprint bind?

Comment on lines +40 to +43
String escaped = regexMatch.group(1);
String dirString = regexMatch.group(2).toLowerCase().strip().replace("_", "");
String sizeModString = regexMatch.group(3);
String angleSigs = regexMatch.group(4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have named capturing groups and then index em with numbers?

@gamma-delta
Copy link
Collaborator

Sure LGTM I guess

@gamma-delta gamma-delta merged commit 2f0509d into main Oct 25, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants