Skip to content

Commit 75937cc

Browse files
committed
Batch and defer world space text rendering: reuse one persistent buffer flushed once per frame, consolidate glyphs, and drop per-label 4MB allocations. Speeds up every label hack
1 parent c7ab5fe commit 75937cc

14 files changed

Lines changed: 130 additions & 189 deletions

src/main/java/net/wurstclient/hacks/EntityCountHack.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.HashMap;
1414
import java.util.Map;
1515
import net.minecraft.client.gui.Font;
16-
import net.wurstclient.util.WurstBufferSource;
1716
import net.minecraft.network.protocol.Packet;
1817
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
1918
import net.minecraft.network.protocol.game.ClientboundBundlePacket;
@@ -507,27 +506,13 @@ private void drawWorldLabel(PoseStack matrices, String text, double x,
507506
matrices.scale(scale, -scale, scale);
508507

509508
Font font = MC.font;
510-
WurstBufferSource vcp = RenderUtils.getVCP();
511509
float halfWidth = font.width(text) / 2F;
512510
int bgAlpha = (int)(MC.options.getBackgroundOpacity(0.25F) * 255) << 24;
513511
var matrix = matrices.last().pose();
514512
int stroke = 0xCC000000;
515-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text,
516-
-halfWidth - 1, 0, stroke, false, matrix, vcp,
517-
Font.DisplayMode.SEE_THROUGH, 0, 0xF000F0);
518-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text,
519-
-halfWidth + 1, 0, stroke, false, matrix, vcp,
520-
Font.DisplayMode.SEE_THROUGH, 0, 0xF000F0);
521-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -halfWidth,
522-
-1, stroke, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
523-
0xF000F0);
524-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -halfWidth,
525-
1, stroke, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
526-
0xF000F0);
527-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -halfWidth,
528-
0, argb, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, bgAlpha,
529-
0xF000F0);
530-
vcp.endBatch();
513+
net.wurstclient.util.RenderUtils.drawOutlinedTextInBatch(font, text,
514+
-halfWidth, 0, argb, stroke, matrix, Font.DisplayMode.SEE_THROUGH,
515+
bgAlpha, 0xF000F0);
531516
matrices.popPose();
532517
}
533518

src/main/java/net/wurstclient/hacks/LogoutSpotsHack.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import net.minecraft.client.gui.Font;
1919
import net.minecraft.client.multiplayer.PlayerInfo;
2020
import net.minecraft.client.multiplayer.ServerData;
21-
import net.wurstclient.util.WurstBufferSource;
2221
import net.minecraft.world.entity.player.Player;
2322
import net.minecraft.world.phys.AABB;
2423
import net.wurstclient.Category;
@@ -340,13 +339,11 @@ private void drawWorldLabel(PoseStack matrices, String text, double x,
340339
.getCappedWorldLabelScale(scale, dist);
341340
matrices.scale(s, -s, s);
342341
Font tr = MC.font;
343-
WurstBufferSource vcp = net.wurstclient.util.RenderUtils.getVCP();
344342
float w = tr.width(text) / 2F;
345343
int bg = (int)(MC.options.getBackgroundOpacity(0.25F) * 255) << 24;
346344
var matrix = matrices.last().pose();
347345
net.wurstclient.util.RenderUtils.drawTextInBatch(tr, text, -w, 0, argb,
348-
false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, bg, 0xF000F0);
349-
vcp.endBatch();
346+
false, matrix, null, Font.DisplayMode.SEE_THROUGH, bg, 0xF000F0);
350347
matrices.popPose();
351348
}
352349

