Skip to content

Commit d3cd9cc

Browse files
committed
use the buffer from GuiGraphics, fix compatibility with ImmediatelyFast
closes RaphiMC/ImmediatelyFast#304 might close #311
1 parent 44dc470 commit d3cd9cc

File tree

12 files changed

+80
-50
lines changed

12 files changed

+80
-50
lines changed

src/api/java/mcp/mobius/waila/api/__internal__/IApiService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import mcp.mobius.waila.api.IWailaConfig;
2020
import net.minecraft.client.DeltaTracker;
2121
import net.minecraft.client.gui.GuiGraphics;
22+
import net.minecraft.client.renderer.MultiBufferSource;
2223
import net.minecraft.core.Registry;
2324
import net.minecraft.resources.ResourceKey;
2425
import net.minecraft.resources.ResourceLocation;
@@ -79,4 +80,6 @@ public interface IApiService {
7980

8081
boolean isDevEnv();
8182

83+
MultiBufferSource getBufferSource(GuiGraphics ctx);
84+
8285
}

src/api/java/mcp/mobius/waila/api/component/BarComponent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void renderBar(
9494
var g = ARGB.green(tint);
9595
var b = ARGB.blue(tint);
9696

97-
var buffer = WRenders.buffer(RenderType.guiTextured(WailaConstants.COMPONENT_TEXTURE));
97+
var buffer = WRenders.buffer(ctx, RenderType.guiTextured(WailaConstants.COMPONENT_TEXTURE));
9898
var pose = ps.last().pose();
9999

100100
buffer.addVertex(pose, x, y + HEIGHT, 0).setUv(U0, v1).setColor(r, g, b, a);
@@ -108,7 +108,7 @@ static void renderBar(
108108
}
109109

110110
static void renderText(GuiGraphics ctx, Component text, int x, int y) {
111-
var bufferSource = WRenders.bufferSource();
111+
var bufferSource = WRenders.bufferSource(ctx);
112112
var font = Minecraft.getInstance().font;
113113
var textWidth = font.width(text);
114114
var textX = x + Math.max((BarComponent.WIDTH - textWidth) / 2F, 0F);

src/api/java/mcp/mobius/waila/api/component/ItemComponent.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import mcp.mobius.waila.api.ITooltipComponent;
44
import mcp.mobius.waila.api.__internal__.ApiSide;
55
import mcp.mobius.waila.api.util.WNumbers;
6+
import mcp.mobius.waila.api.util.WRenders;
67
import net.minecraft.client.DeltaTracker;
78
import net.minecraft.client.Minecraft;
89
import net.minecraft.client.gui.Font;
@@ -45,30 +46,30 @@ public void render(GuiGraphics ctx, int x, int y, DeltaTracker delta) {
4546
}
4647

4748
static void renderItemDecorations(GuiGraphics ctx, ItemStack stack, int x, int y) {
48-
ctx.drawSpecial(bufferSource -> {
49-
var client = Minecraft.getInstance();
50-
var count = stack.getCount();
51-
52-
ctx.renderItemDecorations(client.font, stack, x + 1, y + 1, "");
53-
if (count <= 1) return;
54-
55-
var countText = WNumbers.suffix(count);
56-
var actualW = client.font.width(countText);
57-
var scale = (actualW <= 16) ? 1f : 16f / actualW;
58-
59-
var pose = ctx.pose();
60-
pose.pushPose();
61-
pose.translate(0.0, 0.0, 250.0);
62-
pose.scale(scale, scale, 1f);
63-
64-
client.font.drawInBatch(countText,
65-
((x + 17 - (actualW * scale)) / scale),
66-
((y + 17 - (client.font.lineHeight * scale)) / scale),
67-
0xFFFFFF, true,
68-
pose.last().pose(), bufferSource, Font.DisplayMode.NORMAL, 0, 0xF000F0);
69-
70-
pose.popPose();
71-
});
49+
var buffer = WRenders.bufferSource(ctx);
50+
var client = Minecraft.getInstance();
51+
var count = stack.getCount();
52+
53+
ctx.renderItemDecorations(client.font, stack, x + 1, y + 1, "");
54+
if (count <= 1) return;
55+
56+
var countText = WNumbers.suffix(count);
57+
var actualW = client.font.width(countText);
58+
var scale = (actualW <= 16) ? 1f : 16f / actualW;
59+
60+
var pose = ctx.pose();
61+
pose.pushPose();
62+
pose.translate(0.0, 0.0, 250.0);
63+
pose.scale(scale, scale, 1f);
64+
65+
client.font.drawInBatch(countText,
66+
((x + 17 - (actualW * scale)) / scale),
67+
((y + 17 - (client.font.lineHeight * scale)) / scale),
68+
0xFFFFFF, true,
69+
pose.last().pose(), buffer, Font.DisplayMode.NORMAL, 0, 0xF000F0);
70+
71+
pose.popPose();
72+
ctx.flush();
7273
}
7374

7475
}

src/api/java/mcp/mobius/waila/api/component/SpriteBarComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void render(GuiGraphics ctx, int x, int y, DeltaTracker delta) {
8181
for (var py1 = y; py1 < my; py1 += regionHeight) {
8282
var py2 = py1 + regionHeight;
8383

84-
if (buffer == null) buffer = WRenders.buffer(RenderType.guiTextured(texture));
84+
if (buffer == null) buffer = WRenders.buffer(ctx, RenderType.guiTextured(texture));
8585
buffer.addVertex(pose, px1, py2, 0).setUv(u0, v1).setColor(r, g, b, a);
8686
buffer.addVertex(pose, px2, py2, 0).setUv(u1, v1).setColor(r, g, b, a);
8787
buffer.addVertex(pose, px2, py1, 0).setUv(u1, v0).setColor(r, g, b, a);

src/api/java/mcp/mobius/waila/api/util/WRenders.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
import com.mojang.blaze3d.vertex.VertexConsumer;
44
import mcp.mobius.waila.api.__internal__.ApiSide;
5-
import net.minecraft.client.Minecraft;
5+
import mcp.mobius.waila.api.__internal__.IApiService;
6+
import net.minecraft.client.gui.GuiGraphics;
67
import net.minecraft.client.renderer.MultiBufferSource;
78
import net.minecraft.client.renderer.RenderType;
89

910
@ApiSide.ClientOnly
1011
public final class WRenders {
1112

12-
public static MultiBufferSource bufferSource() {
13-
return Minecraft.getInstance().renderBuffers().bufferSource();
13+
public static MultiBufferSource bufferSource(GuiGraphics ctx) {
14+
return IApiService.INSTANCE.getBufferSource(ctx);
1415
}
1516

16-
public static VertexConsumer buffer(RenderType type) {
17-
return bufferSource().getBuffer(type);
17+
public static VertexConsumer buffer(GuiGraphics ctx, RenderType type) {
18+
return bufferSource(ctx).getBuffer(type);
1819
}
1920

2021
private WRenders() {

src/main/java/mcp/mobius/waila/service/ApiService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import mcp.mobius.waila.config.JsonConfig;
2424
import mcp.mobius.waila.gui.hud.TooltipRenderer;
2525
import mcp.mobius.waila.gui.hud.theme.ThemeType;
26+
import mcp.mobius.waila.mixin.GuiGraphicsAccess;
2627
import mcp.mobius.waila.plugin.PluginInfo;
2728
import mcp.mobius.waila.registry.InstanceRegistry;
2829
import mcp.mobius.waila.registry.RegistryFilter;
@@ -31,6 +32,7 @@
3132
import mcp.mobius.waila.util.ModInfo;
3233
import net.minecraft.client.DeltaTracker;
3334
import net.minecraft.client.gui.GuiGraphics;
35+
import net.minecraft.client.renderer.MultiBufferSource;
3436
import net.minecraft.core.HolderSet;
3537
import net.minecraft.core.Registry;
3638
import net.minecraft.core.component.DataComponents;
@@ -230,4 +232,9 @@ public boolean isDevEnv() {
230232
return Waila.DEV;
231233
}
232234

235+
@Override
236+
public MultiBufferSource getBufferSource(GuiGraphics ctx) {
237+
return ((GuiGraphicsAccess) ctx).wthit_bufferSource();
238+
}
239+
233240
}

src/main/java/mcp/mobius/waila/util/DisplayUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static void renderComponent(GuiGraphics ctx, ITooltipComponent component,
5656
var scale = (float) Minecraft.getInstance().getWindow().getGuiScale();
5757
ctx.pose().scale(1 / scale, 1 / scale, 1);
5858

59-
var buf = WRenders.buffer(RenderType.gui());
59+
var buf = WRenders.buffer(ctx, RenderType.gui());
6060
var bx = Mth.floor(x * scale + 0.5);
6161
var by = Mth.floor(y * scale + 0.5);
6262
var bw = Mth.floor((cw == 0 ? component.getWidth() : cw) * scale + 0.5);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package mcp.mobius.waila.mixin;
2+
3+
import net.minecraft.client.gui.GuiGraphics;
4+
import net.minecraft.client.renderer.MultiBufferSource;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.gen.Accessor;
7+
8+
@Mixin(GuiGraphics.class)
9+
public interface GuiGraphicsAccess {
10+
11+
@Accessor("bufferSource")
12+
MultiBufferSource.BufferSource wthit_bufferSource();
13+
14+
}

src/pluginCore/java/mcp/mobius/waila/plugin/core/theme/GradientTheme.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void renderTooltipBackground(GuiGraphics ctx, int x, int y, int width, in
6060
RenderSystem.defaultBlendFunc();
6161
RenderSystem.setShader(CoreShaders.POSITION_COLOR);
6262

63-
var buf = WRenders.buffer(RenderType.gui());
63+
var buf = WRenders.buffer(ctx, RenderType.gui());
6464
var matrix = ctx.pose().last().pose();
6565

6666
var a = alpha << 24;

src/pluginCore/java/mcp/mobius/waila/plugin/core/theme/NinePatchTheme.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void renderTooltipBackground(GuiGraphics ctx, int x, int y, int width, in
100100
RenderSystem.enableBlend();
101101
RenderSystem.defaultBlendFunc();
102102

103-
var buf = WRenders.buffer(RenderType.guiTextured(textureId));
103+
var buf = WRenders.buffer(ctx, RenderType.guiTextured(textureId));
104104
var matrix = ctx.pose().last().pose();
105105

106106
// @formatter:off

0 commit comments

Comments
 (0)