Skip to content

Commit 8d4d97e

Browse files
committed
1.21.5 support (#9)
Closes #9
1 parent c899b98 commit 8d4d97e

File tree

5 files changed

+143
-15
lines changed

5 files changed

+143
-15
lines changed

src/main/java/com/github/simulatan/meteornotificationsaddon/hud/NotificationsHudElement.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import javax.annotation.Nullable;
2121
import java.lang.reflect.Field;
22+
import java.util.LinkedList;
2223
import java.util.List;
2324

2425
public class NotificationsHudElement extends HudElement {
@@ -185,7 +186,7 @@ public enum VerticalAlign {
185186
public final Setting<List<Module>> modules = sgGeneral.add(new ModuleListSetting.Builder()
186187
.name("Modules to display")
187188
.description("The modules to display in the notifications.")
188-
.defaultValue(Modules.get().getList())
189+
.defaultValue(new LinkedList<>(Modules.get().getAll()))
189190
.build()
190191
);
191192

@@ -290,7 +291,7 @@ public void render(HudRenderer renderer) {
290291
else
291292
DrawUtils.drawQuad(x, y + notificationHeight, progress, progressBarHeight, new Color(notification.getColor()));
292293

293-
DrawUtils.renderer.render(null);
294+
DrawUtils.renderer.render();
294295

295296
final @Nullable String description = notification.getDescription();
296297

src/main/java/com/github/simulatan/meteornotificationsaddon/mixins/MeshMixin.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package com.github.simulatan.meteornotificationsaddon.mixins;
22

33
import com.github.simulatan.meteornotificationsaddon.utils.MeshAccessor;
4-
import meteordevelopment.meteorclient.renderer.Mesh;
4+
import meteordevelopment.meteorclient.renderer.MeshBuilder;
55
import org.spongepowered.asm.mixin.Mixin;
66
import org.spongepowered.asm.mixin.gen.Accessor;
77

8-
@Mixin(Mesh.class)
8+
@Mixin(MeshBuilder.class)
99
public interface MeshMixin extends MeshAccessor {
10-
@Accessor(remap = false)
11-
int getIndicesCount();
12-
1310
@Accessor(remap = false)
1411
long getIndicesPointer();
1512

src/main/java/com/github/simulatan/meteornotificationsaddon/utils/DrawUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.simulatan.meteornotificationsaddon.utils;
22

3+
import meteordevelopment.meteorclient.renderer.Renderer2D;
34
import meteordevelopment.meteorclient.renderer.text.TextRenderer;
45
import meteordevelopment.meteorclient.utils.render.color.Color;
56

@@ -77,18 +78,18 @@ public static double render(String text, double x, double y, java.awt.Color colo
7778
return width;
7879
}
7980

80-
public static Renderer2DQuad renderer;
81+
public static Renderer2D renderer;
8182

8283
public static void init() {
83-
renderer = new Renderer2DQuad(false);
84+
renderer = new Renderer2D(false);
8485
}
8586

8687
public static void drawRoundedQuad(double x, double y, double width, double height, double radius, Color color) {
87-
renderer.quadRounded(x, y, width, height, color, radius, true);
88+
RoundedRenderer2D.quadRounded(renderer, x, y, width, height, color, radius, true);
8889
}
8990

9091
public static void drawRoundedQuad(double x, double y, double width, double height, double radius, Color color, boolean roundTop) {
91-
renderer.quadRounded(x, y, width, height, color, radius, roundTop);
92+
RoundedRenderer2D.quadRounded(renderer, x, y, width, height, color, radius, roundTop);
9293
}
9394

9495
public static void drawQuad(double x, double y, double width, double height, Color color) {

src/main/java/com/github/simulatan/meteornotificationsaddon/utils/Renderer2DQuad.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.simulatan.meteornotificationsaddon.utils;
22

33
import com.github.simulatan.meteornotificationsaddon.mixins.MeshMixin;
4-
import meteordevelopment.meteorclient.renderer.Mesh;
4+
import meteordevelopment.meteorclient.renderer.MeshBuilder;
55
import meteordevelopment.meteorclient.renderer.Renderer2D;
66
import meteordevelopment.meteorclient.utils.render.color.Color;
77

@@ -109,15 +109,15 @@ public void circlePart(double x, double y, double r, double startAngle, double a
109109
}
110110
}
111111

112-
public static void triangle(int i1, int i2, int i3, Mesh entity) {
112+
public static void triangle(int i1, int i2, int i3, MeshBuilder entity) {
113113
MeshMixin accessor = (MeshMixin) entity;
114-
long p = accessor.getIndicesPointer() + accessor.getIndicesCount() * 4L;
114+
long p = accessor.getIndicesPointer() + entity.getIndicesCount() * 4L;
115115

116116
memPutInt(p, i1);
117117
memPutInt(p + 4, i2);
118118
memPutInt(p + 8, i3);
119119

120-
accessor.setIndicesCount(accessor.getIndicesCount() + 3);
120+
accessor.setIndicesCount(entity.getIndicesCount() + 3);
121121
accessor.growIfNeeded();
122122
}
123123

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package com.github.simulatan.meteornotificationsaddon.utils;
2+
3+
import meteordevelopment.meteorclient.renderer.Renderer2D;
4+
import meteordevelopment.meteorclient.utils.render.color.Color;
5+
6+
public class RoundedRenderer2D {
7+
8+
private static final double circleNone = 0;
9+
private static final double circleQuarter = Math.PI / 2;
10+
private static final double circleHalf = circleQuarter * 2;
11+
private static final double circleThreeQuarter = circleQuarter * 3;
12+
13+
public static void quadRoundedOutline(Renderer2D mb, double x, double y, double width, double height, Color color, double r, double s) {
14+
r = getR(r, width, height);
15+
if (r <= 0) {
16+
mb.quad(x, y, width, s, color);
17+
mb.quad(x, y + height - s, width, s, color);
18+
mb.quad(x, y + s, s, height - s * 2, color);
19+
mb.quad(x + width - s, y + s, s, height - s * 2, color);
20+
}
21+
else {
22+
//top
23+
circlePartOutline(mb, x + r, y + r, r, circleThreeQuarter, circleQuarter, color, s);
24+
mb.quad(x + r, y, width - r * 2, s, color);
25+
circlePartOutline(mb, x + width - r, y + r, r, circleNone, circleQuarter, color, s);
26+
//middle
27+
mb.quad(x, y + r, s, height - r * 2, color);
28+
mb.quad(x + width - s, y + r, s, height - r * 2, color);
29+
//bottom
30+
circlePartOutline(mb, x + width - r, y + height - r, r, circleQuarter, circleQuarter, color, s);
31+
mb.quad(x + r, y + height - s, width - r * 2, s, color);
32+
circlePartOutline(mb, x + r, y + height - r, r, circleHalf, circleQuarter, color, s);
33+
}
34+
}
35+
36+
public static void quadRounded(Renderer2D mb, double x, double y, double width, double height, Color color, double r, boolean roundTop) {
37+
r = getR(r, width, height);
38+
if (r <= 0)
39+
mb.quad(x, y, width, height, color);
40+
else {
41+
if (roundTop) {
42+
//top
43+
circlePart(mb, x + r, y + r, r, circleThreeQuarter, circleQuarter, color);
44+
mb.quad(x + r, y, width - 2 * r, r, color);
45+
circlePart(mb, x + width - r, y + r, r, circleNone, circleQuarter, color);
46+
//middle
47+
mb.quad(x, y + r, width, height - 2 * r, color);
48+
}
49+
else {
50+
//middle
51+
mb.quad(x, y, width, height - r, color);
52+
}
53+
//bottom
54+
circlePart(mb, x + width - r, y + height - r, r, circleQuarter, circleQuarter, color);
55+
mb.quad(x + r, y + height - r, width - 2 * r, r, color);
56+
circlePart(mb, x + r, y + height - r, r, circleHalf, circleQuarter, color);
57+
}
58+
}
59+
60+
public static void quadRoundedSide(Renderer2D mb, double x, double y, double width, double height, Color color, double r, boolean right) {
61+
r = getR(r, width, height);
62+
if (r <= 0)
63+
mb.quad(x, y, width, height, color);
64+
else {
65+
if (right) {
66+
circlePart(mb, x + width - r, y + r, r, circleNone, circleQuarter, color);
67+
circlePart(mb, x + width - r, y + height - r, r, circleQuarter, circleQuarter, color);
68+
mb.quad(x, y, width - r, height, color);
69+
mb.quad(x + width - r, y + r, r, height - r * 2, color);
70+
}
71+
else {
72+
circlePart(mb, x + r, y + r, r, circleThreeQuarter, circleQuarter, color);
73+
circlePart(mb, x + r, y + height - r, r, circleHalf, circleQuarter, color);
74+
mb.quad(x + r, y, width - r, height, color);
75+
mb.quad(x, y + r, r, height - r * 2, color);
76+
}
77+
}
78+
}
79+
80+
private static double getR(double r, double w, double h) {
81+
if (r * 2 > h) {
82+
r = h / 2;
83+
}
84+
if (r * 2 > w) {
85+
r = w / 2;
86+
}
87+
return r;
88+
}
89+
90+
private static int getCirDepth(double r, double angle) {
91+
return Math.max(1, (int)(angle * r / circleQuarter));
92+
}
93+
94+
public static void circlePart(Renderer2D mb, double x, double y, double r, double startAngle, double angle, Color color) {
95+
int cirDepth = getCirDepth(r, angle);
96+
double cirPart = angle / cirDepth;
97+
mb.triangles.ensureTriCapacity();
98+
int center = mb.triangles.vec2(x, y).color(color).next();
99+
int prev = vecOnCircle(mb, x, y, r, startAngle, color);
100+
for (int i = 1; i < cirDepth + 1; i++) {
101+
int next = vecOnCircle(mb, x, y, r, startAngle + cirPart * i, color);
102+
mb.triangles.quad(prev, center, next, next);
103+
prev = next;
104+
}
105+
}
106+
107+
public static void circlePartOutline(Renderer2D mb, double x, double y, double r, double startAngle, double angle, Color color, double outlineWidth) {
108+
if (outlineWidth >= r) {
109+
circlePart(mb, x, y, r, startAngle, angle, color);
110+
return;
111+
}
112+
int cirDepth = getCirDepth(r, angle);
113+
double cirPart = angle / cirDepth;
114+
int innerPrev = vecOnCircle(mb, x, y, r - outlineWidth, startAngle, color);
115+
int outerPrev = vecOnCircle(mb, x, y, r, startAngle, color);
116+
for (int i = 1; i < cirDepth + 1; i++) {
117+
int inner = vecOnCircle(mb, x, y, r - outlineWidth, startAngle + cirPart * i, color);
118+
int outer = vecOnCircle(mb, x, y, r, startAngle + cirPart * i, color);
119+
mb.triangles.quad(inner, innerPrev, outerPrev, outer);
120+
innerPrev = inner;
121+
outerPrev = outer;
122+
}
123+
}
124+
125+
private static int vecOnCircle(Renderer2D mb, double x, double y, double r, double angle, Color color) {
126+
mb.triangles.ensureTriCapacity();
127+
return mb.triangles.vec2(x + Math.sin(angle) * r, y - Math.cos(angle) * r).color(color).next();
128+
}
129+
}

0 commit comments

Comments
 (0)