src/main/java/net/wurstclient/hacks/MobOwnersHack.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.UUID;
1414
import net.minecraft.network.chat.Component;
1515
import net.minecraft.client.gui.Font;
16-
import net.wurstclient.util.WurstBufferSource;
1716
import net.minecraft.world.entity.Entity;
1817
import net.minecraft.world.entity.Mob;
1918
import net.minecraft.world.entity.player.Player;
@@ -203,7 +202,6 @@ private void drawWorldLabel(PoseStack matrices, String text, double x,
203202
matrices.scale(s, -s, s);
204203

205204
Font font = MC.font;
206-
WurstBufferSource vcp = RenderUtils.getVCP();
207205
float w = font.width(text) / 2F;
208206
int baseAlpha = (argb >>> 24) & 0xFF;
209207
int bgAlpha =
@@ -213,23 +211,10 @@ private void drawWorldLabel(PoseStack matrices, String text, double x,
213211
(Math.max(0, Math.min(255, baseAlpha)) << 24) | 0x000000;
214212
var matrix = matrices.last().pose();
215213

216-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -w - 1, 0,
217-
strokeColor, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
218-
0xF000F0);
219-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -w + 1, 0,
220-
strokeColor, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
221-
0xF000F0);
222-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -w, -1,
223-
strokeColor, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
224-
0xF000F0);
225-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -w, 1,
226-
strokeColor, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
227-
0xF000F0);
228-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -w, 0,
229-
argb, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, bg,
214+
net.wurstclient.util.RenderUtils.drawOutlinedTextInBatch(font, text, -w,
215+
0, argb, strokeColor, matrix, Font.DisplayMode.SEE_THROUGH, bg,
230216
0xF000F0);
231217

232-
vcp.endBatch();
233218
matrices.popPose();
234219
}
235220
}

src/main/java/net/wurstclient/hacks/NbtSizeCounterHack.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
2020
import net.minecraft.client.input.MouseButtonEvent;
2121
import net.minecraft.client.multiplayer.ClientLevel;
22-
import net.wurstclient.util.WurstBufferSource;
2322
import net.minecraft.network.FriendlyByteBuf;
2423
import net.minecraft.network.RegistryFriendlyByteBuf;
2524
import net.minecraft.network.chat.Component;
@@ -752,7 +751,6 @@ private void drawWorldLabel(PoseStack matrices, String text, double x,
752751
matrices.scale(scale, -scale, scale);
753752

754753
Font tr = MC.font;
755-
WurstBufferSource vcp = RenderUtils.getVCP();
756754
float w = tr.width(text) / 2F;
757755
int baseAlpha = (argb >>> 24) & 0xFF;
758756
int bgAlpha =
@@ -761,21 +759,9 @@ private void drawWorldLabel(PoseStack matrices, String text, double x,
761759
var matrix = matrices.last().pose();
762760
int stroke = (Math.max(0, Math.min(255, baseAlpha)) << 24);
763761

764-
net.wurstclient.util.RenderUtils.drawTextInBatch(tr, text, -w - 1, 0,
765-
stroke, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
762+
net.wurstclient.util.RenderUtils.drawOutlinedTextInBatch(tr, text, -w,
763+
0, argb, stroke, matrix, Font.DisplayMode.SEE_THROUGH, bg,
766764
0xF000F0);
767-
net.wurstclient.util.RenderUtils.drawTextInBatch(tr, text, -w + 1, 0,
768-
stroke, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
769-
0xF000F0);
770-
net.wurstclient.util.RenderUtils.drawTextInBatch(tr, text, -w, -1,
771-
stroke, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
772-
0xF000F0);
773-
net.wurstclient.util.RenderUtils.drawTextInBatch(tr, text, -w, +1,
774-
stroke, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
775-
0xF000F0);
776-
net.wurstclient.util.RenderUtils.drawTextInBatch(tr, text, -w, 0, argb,
777-
false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, bg, 0xF000F0);
778-
vcp.endBatch();
779765
matrices.popPose();
780766
}
781767

src/main/java/net/wurstclient/hacks/PearlDropHack.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.mojang.blaze3d.vertex.PoseStack;
1414
import com.mojang.math.Axis;
1515
import net.minecraft.client.gui.Font;
16-
import net.wurstclient.util.WurstBufferSource;
1716
import net.minecraft.core.BlockPos;
1817
import net.minecraft.core.Direction;
1918
import net.minecraft.world.InteractionHand;
@@ -651,13 +650,11 @@ private void drawWorldLabel(PoseStack matrices, String text, Vec3 pos,
651650
matrices.scale(s, -s, s);
652651

653652
Font font = MC.font;
654-
WurstBufferSource vcp = RenderUtils.getVCP();
655653
float w = font.width(text) / 2F;
656654
var matrix = matrices.last().pose();
657655
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -w, 0,
658-
argb, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0x80000000,
656+
argb, false, matrix, null, Font.DisplayMode.SEE_THROUGH, 0x80000000,
659657
0xF000F0);
660-
vcp.endBatch();
661658
matrices.popPose();
662659
}
663660

src/main/java/net/wurstclient/hacks/PearlEspHack.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Map;
2222
import java.util.UUID;
2323
import net.minecraft.client.gui.Font;
24-
import net.wurstclient.util.WurstBufferSource;
2524
import net.minecraft.core.BlockPos;
2625
import net.minecraft.core.registries.BuiltInRegistries;
2726
import net.minecraft.network.protocol.Packet;
@@ -1194,7 +1193,6 @@ private void drawWorldLabel(PoseStack matrices, String text, double x,
11941193
matrices.translate(0, offsetPx, 0);
11951194

11961195
Font font = MC.font;
1197-
WurstBufferSource vcp = RenderUtils.getVCP();
11981196
float w = font.width(text) / 2F;
11991197
int baseAlpha = (argb >>> 24) & 0xFF;
12001198
int bgAlpha =
@@ -1204,23 +1202,10 @@ private void drawWorldLabel(PoseStack matrices, String text, double x,
12041202
(Math.max(0, Math.min(255, baseAlpha)) << 24) | 0x000000;
12051203
var matrix = matrices.last().pose();
12061204

1207-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -w - 1, 0,
1208-
strokeColor, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
1209-
0xF000F0);
1210-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -w + 1, 0,
1211-
strokeColor, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
1212-
0xF000F0);
1213-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -w, -1,
1214-
strokeColor, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
1215-
0xF000F0);
1216-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -w, 1,
1217-
strokeColor, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
1218-
0xF000F0);
1219-
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -w, 0,
1220-
argb, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, bg,
1205+
net.wurstclient.util.RenderUtils.drawOutlinedTextInBatch(font, text, -w,
1206+
0, argb, strokeColor, matrix, Font.DisplayMode.SEE_THROUGH, bg,
12211207
0xF000F0);
12221208

1223-
vcp.endBatch();
12241209
matrices.popPose();
12251210
}
12261211

src/main/java/net/wurstclient/hacks/PlayerEspHack.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import net.minecraft.ChatFormatting;
2525
import net.minecraft.util.Util;
2626
import net.minecraft.client.player.AbstractClientPlayer;
27-
import net.wurstclient.util.WurstBufferSource;
2827
import net.minecraft.client.gui.components.toasts.SystemToast;
2928
import net.minecraft.util.StringUtil;
3029
import net.minecraft.core.registries.BuiltInRegistries;
@@ -1212,7 +1211,6 @@ private void drawWorldLabel(PoseStack matrices, String text, double x,
12121211
matrices.scale(s, -s, s);
12131212
matrices.translate(0, offsetPx, 0);
12141213

1215-
WurstBufferSource vcp = RenderUtils.getVCP();
12161214
float w = MC.font.width(text) / 2F;
12171215
int baseAlpha = (argb >>> 24) & 0xFF;
12181216
int bgAlpha =
@@ -1221,23 +1219,10 @@ private void drawWorldLabel(PoseStack matrices, String text, double x,
12211219
var matrix = matrices.last().pose();
12221220
int strokeColor =
12231221
(Math.max(0, Math.min(255, baseAlpha)) << 24) | 0x000000;
1224-
net.wurstclient.util.RenderUtils.drawTextInBatch(MC.font, text, -w - 1,
1225-
0, strokeColor, false, matrix, vcp,
1226-
net.minecraft.client.gui.Font.DisplayMode.SEE_THROUGH, 0, 0xF000F0);
1227-
net.wurstclient.util.RenderUtils.drawTextInBatch(MC.font, text, -w + 1,
1228-
0, strokeColor, false, matrix, vcp,
1229-
net.minecraft.client.gui.Font.DisplayMode.SEE_THROUGH, 0, 0xF000F0);
1230-
net.wurstclient.util.RenderUtils.drawTextInBatch(MC.font, text, -w, -1,
1231-
strokeColor, false, matrix, vcp,
1232-
net.minecraft.client.gui.Font.DisplayMode.SEE_THROUGH, 0, 0xF000F0);
1233-
net.wurstclient.util.RenderUtils.drawTextInBatch(MC.font, text, -w, 1,
1234-
strokeColor, false, matrix, vcp,
1235-
net.minecraft.client.gui.Font.DisplayMode.SEE_THROUGH, 0, 0xF000F0);
1236-
net.wurstclient.util.RenderUtils.drawTextInBatch(MC.font, text, -w, 0,
1237-
argb, false, matrix, vcp,
1222+
net.wurstclient.util.RenderUtils.drawOutlinedTextInBatch(MC.font, text,
1223+
-w, 0, argb, strokeColor, matrix,
12381224
net.minecraft.client.gui.Font.DisplayMode.SEE_THROUGH, bg,
12391225
0xF000F0);
1240-
vcp.endBatch();
12411226
matrices.popPose();
12421227
}
12431228

src/main/java/net/wurstclient/hacks/ProjectileEspHack.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.util.List;
1616
import java.util.Map;
1717
import net.minecraft.client.gui.Font;
18-
import net.wurstclient.util.WurstBufferSource;
1918
import net.minecraft.core.registries.BuiltInRegistries;
2019
import net.minecraft.world.entity.Entity;
2120
import net.minecraft.world.entity.player.Player;
@@ -372,14 +371,12 @@ private void drawNameTag(PoseStack matrices, String text, double x,
372371
matrices.scale(scale, -scale, scale);
373372

374373
Font font = MC.font;
375-
WurstBufferSource vcp = RenderUtils.getVCP();
376374
float w = font.width(text) / 2F;
377375
int bgAlpha = (int)(MC.options.getBackgroundOpacity(0.25F) * 255) << 24;
378376
var matrix = matrices.last().pose();
379377
net.wurstclient.util.RenderUtils.drawTextInBatch(font, text, -w, 0,
380-
argb | 0xFF000000, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH,
381-
bgAlpha, 0xF000F0);
382-
vcp.endBatch();
378+
argb | 0xFF000000, false, matrix, null,
379+
Font.DisplayMode.SEE_THROUGH, bgAlpha, 0xF000F0);
383380
matrices.popPose();
384381
}
385382

src/main/java/net/wurstclient/hacks/TrialSpawnerEspHack.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.TimerTask;
2222
import net.minecraft.client.gui.Font;
2323
import net.minecraft.client.gui.Font.DisplayMode;
24-
import net.wurstclient.util.WurstBufferSource;
2524
import net.minecraft.core.BlockPos;
2625
import net.minecraft.core.registries.BuiltInRegistries;
2726
import net.minecraft.core.registries.Registries;
@@ -643,17 +642,8 @@ private void drawActivationRadius(PoseStack matrices, TrialSpawnerInfo info,
643642
inside ? mixWithWhite(stateColor, 0.35F) : radiusColor.getColorI(),
644643
inside ? 0.65F : 0.35F);
645644
int segments = Math.max(32, radius * 12);
646-
double step = (Math.PI * 2) / segments;
647-
648-
Vec3 prev = center.add(radius, 0, 0);
649-
for(int i = 1; i <= segments; i++)
650-
{
651-
double angle = i * step;
652-
Vec3 next = center.add(radius * Math.cos(angle), 0,
653-
radius * Math.sin(angle));
654-
RenderUtils.drawLine(matrices, prev, next, color, false);
655-
prev = next;
656-
}
645+
RenderUtils.drawCircle(matrices, center, radius, segments, color,
646+
false);
657647
}
658648

659649
private void drawVaultLink(PoseStack matrices, TrialSpawnerInfo info,
@@ -837,22 +827,21 @@ private void drawLabel(PoseStack matrices, Vec3 position,
837827
Font tr = MC.font;
838828
int bg = (int)(MC.options.getBackgroundOpacity(0.25F) * 255) << 24;
839829
int lineHeight = tr.lineHeight + 2;
840-
int maxWidth = lines.stream().mapToInt(line -> tr.width(line.text()))
841-
.max().orElse(0);
830+
int maxWidth = 0;
831+
for(OverlayLine line : lines)
832+
maxWidth = Math.max(maxWidth, tr.width(line.text()));
842833
int x = -maxWidth / 2;
843834

844-
WurstBufferSource vcp = RenderUtils.getVCP();
835+
DisplayMode layerType =
836+
NiceWurstModule.enforceTextLayer(DisplayMode.SEE_THROUGH);
845837
for(int i = 0; i < lines.size(); i++)
846838
{
847839
OverlayLine line = lines.get(i);
848840
int y = i * lineHeight;
849-
DisplayMode layerType =
850-
NiceWurstModule.enforceTextLayer(DisplayMode.SEE_THROUGH);
851841
net.wurstclient.util.RenderUtils.drawTextInBatch(tr, line.text(), x,
852-
y, line.color(), false, matrices.last().pose(), vcp, layerType,
842+
y, line.color(), false, matrices.last().pose(), null, layerType,
853843
bg, 0xF000F0);
854844
}
855-
vcp.endBatch();
856845
matrices.popPose();
857846
}
858847

src/main/java/net/wurstclient/hacks/WardenEspHack.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import net.wurstclient.settings.SliderSetting;
3030
import com.mojang.math.Axis;
3131
import net.minecraft.client.gui.Font;
32-
import net.wurstclient.util.WurstBufferSource;
3332
import net.wurstclient.util.EntityUtils;
3433
import net.wurstclient.util.RenderUtils;
3534
import net.wurstclient.util.RenderUtils.ColoredBox;
@@ -419,7 +418,6 @@ private void drawWorldLabel(PoseStack matrices, String text, double x,
419418
matrices.scale(s, -s, s);
420419
matrices.translate(0, offsetPx, 0);
421420
Font tr = MC.font;
422-
WurstBufferSource vcp = RenderUtils.getVCP();
423421
float w = tr.width(text) / 2F;
424422
int baseAlpha = (argb >>> 24) & 0xFF;
425423
int bgAlpha =
@@ -429,21 +427,9 @@ private void drawWorldLabel(PoseStack matrices, String text, double x,
429427
// stroke for legibility
430428
int strokeColor =
431429
(Math.max(0, Math.min(255, baseAlpha)) << 24) | 0x000000;
432-
net.wurstclient.util.RenderUtils.drawTextInBatch(tr, text, -w - 1, 0,
433-
strokeColor, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
430+
net.wurstclient.util.RenderUtils.drawOutlinedTextInBatch(tr, text, -w,
431+
0, argb, strokeColor, matrix, Font.DisplayMode.SEE_THROUGH, bg,
434432
0xF000F0);
435-
net.wurstclient.util.RenderUtils.drawTextInBatch(tr, text, -w + 1, 0,
436-
strokeColor, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
437-
0xF000F0);
438-
net.wurstclient.util.RenderUtils.drawTextInBatch(tr, text, -w, -1,
439-
strokeColor, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
440-
0xF000F0);
441-
net.wurstclient.util.RenderUtils.drawTextInBatch(tr, text, -w, +1,
442-
strokeColor, false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, 0,
443-
0xF000F0);
444-
net.wurstclient.util.RenderUtils.drawTextInBatch(tr, text, -w, 0, argb,
445-
false, matrix, vcp, Font.DisplayMode.SEE_THROUGH, bg, 0xF000F0);
446-
vcp.endBatch();
447433
matrices.popPose();
448434
}
449435

0 commit comments

Comments
 (0)