GuiGraphicsExtractor .java

net.minecraft.client.gui.GuiGraphicsExtractor (class, 1457 lines): members: EXTRA_SPACE_AFTER_FIRST_TOOLTIP_LINE, setComponentTooltipForNextFrame, blit.

net.minecraft.client.guiclass1,457 linesclient47.5 KB

API Surface (87)

void requestCursor(final CursorType cursorType)
void applyCursor(final Window window)
int guiWidth()
int guiHeight()
Matrix3x2fStack pose()
void nextStratum()
void blurBeforeThisStratum()
void enableScissor(final int x0, final int y0, final int x1, final int y1)
void disableScissor()
boolean containsPointInScissor(final int x, final int y)
void horizontalLine(int x0, int x1, final int y, final int col)
void verticalLine(final int x, int y0, int y1, final int col)
void fill(final int x0, final int y0, final int x1, final int y1, final int col)
void fill(final RenderPipeline pipeline, int x0, int y0, int x1, int y1, final int col)
void fillGradient(final int x0, final int y0, final int x1, final int y1, final int col1, final int col2)
void fill(final RenderPipeline renderPipeline, final TextureSetup textureSetup, final int x0, final int y0, final int x1, final int y1)
void outline(final int x, final int y, final int width, final int height, final int color)
void textHighlight(final int x0, final int y0, final int x1, final int y1, final boolean invertText)
void text(final Font font, final @Nullable String str, final int x, final int y, final int color)
void text(final Font font, final @Nullable String str, final int x, final int y, final int color, final boolean dropShadow)
void text(final Font font, final FormattedCharSequence str, final int x, final int y, final int color)
void text(final Font font, final FormattedCharSequence str, final int x, final int y, final int color, final boolean dropShadow)
void text(final Font font, final Component str, final int x, final int y, final int color)
void text(final Font font, final Component str, final int x, final int y, final int color, final boolean dropShadow)
void centeredText(final Font font, final String str, final int x, final int y, final int color)
void centeredText(final Font font, final Component text, final int x, final int y, final int color)
void centeredText(final Font font, final FormattedCharSequence text, final int x, final int y, final int color)
int textWithWordWrap(final Font font, final FormattedText string, final int x, final int y, final int width, final int col)
int textWithWordWrap(final Font font, final FormattedText string, final int x, int y, final int width, final int col, final boolean dropShadow)
void textWithBackdrop(final Font font, final Component str, final int textX, final int textY, final int textWidth, final int textColor)
void blit(final RenderPipeline renderPipeline, final Identifier texture, final int x, final int y, final float u, final float v, final int width, final int height, final int textureWidth, final int textureHeight, final int color)
void blit(final RenderPipeline renderPipeline, final Identifier texture, final int x, final int y, final float u, final float v, final int width, final int height, final int textureWidth, final int textureHeight)
void blit(final RenderPipeline renderPipeline, final Identifier texture, final int x, final int y, final float u, final float v, final int width, final int height, final int srcWidth, final int srcHeight, final int textureWidth, final int textureHeight)
void blit(final RenderPipeline renderPipeline, final Identifier texture, final int x, final int y, final float u, final float v, final int width, final int height, final int srcWidth, final int srcHeight, final int textureWidth, final int textureHeight, final int color)
void blit(final Identifier location, final int x0, final int y0, final int x1, final int y1, final float u0, final float u1, final float v0, final float v1)
void blit(final GpuTextureView textureView, final GpuSampler sampler, final int x0, final int y0, final int x1, final int y1, final float u0, final float u1, final float v0, final float v1)
void blitSprite(final RenderPipeline renderPipeline, final Identifier location, final int x, final int y, final int width, final int height)
void blitSprite(final RenderPipeline renderPipeline, final Identifier location, final int x, final int y, final int width, final int height, final float alpha)
void blitSprite(final RenderPipeline renderPipeline, final Identifier location, final int x, final int y, final int width, final int height, final int color)
void blitSprite(final RenderPipeline renderPipeline, final Identifier location, final int spriteWidth, final int spriteHeight, final int textureX, final int textureY, final int x, final int y, final int width, final int height)
void blitSprite(final RenderPipeline renderPipeline, final Identifier location, final int spriteWidth, final int spriteHeight, final int textureX, final int textureY, final int x, final int y, final int width, final int height, final int color)
void blitSprite(final RenderPipeline renderPipeline, final TextureAtlasSprite sprite, final int x, final int y, final int width, final int height)
void blitSprite(final RenderPipeline renderPipeline, final TextureAtlasSprite sprite, final int x, final int y, final int width, final int height, final int color)
void item(final ItemStack itemStack, final int x, final int y)
void item(final ItemStack itemStack, final int x, final int y, final int seed)
void item(final LivingEntity owner, final ItemStack itemStack, final int x, final int y, final int seed)
void fakeItem(final ItemStack itemStack, final int x, final int y)
void fakeItem(final ItemStack itemStack, final int x, final int y, final int seed)
void itemDecorations(final Font font, final ItemStack itemStack, final int x, final int y)
void itemDecorations(final Font font, final ItemStack itemStack, final int x, final int y, final @Nullable String countText)
void map(final MapRenderState mapRenderState)
void entity(final EntityRenderState renderState, final float scale, final Vector3fc translation, final Quaternionfc rotation, final @Nullable Quaternionfc overrideCameraAngle, final int x0, final int y0, final int x1, final int y1)
void skin(final Model.Simple playerModel, final Identifier texture, final float scale, final float rotationX, final float rotationY, final float pivotY, final int x0, final int y0, final int x1, final int y1)
void book(final BookModel bookModel, final Identifier texture, final float scale, final float open, final float flip, final int x0, final int y0, final int x1, final int y1)
void bannerPattern(final BannerFlagModel flag, final DyeColor baseColor, final BannerPatternLayers resultBannerPatterns, final int x0, final int y0, final int x1, final int y1)
void profilerChart(final List<ResultField> chartData, final int x0, final int y0, final int x1, final int y1)
void setTooltipForNextFrame(final Component component, final int x, final int y)
void setTooltipForNextFrame(final List<FormattedCharSequence> formattedCharSequences, final int x, final int y)
void setTooltipForNextFrame(final Font font, final ItemStack itemStack, final int xo, final int yo)
void setTooltipForNextFrame(final Font font, final List<Component> texts, final Optional<TooltipComponent> optionalImage, final int xo, final int yo)
void setTooltipForNextFrame(final Font font, final List<Component> texts, final Optional<TooltipComponent> optionalImage, final int xo, final int yo, final @Nullable Identifier style)
void setTooltipForNextFrame(final Font font, final List<Component> texts, final Optional<TooltipComponent> optionalImage, final int xo, final int yo, final @Nullable Identifier style, final boolean extraSpaceAfterFirstLine)
void setTooltipForNextFrame(final Font font, final List<FormattedCharSequence> tooltip, final Optional<TooltipComponent> component, final ClientTooltipPositioner positioner, final int xo, final int yo, final boolean replaceExisting, final @Nullable Identifier style)
void setTooltipForNextFrame(final Font font, final Component text, final int xo, final int yo)
void setTooltipForNextFrame(final Font font, final Component text, final int xo, final int yo, final @Nullable Identifier style)
void setComponentTooltipForNextFrame(final Font font, final List<Component> lines, final int xo, final int yo)
void setComponentTooltipForNextFrame(final Font font, final List<Component> lines, final int xo, final int yo, final @Nullable Identifier style)
void setTooltipForNextFrame(final Font font, final List<? extends FormattedCharSequence> lines, final int xo, final int yo)
void setTooltipForNextFrame(final Font font, final List<? extends FormattedCharSequence> lines, final int xo, final int yo, final @Nullable Identifier style)
void setTooltipForNextFrame(final Font font, final List<FormattedCharSequence> tooltip, final ClientTooltipPositioner positioner, final int xo, final int yo, final boolean replaceExisting)
void tooltip(final Font font, final List<ClientTooltipComponent> lines, final int xo, final int yo, final ClientTooltipPositioner positioner, final @Nullable Identifier style, boolean extraSpaceAfterFirstLine)
void setPreeditOverlay(final Renderable preeditOverlay)
void extractDeferredElements(final int mouseX, final int mouseY, final float a)
TextureAtlasSprite getSprite(final SpriteId sprite)
ActiveTextCollector textRendererForWidget(final AbstractWidget owner, final GuiGraphicsExtractor.HoveredTextEffects hoveredTextEffects)
ActiveTextCollector textRenderer()
ActiveTextCollector textRenderer(final GuiGraphicsExtractor.HoveredTextEffects hoveredTextEffects)
ActiveTextCollector textRenderer(final GuiGraphicsExtractor.HoveredTextEffects hoveredTextEffects, final @Nullable Consumer<Style> additionalHoverStyleConsumer)
GuiGraphicsExtractor.HoveredTextEffects notClickable(final boolean canTooltip)
ActiveTextCollector.Parameters defaultParameters()
void defaultParameters(final ActiveTextCollector.Parameters newParameters)
void accept(final Style style)
void accept(final TextAlignment alignment, final int anchorX, final int y, final ActiveTextCollector.Parameters parameters, final FormattedCharSequence text)
void acceptScrolling(final Component message, final int centerX, final int left, final int right, final int top, final int bottom, final ActiveTextCollector.Parameters parameters)
void push(final ScreenRectangle rectangle)
void pop()
boolean containsPoint(final int x, final int y)

Fields & Constants (73)

EXTRA_SPACE_AFTER_FIRST_TOOLTIP_LINE
minecraft
pose
scissorStack
sprites
guiSprites
guiRenderState
pendingCursor
mouseX
mouseY
deferredTooltip
hoveredTextStyle
clickableTextStyle
preeditOverlay
renderPipeline
textureSetup
x0
y0
x1
y1
color1
texture
x
y
u

…and 48 more (see full source).

String literals (7)

"Tile size must be positive, got "
"Rendering item"
"Item being rendered"
"Item Type"
"Item Components"
"Item Foil"
"Scissor stack underflow"

Code Graph: Dependencies (71)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

GuiGraphicsExtractor.java1457 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui;
2
3
import com.mojang.blaze3d.platform.Window;
4
import com.mojang.blaze3d.platform.cursor.CursorType;
5
import com.mojang.blaze3d.platform.cursor.CursorTypes;
6
import com.mojang.renderpearl.api.pipeline.RenderPipeline;
7
import com.mojang.renderpearl.api.textures.GpuSampler;
8
import com.mojang.renderpearl.api.textures.GpuTextureView;
9
import java.util.ArrayDeque;
10
import java.util.Deque;
11
import java.util.List;
12
import java.util.Objects;
13
import java.util.Optional;
14
import java.util.function.Consumer;
15
import java.util.stream.Collectors;
16
import net.fabricmc.api.EnvType;
17
import net.fabricmc.api.Environment;
18
import net.minecraft.CrashReport;
19
import net.minecraft.CrashReportCategory;
20
import net.minecraft.ReportedException;
21
import net.minecraft.client.Minecraft;
22
import net.minecraft.client.gui.components.AbstractWidget;
23
import net.minecraft.client.gui.components.Renderable;
24
import net.minecraft.client.gui.navigation.ScreenRectangle;
25
import net.minecraft.client.gui.render.TextureSetup;
26
import net.minecraft.client.gui.screens.Screen;
27
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
28
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner;
29
import net.minecraft.client.gui.screens.inventory.tooltip.DefaultTooltipPositioner;
30
import net.minecraft.client.gui.screens.inventory.tooltip.TooltipRenderUtil;
31
import net.minecraft.client.model.Model;
32
import net.minecraft.client.model.object.banner.BannerFlagModel;
33
import net.minecraft.client.model.object.book.BookModel;
34
import net.minecraft.client.player.LocalPlayer;
35
import net.minecraft.client.renderer.RenderPipelines;
36
import net.minecraft.client.renderer.entity.state.EntityRenderState;
37
import net.minecraft.client.renderer.item.TrackingItemStackRenderState;
38
import net.minecraft.client.renderer.state.MapRenderState;
39
import net.minecraft.client.renderer.state.gui.BlitRenderState;
40
import net.minecraft.client.renderer.state.gui.ColoredRectangleRenderState;
41
import net.minecraft.client.renderer.state.gui.GuiItemRenderState;
42
import net.minecraft.client.renderer.state.gui.GuiRenderState;
43
import net.minecraft.client.renderer.state.gui.GuiTextRenderState;
44
import net.minecraft.client.renderer.state.gui.TiledBlitRenderState;
45
import net.minecraft.client.renderer.state.gui.pip.GuiBannerResultRenderState;
46
import net.minecraft.client.renderer.state.gui.pip.GuiBookModelRenderState;
47
import net.minecraft.client.renderer.state.gui.pip.GuiEntityRenderState;
48
import net.minecraft.client.renderer.state.gui.pip.GuiProfilerChartRenderState;
49
import net.minecraft.client.renderer.state.gui.pip.GuiSkinRenderState;
50
import net.minecraft.client.renderer.texture.AbstractTexture;
51
import net.minecraft.client.renderer.texture.TextureAtlas;
52
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
53
import net.minecraft.client.renderer.texture.TextureManager;
54
import net.minecraft.client.resources.metadata.gui.GuiMetadataSection;
55
import net.minecraft.client.resources.metadata.gui.GuiSpriteScaling;
56
import net.minecraft.client.resources.metadata.gui.GuiSpriteScaling.NineSlice.Border;
57
import net.minecraft.client.resources.model.sprite.AtlasManager;
58
import net.minecraft.client.resources.model.sprite.SpriteGetter;
59
import net.minecraft.client.resources.model.sprite.SpriteId;
60
import net.minecraft.core.component.DataComponents;
61
import net.minecraft.data.AtlasIds;
62
import net.minecraft.locale.Language;
63
import net.minecraft.network.chat.Component;
64
import net.minecraft.network.chat.FormattedText;
65
import net.minecraft.network.chat.Style;
66
import net.minecraft.network.chat.HoverEvent.EntityTooltipInfo;
67
import net.minecraft.network.chat.HoverEvent.ShowEntity;
68
import net.minecraft.network.chat.HoverEvent.ShowItem;
69
import net.minecraft.network.chat.HoverEvent.ShowText;
70
import net.minecraft.resources.Identifier;
71
import net.minecraft.util.ARGB;
72
import net.minecraft.util.FormattedCharSequence;
73
import net.minecraft.util.Mth;
74
import net.minecraft.util.Util;
75
import net.minecraft.util.profiling.ResultField;
76
import net.minecraft.world.entity.LivingEntity;
77
import net.minecraft.world.inventory.tooltip.TooltipComponent;
78
import net.minecraft.world.item.DyeColor;
79
import net.minecraft.world.item.ItemDisplayContext;
80
import net.minecraft.world.item.ItemStack;
81
import net.minecraft.world.item.ItemStackTemplate;
82
import net.minecraft.world.level.Level;
83
import net.minecraft.world.level.block.entity.BannerPatternLayers;
84
import org.joml.Matrix3x2f;
85
import org.joml.Matrix3x2fStack;
86
import org.joml.Quaternionfc;
87
import org.joml.Vector2ic;
88
import org.joml.Vector3fc;
89
import org.jspecify.annotations.Nullable;
90
91
/**
92
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
93
 */
94
@Environment(EnvType.CLIENT)
95
public class GuiGraphicsExtractor {
96
	private static final int EXTRA_SPACE_AFTER_FIRST_TOOLTIP_LINE = 2;
97
	private final Minecraft minecraft;
98
	private final Matrix3x2fStack pose;
99
	/**
100
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
101
	 */
102
	public final GuiGraphicsExtractor.ScissorStack scissorStack;
103
	private final SpriteGetter sprites;
104
	private final TextureAtlas guiSprites;
105
	/**
106
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
107
	 */
108
	public final GuiRenderState guiRenderState;
109
	private CursorType pendingCursor = CursorType.DEFAULT;
110
	private final int mouseX;
111
	private final int mouseY;
112
	private @Nullable Runnable deferredTooltip;
113
	private @Nullable Style hoveredTextStyle;
114
	private @Nullable Style clickableTextStyle;
115
	private @Nullable Renderable preeditOverlay;
116
117
	private GuiGraphicsExtractor(final Minecraft minecraft, final Matrix3x2fStack pose, final GuiRenderState guiRenderState, final int mouseX, final int mouseY) {
118
		this.minecraft = minecraft;
119
		this.pose = pose;
120
		this.mouseX = mouseX;
121
		this.mouseY = mouseY;
122
		AtlasManager atlasManager = minecraft.getAtlasManager();
123
		this.sprites = atlasManager;
124
		this.guiSprites = atlasManager.getAtlasOrThrow(AtlasIds.GUI);
125
		this.guiRenderState = guiRenderState;
126
		this.scissorStack = new GuiGraphicsExtractor.ScissorStack(new ScreenRectangle(0, 0, this.guiWidth(), this.guiHeight()));
127
	}
128
129
	public GuiGraphicsExtractor(final Minecraft minecraft, final GuiRenderState guiRenderState, final int mouseX, final int mouseY) {
130
		this(minecraft, new Matrix3x2fStack(16), guiRenderState, mouseX, mouseY);
131
	}
132
133
	public void requestCursor(final CursorType cursorType) {
134
		this.pendingCursor = cursorType;
135
	}
136
137
	public void applyCursor(final Window window) {
138
		window.selectCursor(this.pendingCursor);
139
	}
140
141
	public int guiWidth() {
142
		return this.minecraft.getWindow().getGuiScaledWidth();
143
	}
144
145
	public int guiHeight() {
146
		return this.minecraft.getWindow().getGuiScaledHeight();
147
	}
148
149
	public Matrix3x2fStack pose() {
150
		return this.pose;
151
	}
152
153
	public void nextStratum() {
154
		this.guiRenderState.nextStratum();
155
	}
156
157
	public void blurBeforeThisStratum() {
158
		this.guiRenderState.blurBeforeThisStratum();
159
	}
160
161
	public void enableScissor(final int x0, final int y0, final int x1, final int y1) {
162
		ScreenRectangle rectangle = new ScreenRectangle(x0, y0, x1 - x0, y1 - y0).transformAxisAligned(this.pose);
163
		this.scissorStack.push(rectangle);
164
	}
165
166
	public void disableScissor() {
167
		this.scissorStack.pop();
168
	}
169
170
	public boolean containsPointInScissor(final int x, final int y) {
171
		return this.scissorStack.containsPoint(x, y);
172
	}
173
174
	public void horizontalLine(int x0, int x1, final int y, final int col) {
175
		if (x1 < x0) {
176
			int tmp = x0;
177
			x0 = x1;
178
			x1 = tmp;
179
		}
180
181
		this.fill(x0, y, x1 + 1, y + 1, col);
182
	}
183
184
	public void verticalLine(final int x, int y0, int y1, final int col) {
185
		if (y1 < y0) {
186
			int tmp = y0;
187
			y0 = y1;
188
			y1 = tmp;
189
		}
190
191
		this.fill(x, y0 + 1, x + 1, y1, col);
192
	}
193
194
	public void fill(final int x0, final int y0, final int x1, final int y1, final int col) {
195
		this.fill(RenderPipelines.GUI, x0, y0, x1, y1, col);
196
	}
197
198
	public void fill(final RenderPipeline pipeline, int x0, int y0, int x1, int y1, final int col) {
199
		if (x0 < x1) {
200
			int tmp = x0;
201
			x0 = x1;
202
			x1 = tmp;
203
		}
204
205
		if (y0 < y1) {
206
			int tmp = y0;
207
			y0 = y1;
208
			y1 = tmp;
209
		}
210
211
		this.innerFill(pipeline, TextureSetup.noTexture(), x0, y0, x1, y1, col, null);
212
	}
213
214
	public void fillGradient(final int x0, final int y0, final int x1, final int y1, final int col1, final int col2) {
215
		this.innerFill(RenderPipelines.GUI, TextureSetup.noTexture(), x0, y0, x1, y1, col1, col2);
216
	}
217
218
	public void fill(final RenderPipeline renderPipeline, final TextureSetup textureSetup, final int x0, final int y0, final int x1, final int y1) {
219
		this.innerFill(renderPipeline, textureSetup, x0, y0, x1, y1, -1, null);
220
	}
221
222
	public void outline(final int x, final int y, final int width, final int height, final int color) {
223
		this.fill(x, y, x + width, y + 1, color);
224
		this.fill(x, y + height - 1, x + width, y + height, color);
225
		this.fill(x, y + 1, x + 1, y + height - 1, color);
226
		this.fill(x + width - 1, y + 1, x + width, y + height - 1, color);
227
	}
228
229
	private void innerFill(
230
		final RenderPipeline renderPipeline,
231
		final TextureSetup textureSetup,
232
		final int x0,
233
		final int y0,
234
		final int x1,
235
		final int y1,
236
		final int color1,
237
		final @Nullable Integer color2
238
	) {
239
		this.guiRenderState
240
			.addGuiElement(
241
				new ColoredRectangleRenderState(
242
					renderPipeline, textureSetup, new Matrix3x2f(this.pose), x0, y0, x1, y1, color1, color2 != null ? color2 : color1, this.scissorStack.peek()
243
				)
244
			);
245
	}
246
247
	public void textHighlight(final int x0, final int y0, final int x1, final int y1, final boolean invertText) {
248
		if (invertText) {
249
			this.fill(RenderPipelines.GUI_INVERT, x0, y0, x1, y1, -1);
250
		}
251
252
		this.fill(RenderPipelines.GUI_TEXT_HIGHLIGHT, x0, y0, x1, y1, -16776961);
253
	}
254
255
	public void text(final Font font, final @Nullable String str, final int x, final int y, final int color) {
256
		this.text(font, str, x, y, color, true);
257
	}
258
259
	public void text(final Font font, final @Nullable String str, final int x, final int y, final int color, final boolean dropShadow) {
260
		if (str != null) {
261
			this.text(font, Language.getInstance().getVisualOrder(FormattedText.of(str)), x, y, color, dropShadow);
262
		}
263
	}
264
265
	public void text(final Font font, final FormattedCharSequence str, final int x, final int y, final int color) {
266
		this.text(font, str, x, y, color, true);
267
	}
268
269
	public void text(final Font font, final FormattedCharSequence str, final int x, final int y, final int color, final boolean dropShadow) {
270
		if (ARGB.alpha(color) != 0) {
271
			this.guiRenderState.addText(new GuiTextRenderState(font, str, new Matrix3x2f(this.pose), x, y, color, 0, dropShadow, false, this.scissorStack.peek()));
272
		}
273
	}
274
275
	public void text(final Font font, final Component str, final int x, final int y, final int color) {
276
		this.text(font, str, x, y, color, true);
277
	}
278
279
	public void text(final Font font, final Component str, final int x, final int y, final int color, final boolean dropShadow) {
280
		this.text(font, str.getVisualOrderText(), x, y, color, dropShadow);
281
	}
282
283
	public void centeredText(final Font font, final String str, final int x, final int y, final int color) {
284
		this.text(font, str, x - font.width(str) / 2, y, color);
285
	}
286
287
	public void centeredText(final Font font, final Component text, final int x, final int y, final int color) {
288
		FormattedCharSequence toRender = text.getVisualOrderText();
289
		this.text(font, toRender, x - font.width(toRender) / 2, y, color);
290
	}
291
292
	public void centeredText(final Font font, final FormattedCharSequence text, final int x, final int y, final int color) {
293
		this.text(font, text, x - font.width(text) / 2, y, color);
294
	}
295
296
	public int textWithWordWrap(final Font font, final FormattedText string, final int x, final int y, final int width, final int col) {
297
		return this.textWithWordWrap(font, string, x, y, width, col, true);
298
	}
299
300
	public int textWithWordWrap(final Font font, final FormattedText string, final int x, int y, final int width, final int col, final boolean dropShadow) {
301
		for (FormattedCharSequence line : font.split(string, width)) {
302
			this.text(font, line, x, y, col, dropShadow);
303
			y += 9;
304
		}
305
306
		return y;
307
	}
308
309
	public void textWithBackdrop(final Font font, final Component str, final int textX, final int textY, final int textWidth, final int textColor) {
310
		int backgroundColor = this.minecraft.options.getBackgroundColor(0.0F);
311
		if (backgroundColor != 0) {
312
			int padding = 2;
313
			this.fill(textX - 2, textY - 2, textX + textWidth + 2, textY + 9 + 2, ARGB.multiply(backgroundColor, textColor));
314
		}
315
316
		this.text(font, str, textX, textY, textColor, true);
317
	}
318
319
	public void blit(
320
		final RenderPipeline renderPipeline,
321
		final Identifier texture,
322
		final int x,
323
		final int y,
324
		final float u,
325
		final float v,
326
		final int width,
327
		final int height,
328
		final int textureWidth,
329
		final int textureHeight,
330
		final int color
331
	) {
332
		this.blit(renderPipeline, texture, x, y, u, v, width, height, width, height, textureWidth, textureHeight, color);
333
	}
334
335
	public void blit(
336
		final RenderPipeline renderPipeline,
337
		final Identifier texture,
338
		final int x,
339
		final int y,
340
		final float u,
341
		final float v,
342
		final int width,
343
		final int height,
344
		final int textureWidth,
345
		final int textureHeight
346
	) {
347
		this.blit(renderPipeline, texture, x, y, u, v, width, height, width, height, textureWidth, textureHeight);
348
	}
349
350
	public void blit(
351
		final RenderPipeline renderPipeline,
352
		final Identifier texture,
353
		final int x,
354
		final int y,
355
		final float u,
356
		final float v,
357
		final int width,
358
		final int height,
359
		final int srcWidth,
360
		final int srcHeight,
361
		final int textureWidth,
362
		final int textureHeight
363
	) {
364
		this.blit(renderPipeline, texture, x, y, u, v, width, height, srcWidth, srcHeight, textureWidth, textureHeight, -1);
365
	}
366
367
	public void blit(
368
		final RenderPipeline renderPipeline,
369
		final Identifier texture,
370
		final int x,
371
		final int y,
372
		final float u,
373
		final float v,
374
		final int width,
375
		final int height,
376
		final int srcWidth,
377
		final int srcHeight,
378
		final int textureWidth,
379
		final int textureHeight,
380
		final int color
381
	) {
382
		this.innerBlit(
383
			renderPipeline,
384
			texture,
385
			x,
386
			x + width,
387
			y,
388
			y + height,
389
			(u + 0.0F) / textureWidth,
390
			(u + srcWidth) / textureWidth,
391
			(v + 0.0F) / textureHeight,
392
			(v + srcHeight) / textureHeight,
393
			color
394
		);
395
	}
396
397
	public void blit(
398
		final Identifier location, final int x0, final int y0, final int x1, final int y1, final float u0, final float u1, final float v0, final float v1
399
	) {
400
		this.innerBlit(RenderPipelines.GUI_TEXTURED, location, x0, x1, y0, y1, u0, u1, v0, v1, -1);
401
	}
402
403
	public void blit(
404
		final GpuTextureView textureView,
405
		final GpuSampler sampler,
406
		final int x0,
407
		final int y0,
408
		final int x1,
409
		final int y1,
410
		final float u0,
411
		final float u1,
412
		final float v0,
413
		final float v1
414
	) {
415
		this.innerBlit(RenderPipelines.GUI_TEXTURED, textureView, sampler, x0, y0, x1, y1, u0, u1, v0, v1, -1);
416
	}
417
418
	public void blitSprite(final RenderPipeline renderPipeline, final Identifier location, final int x, final int y, final int width, final int height) {
419
		this.blitSprite(renderPipeline, location, x, y, width, height, -1);
420
	}
421
422
	public void blitSprite(
423
		final RenderPipeline renderPipeline, final Identifier location, final int x, final int y, final int width, final int height, final float alpha
424
	) {
425
		this.blitSprite(renderPipeline, location, x, y, width, height, ARGB.white(alpha));
426
	}
427
428
	public void blitSprite(
429
		final RenderPipeline renderPipeline, final Identifier location, final int x, final int y, final int width, final int height, final int color
430
	) {
431
		TextureAtlasSprite sprite = this.guiSprites.getSprite(location);
432
		GuiSpriteScaling scaling = getSpriteScaling(sprite);
433
		switch (scaling) {
434
			case GuiSpriteScaling.Stretch stretch:
435
				this.blitSprite(renderPipeline, sprite, x, y, width, height, color);
436
				break;
437
			case GuiSpriteScaling.Tile tile:
438
				this.blitTiledSprite(renderPipeline, sprite, x, y, width, height, 0, 0, tile.width(), tile.height(), tile.width(), tile.height(), color);
439
				break;
440
			case GuiSpriteScaling.NineSlice nineSlice:
441
				this.blitNineSlicedSprite(renderPipeline, sprite, nineSlice, x, y, width, height, color);
442
				break;
443
			default:
444
		}
445
	}
446
447
	public void blitSprite(
448
		final RenderPipeline renderPipeline,
449
		final Identifier location,
450
		final int spriteWidth,
451
		final int spriteHeight,
452
		final int textureX,
453
		final int textureY,
454
		final int x,
455
		final int y,
456
		final int width,
457
		final int height
458
	) {
459
		this.blitSprite(renderPipeline, location, spriteWidth, spriteHeight, textureX, textureY, x, y, width, height, -1);
460
	}
461
462
	public void blitSprite(
463
		final RenderPipeline renderPipeline,
464
		final Identifier location,
465
		final int spriteWidth,
466
		final int spriteHeight,
467
		final int textureX,
468
		final int textureY,
469
		final int x,
470
		final int y,
471
		final int width,
472
		final int height,
473
		final int color
474
	) {
475
		TextureAtlasSprite sprite = this.guiSprites.getSprite(location);
476
		GuiSpriteScaling scaling = getSpriteScaling(sprite);
477
		if (scaling instanceof GuiSpriteScaling.Stretch) {
478
			this.blitSprite(renderPipeline, sprite, spriteWidth, spriteHeight, textureX, textureY, x, y, width, height, color);
479
		} else {
480
			this.enableScissor(x, y, x + width, y + height);
481
			this.blitSprite(renderPipeline, location, x - textureX, y - textureY, spriteWidth, spriteHeight, color);
482
			this.disableScissor();
483
		}
484
	}
485
486
	public void blitSprite(final RenderPipeline renderPipeline, final TextureAtlasSprite sprite, final int x, final int y, final int width, final int height) {
487
		this.blitSprite(renderPipeline, sprite, x, y, width, height, -1);
488
	}
489
490
	public void blitSprite(
491
		final RenderPipeline renderPipeline, final TextureAtlasSprite sprite, final int x, final int y, final int width, final int height, final int color
492
	) {
493
		if (width != 0 && height != 0) {
494
			this.innerBlit(renderPipeline, sprite.atlasLocation(), x, x + width, y, y + height, sprite.getU0(), sprite.getU1(), sprite.getV0(), sprite.getV1(), color);
495
		}
496
	}
497
498
	private void blitSprite(
499
		final RenderPipeline renderPipeline,
500
		final TextureAtlasSprite sprite,
501
		final int spriteWidth,
502
		final int spriteHeight,
503
		final int textureX,
504
		final int textureY,
505
		final int x,
506
		final int y,
507
		final int width,
508
		final int height,
509
		final int color
510
	) {
511
		if (width != 0 && height != 0) {
512
			this.innerBlit(
513
				renderPipeline,
514
				sprite.atlasLocation(),
515
				x,
516
				x + width,
517
				y,
518
				y + height,
519
				sprite.getU((float)textureX / spriteWidth),
520
				sprite.getU((float)(textureX + width) / spriteWidth),
521
				sprite.getV((float)textureY / spriteHeight),
522
				sprite.getV((float)(textureY + height) / spriteHeight),
523
				color
524
			);
525
		}
526
	}
527
528
	private void blitNineSlicedSprite(
529
		final RenderPipeline renderPipeline,
530
		final TextureAtlasSprite sprite,
531
		final GuiSpriteScaling.NineSlice nineSlice,
532
		final int x,
533
		final int y,
534
		final int width,
535
		final int height,
536
		final int color
537
	) {
538
		Border border = nineSlice.border();
539
		int borderLeft = Math.min(border.left(), width / 2);
540
		int borderRight = Math.min(border.right(), width / 2);
541
		int borderTop = Math.min(border.top(), height / 2);
542
		int borderBottom = Math.min(border.bottom(), height / 2);
543
		if (width == nineSlice.width() && height == nineSlice.height()) {
544
			this.blitSprite(renderPipeline, sprite, nineSlice.width(), nineSlice.height(), 0, 0, x, y, width, height, color);
545
		} else if (height == nineSlice.height()) {
546
			this.blitSprite(renderPipeline, sprite, nineSlice.width(), nineSlice.height(), 0, 0, x, y, borderLeft, height, color);
547
			this.blitNineSliceInnerSegment(
548
				renderPipeline,
549
				nineSlice,
550
				sprite,
551
				x + borderLeft,
552
				y,
553
				width - borderRight - borderLeft,
554
				height,
555
				borderLeft,
556
				0,
557
				nineSlice.width() - borderRight - borderLeft,
558
				nineSlice.height(),
559
				nineSlice.width(),
560
				nineSlice.height(),
561
				color
562
			);
563
			this.blitSprite(
564
				renderPipeline, sprite, nineSlice.width(), nineSlice.height(), nineSlice.width() - borderRight, 0, x + width - borderRight, y, borderRight, height, color
565
			);
566
		} else if (width == nineSlice.width()) {
567
			this.blitSprite(renderPipeline, sprite, nineSlice.width(), nineSlice.height(), 0, 0, x, y, width, borderTop, color);
568
			this.blitNineSliceInnerSegment(
569
				renderPipeline,
570
				nineSlice,
571
				sprite,
572
				x,
573
				y + borderTop,
574
				width,
575
				height - borderBottom - borderTop,
576
				0,
577
				borderTop,
578
				nineSlice.width(),
579
				nineSlice.height() - borderBottom - borderTop,
580
				nineSlice.width(),
581
				nineSlice.height(),
582
				color
583
			);
584
			this.blitSprite(
585
				renderPipeline,
586
				sprite,
587
				nineSlice.width(),
588
				nineSlice.height(),
589
				0,
590
				nineSlice.height() - borderBottom,
591
				x,
592
				y + height - borderBottom,
593
				width,
594
				borderBottom,
595
				color
596
			);
597
		} else {
598
			this.blitSprite(renderPipeline, sprite, nineSlice.width(), nineSlice.height(), 0, 0, x, y, borderLeft, borderTop, color);
599
			this.blitNineSliceInnerSegment(
600
				renderPipeline,
601
				nineSlice,
602
				sprite,
603
				x + borderLeft,
604
				y,
605
				width - borderRight - borderLeft,
606
				borderTop,
607
				borderLeft,
608
				0,
609
				nineSlice.width() - borderRight - borderLeft,
610
				borderTop,
611
				nineSlice.width(),
612
				nineSlice.height(),
613
				color
614
			);
615
			this.blitSprite(
616
				renderPipeline,
617
				sprite,
618
				nineSlice.width(),
619
				nineSlice.height(),
620
				nineSlice.width() - borderRight,
621
				0,
622
				x + width - borderRight,
623
				y,
624
				borderRight,
625
				borderTop,
626
				color
627
			);
628
			this.blitSprite(
629
				renderPipeline,
630
				sprite,
631
				nineSlice.width(),
632
				nineSlice.height(),
633
				0,
634
				nineSlice.height() - borderBottom,
635
				x,
636
				y + height - borderBottom,
637
				borderLeft,
638
				borderBottom,
639
				color
640
			);
641
			this.blitNineSliceInnerSegment(
642
				renderPipeline,
643
				nineSlice,
644
				sprite,
645
				x + borderLeft,
646
				y + height - borderBottom,
647
				width - borderRight - borderLeft,
648
				borderBottom,
649
				borderLeft,
650
				nineSlice.height() - borderBottom,
651
				nineSlice.width() - borderRight - borderLeft,
652
				borderBottom,
653
				nineSlice.width(),
654
				nineSlice.height(),
655
				color
656
			);
657
			this.blitSprite(
658
				renderPipeline,
659
				sprite,
660
				nineSlice.width(),
661
				nineSlice.height(),
662
				nineSlice.width() - borderRight,
663
				nineSlice.height() - borderBottom,
664
				x + width - borderRight,
665
				y + height - borderBottom,
666
				borderRight,
667
				borderBottom,
668
				color
669
			);
670
			this.blitNineSliceInnerSegment(
671
				renderPipeline,
672
				nineSlice,
673
				sprite,
674
				x,
675
				y + borderTop,
676
				borderLeft,
677
				height - borderBottom - borderTop,
678
				0,
679
				borderTop,
680
				borderLeft,
681
				nineSlice.height() - borderBottom - borderTop,
682
				nineSlice.width(),
683
				nineSlice.height(),
684
				color
685
			);
686
			this.blitNineSliceInnerSegment(
687
				renderPipeline,
688
				nineSlice,
689
				sprite,
690
				x + borderLeft,
691
				y + borderTop,
692
				width - borderRight - borderLeft,
693
				height - borderBottom - borderTop,
694
				borderLeft,
695
				borderTop,
696
				nineSlice.width() - borderRight - borderLeft,
697
				nineSlice.height() - borderBottom - borderTop,
698
				nineSlice.width(),
699
				nineSlice.height(),
700
				color
701
			);
702
			this.blitNineSliceInnerSegment(
703
				renderPipeline,
704
				nineSlice,
705
				sprite,
706
				x + width - borderRight,
707
				y + borderTop,
708
				borderRight,
709
				height - borderBottom - borderTop,
710
				nineSlice.width() - borderRight,
711
				borderTop,
712
				borderRight,
713
				nineSlice.height() - borderBottom - borderTop,
714
				nineSlice.width(),
715
				nineSlice.height(),
716
				color
717
			);
718
		}
719
	}
720
721
	private void blitNineSliceInnerSegment(
722
		final RenderPipeline renderPipeline,
723
		final GuiSpriteScaling.NineSlice nineSlice,
724
		final TextureAtlasSprite sprite,
725
		final int x,
726
		final int y,
727
		final int width,
728
		final int height,
729
		final int textureX,
730
		final int textureY,
731
		final int textureWidth,
732
		final int textureHeight,
733
		final int spriteWidth,
734
		final int spriteHeight,
735
		final int color
736
	) {
737
		if (width > 0 && height > 0) {
738
			if (nineSlice.stretchInner()) {
739
				this.innerBlit(
740
					renderPipeline,
741
					sprite.atlasLocation(),
742
					x,
743
					x + width,
744
					y,
745
					y + height,
746
					sprite.getU((float)textureX / spriteWidth),
747
					sprite.getU((float)(textureX + textureWidth) / spriteWidth),
748
					sprite.getV((float)textureY / spriteHeight),
749
					sprite.getV((float)(textureY + textureHeight) / spriteHeight),
750
					color
751
				);
752
			} else {
753
				this.blitTiledSprite(renderPipeline, sprite, x, y, width, height, textureX, textureY, textureWidth, textureHeight, spriteWidth, spriteHeight, color);
754
			}
755
		}
756
	}
757
758
	private void blitTiledSprite(
759
		final RenderPipeline renderPipeline,
760
		final TextureAtlasSprite sprite,
761
		final int x,
762
		final int y,
763
		final int width,
764
		final int height,
765
		final int textureX,
766
		final int textureY,
767
		final int tileWidth,
768
		final int tileHeight,
769
		final int spriteWidth,
770
		final int spriteHeight,
771
		final int color
772
	) {
773
		if (width > 0 && height > 0) {
774
			if (tileWidth > 0 && tileHeight > 0) {
775
				AbstractTexture spriteTexture = this.minecraft.getTextureManager().getTexture(sprite.atlasLocation());
776
				GpuTextureView texture = spriteTexture.getTextureView();
777
				this.innerTiledBlit(
778
					renderPipeline,
779
					texture,
780
					spriteTexture.getSampler(),
781
					tileWidth,
782
					tileHeight,
783
					x,
784
					y,
785
					x + width,
786
					y + height,
787
					sprite.getU((float)textureX / spriteWidth),
788
					sprite.getU((float)(textureX + tileWidth) / spriteWidth),
789
					sprite.getV((float)textureY / spriteHeight),
790
					sprite.getV((float)(textureY + tileHeight) / spriteHeight),
791
					color
792
				);
793
			} else {
794
				throw new IllegalArgumentException("Tile size must be positive, got " + tileWidth + "x" + tileHeight);
795
			}
796
		}
797
	}
798
799
	private void innerBlit(
800
		final RenderPipeline renderPipeline,
801
		final Identifier location,
802
		final int x0,
803
		final int x1,
804
		final int y0,
805
		final int y1,
806
		final float u0,
807
		final float u1,
808
		final float v0,
809
		final float v1,
810
		final int color
811
	) {
812
		AbstractTexture texture = this.minecraft.getTextureManager().getTexture(location);
813
		this.innerBlit(renderPipeline, texture.getTextureView(), texture.getSampler(), x0, y0, x1, y1, u0, u1, v0, v1, color);
814
	}
815
816
	private void innerBlit(
817
		final RenderPipeline pipeline,
818
		final GpuTextureView textureView,
819
		final GpuSampler sampler,
820
		final int x0,
821
		final int y0,
822
		final int x1,
823
		final int y1,
824
		final float u0,
825
		final float u1,
826
		final float v0,
827
		final float v1,
828
		final int color
829
	) {
830
		this.guiRenderState
831
			.addGuiElement(
832
				new BlitRenderState(
833
					pipeline, TextureSetup.singleTexture(textureView, sampler), new Matrix3x2f(this.pose), x0, y0, x1, y1, u0, u1, v0, v1, color, this.scissorStack.peek()
834
				)
835
			);
836
	}
837
838
	private void innerTiledBlit(
839
		final RenderPipeline pipeline,
840
		final GpuTextureView textureView,
841
		final GpuSampler sampler,
842
		final int tileWidth,
843
		final int tileHeight,
844
		final int x0,
845
		final int y0,
846
		final int x1,
847
		final int y1,
848
		final float u0,
849
		final float u1,
850
		final float v0,
851
		final float v1,
852
		final int color
853
	) {
854
		this.guiRenderState
855
			.addGuiElement(
856
				new TiledBlitRenderState(
857
					pipeline,
858
					TextureSetup.singleTexture(textureView, sampler),
859
					new Matrix3x2f(this.pose),
860
					tileWidth,
861
					tileHeight,
862
					x0,
863
					y0,
864
					x1,
865
					y1,
866
					u0,
867
					u1,
868
					v0,
869
					v1,
870
					color,
871
					this.scissorStack.peek()
872
				)
873
			);
874
	}
875
876
	private static GuiSpriteScaling getSpriteScaling(final TextureAtlasSprite sprite) {
877
		return sprite.contents().getAdditionalMetadata(GuiMetadataSection.TYPE).orElse(GuiMetadataSection.DEFAULT).scaling();
878
	}
879
880
	public void item(final ItemStack itemStack, final int x, final int y) {
881
		this.item(this.minecraft.player, this.minecraft.level, itemStack, x, y, 0);
882
	}
883
884
	public void item(final ItemStack itemStack, final int x, final int y, final int seed) {
885
		this.item(this.minecraft.player, this.minecraft.level, itemStack, x, y, seed);
886
	}
887
888
	public void item(final LivingEntity owner, final ItemStack itemStack, final int x, final int y, final int seed) {
889
		this.item(owner, owner.level(), itemStack, x, y, seed);
890
	}
891
892
	private void item(final @Nullable LivingEntity owner, final @Nullable Level level, final ItemStack itemStack, final int x, final int y, final int seed) {
893
		if (!itemStack.isEmpty()) {
894
			TrackingItemStackRenderState itemStackRenderState = new TrackingItemStackRenderState();
895
			this.minecraft.getItemModelResolver().updateForTopItem(itemStackRenderState, itemStack, ItemDisplayContext.GUI, level, owner, seed);
896
897
			try {
898
				this.guiRenderState.addItem(new GuiItemRenderState(new Matrix3x2f(this.pose), itemStackRenderState, x, y, this.scissorStack.peek()));
899
			} catch (Throwable t) {
900
				CrashReport report = CrashReport.forThrowable(t, "Rendering item");
901
				CrashReportCategory category = report.addCategory("Item being rendered");
902
				category.setDetail("Item Type", () -> String.valueOf(itemStack.getItem()));
903
				category.setDetail("Item Components", () -> String.valueOf(itemStack.getComponents()));
904
				category.setDetail("Item Foil", () -> String.valueOf(itemStack.hasFoil()));
905
				throw new ReportedException(report);
906
			}
907
		}
908
	}
909
910
	public void fakeItem(final ItemStack itemStack, final int x, final int y) {
911
		this.fakeItem(itemStack, x, y, 0);
912
	}
913
914
	public void fakeItem(final ItemStack itemStack, final int x, final int y, final int seed) {
915
		this.item(null, this.minecraft.level, itemStack, x, y, seed);
916
	}
917
918
	public void itemDecorations(final Font font, final ItemStack itemStack, final int x, final int y) {
919
		this.itemDecorations(font, itemStack, x, y, null);
920
	}
921
922
	public void itemDecorations(final Font font, final ItemStack itemStack, final int x, final int y, final @Nullable String countText) {
923
		if (!itemStack.isEmpty()) {
924
			this.pose.pushMatrix();
925
			this.itemBar(itemStack, x, y);
926
			this.itemCooldown(itemStack, x, y);
927
			this.itemCount(font, itemStack, x, y, countText);
928
			this.pose.popMatrix();
929
		}
930
	}
931
932
	private void itemBar(final ItemStack itemStack, final int x, final int y) {
933
		if (itemStack.isBarVisible()) {
934
			int left = x + 2;
935
			int top = y + 13;
936
			this.fill(RenderPipelines.GUI, left, top, left + 13, top + 2, -16777216);
937
			this.fill(RenderPipelines.GUI, left, top, left + itemStack.getBarWidth(), top + 1, ARGB.opaque(itemStack.getBarColor()));
938
		}
939
	}
940
941
	private void itemCount(final Font font, final ItemStack itemStack, final int x, final int y, final @Nullable String countText) {
942
		if (itemStack.getCount() != 1 || countText != null) {
943
			String amount = countText == null ? String.valueOf(itemStack.getCount()) : countText;
944
			this.text(font, amount, x + 19 - 2 - font.width(amount), y + 6 + 3, -1, true);
945
		}
946
	}
947
948
	private void itemCooldown(final ItemStack itemStack, final int x, final int y) {
949
		LocalPlayer player = this.minecraft.player;
950
		float cooldown = player == null
951
			? 0.0F
952
			: player.getCooldowns().getCooldownPercent(itemStack, this.minecraft.getDeltaTracker().getGameTimeDeltaPartialTick(true));
953
		if (cooldown > 0.0F) {
954
			int top = y + Mth.floor(16.0F * (1.0F - cooldown));
955
			int bottom = top + Mth.ceil(16.0F * cooldown);
956
			this.fill(RenderPipelines.GUI, x, top, x + 16, bottom, Integer.MAX_VALUE);
957
		}
958
	}
959
960
	public void map(final MapRenderState mapRenderState) {
961
		Minecraft minecraft = Minecraft.getInstance();
962
		TextureManager textureManager = minecraft.getTextureManager();
963
		AbstractTexture texture = textureManager.getTexture(mapRenderState.texture);
964
		this.innerBlit(RenderPipelines.GUI_TEXTURED, texture.getTextureView(), texture.getSampler(), 0, 0, 128, 128, 0.0F, 1.0F, 0.0F, 1.0F, -1);
965
966
		for (MapRenderState.MapDecorationRenderState decoration : mapRenderState.decorations) {
967
			if (decoration.renderOnFrame) {
968
				this.pose.pushMatrix();
969
				this.pose.translate(decoration.x / 2.0F + 64.0F, decoration.y / 2.0F + 64.0F);
970
				this.pose.rotate((float) (Math.PI / 180.0) * decoration.rot * 360.0F / 16.0F);
971
				this.pose.scale(4.0F, 4.0F);
972
				this.pose.translate(-0.125F, 0.125F);
973
				TextureAtlasSprite atlasSprite = decoration.atlasSprite;
974
				if (atlasSprite != null) {
975
					AbstractTexture decorationTexture = textureManager.getTexture(atlasSprite.atlasLocation());
976
					this.innerBlit(
977
						RenderPipelines.GUI_TEXTURED,
978
						decorationTexture.getTextureView(),
979
						decorationTexture.getSampler(),
980
						-1,
981
						-1,
982
						1,
983
						1,
984
						atlasSprite.getU0(),
985
						atlasSprite.getU1(),
986
						atlasSprite.getV1(),
987
						atlasSprite.getV0(),
988
						-1
989
					);
990
				}
991
992
				this.pose.popMatrix();
993
				if (decoration.name != null) {
994
					Font font = minecraft.font;
995
					float width = font.width(decoration.name);
996
					float scale = Mth.clamp(25.0F / width, 0.0F, 6.0F / 9.0F);
997
					this.pose.pushMatrix();
998
					this.pose.translate(decoration.x / 2.0F + 64.0F - width * scale / 2.0F, decoration.y / 2.0F + 64.0F + 4.0F);
999
					this.pose.scale(scale, scale);
1000
					this.guiRenderState
1001
						.addText(
1002
							new GuiTextRenderState(
1003
								font, decoration.name.getVisualOrderText(), new Matrix3x2f(this.pose), 0, 0, -1, Integer.MIN_VALUE, false, false, this.scissorStack.peek()
1004
							)
1005
						);
1006
					this.pose.popMatrix();
1007
				}
1008
			}
1009
		}
1010
	}
1011
1012
	public void entity(
1013
		final EntityRenderState renderState,
1014
		final float scale,
1015
		final Vector3fc translation,
1016
		final Quaternionfc rotation,
1017
		final @Nullable Quaternionfc overrideCameraAngle,
1018
		final int x0,
1019
		final int y0,
1020
		final int x1,
1021
		final int y1
1022
	) {
1023
		renderState.lightCoords = 15728880;
1024
		this.guiRenderState
1025
			.addPicturesInPictureState(
1026
				new GuiEntityRenderState(renderState, translation, rotation, overrideCameraAngle, x0, y0, x1, y1, scale, this.scissorStack.peek())
1027
			);
1028
	}
1029
1030
	public void skin(
1031
		final Model.Simple playerModel,
1032
		final Identifier texture,
1033
		final float scale,
1034
		final float rotationX,
1035
		final float rotationY,
1036
		final float pivotY,
1037
		final int x0,
1038
		final int y0,
1039
		final int x1,
1040
		final int y1
1041
	) {
1042
		this.guiRenderState
1043
			.addPicturesInPictureState(new GuiSkinRenderState(playerModel, texture, rotationX, rotationY, pivotY, x0, y0, x1, y1, scale, this.scissorStack.peek()));
1044
	}
1045
1046
	public void book(
1047
		final BookModel bookModel,
1048
		final Identifier texture,
1049
		final float scale,
1050
		final float open,
1051
		final float flip,
1052
		final int x0,
1053
		final int y0,
1054
		final int x1,
1055
		final int y1
1056
	) {
1057
		this.guiRenderState.addPicturesInPictureState(new GuiBookModelRenderState(bookModel, texture, open, flip, x0, y0, x1, y1, scale, this.scissorStack.peek()));
1058
	}
1059
1060
	public void bannerPattern(
1061
		final BannerFlagModel flag, final DyeColor baseColor, final BannerPatternLayers resultBannerPatterns, final int x0, final int y0, final int x1, final int y1
1062
	) {
1063
		this.guiRenderState
1064
			.addPicturesInPictureState(new GuiBannerResultRenderState(flag, baseColor, resultBannerPatterns, x0, y0, x1, y1, this.scissorStack.peek()));
1065
	}
1066
1067
	public void profilerChart(final List<ResultField> chartData, final int x0, final int y0, final int x1, final int y1) {
1068
		this.guiRenderState
1069
			.addPicturesInPictureState(new GuiProfilerChartRenderState(new Matrix3x2f(this.pose), chartData, x0, y0, x1, y1, this.scissorStack.peek()));
1070
	}
1071
1072
	public void setTooltipForNextFrame(final Component component, final int x, final int y) {
1073
		this.setTooltipForNextFrame(List.of(component.getVisualOrderText()), x, y);
1074
	}
1075
1076
	public void setTooltipForNextFrame(final List<FormattedCharSequence> formattedCharSequences, final int x, final int y) {
1077
		this.setTooltipForNextFrame(this.minecraft.font, formattedCharSequences, DefaultTooltipPositioner.INSTANCE, x, y, false);
1078
	}
1079
1080
	public void setTooltipForNextFrame(final Font font, final ItemStack itemStack, final int xo, final int yo) {
1081
		this.setTooltipForNextFrame(
1082
			font, Screen.getTooltipFromItem(this.minecraft, itemStack), itemStack.getTooltipImage(), xo, yo, itemStack.get(DataComponents.TOOLTIP_STYLE), true
1083
		);
1084
	}
1085
1086
	public void setTooltipForNextFrame(final Font font, final List<Component> texts, final Optional<TooltipComponent> optionalImage, final int xo, final int yo) {
1087
		this.setTooltipForNextFrame(font, texts, optionalImage, xo, yo, null);
1088
	}
1089
1090
	public void setTooltipForNextFrame(
1091
		final Font font, final List<Component> texts, final Optional<TooltipComponent> optionalImage, final int xo, final int yo, final @Nullable Identifier style
1092
	) {
1093
		this.setTooltipForNextFrame(font, texts, optionalImage, xo, yo, style, false);
1094
	}
1095
1096
	public void setTooltipForNextFrame(
1097
		final Font font,
1098
		final List<Component> texts,
1099
		final Optional<TooltipComponent> optionalImage,
1100
		final int xo,
1101
		final int yo,
1102
		final @Nullable Identifier style,
1103
		final boolean extraSpaceAfterFirstLine
1104
	) {
1105
		List<ClientTooltipComponent> components = texts.stream().map(Component::getVisualOrderText).map(ClientTooltipComponent::create).collect(Util.toMutableList());
1106
		optionalImage.ifPresent(image -> components.add(components.isEmpty() ? 0 : 1, ClientTooltipComponent.create(image)));
1107
		this.setTooltipForNextFrameInternal(font, components, xo, yo, DefaultTooltipPositioner.INSTANCE, style, false, extraSpaceAfterFirstLine);
1108
	}
1109
1110
	public void setTooltipForNextFrame(
1111
		final Font font,
1112
		final List<FormattedCharSequence> tooltip,
1113
		final Optional<TooltipComponent> component,
1114
		final ClientTooltipPositioner positioner,
1115
		final int xo,
1116
		final int yo,
1117
		final boolean replaceExisting,
1118
		final @Nullable Identifier style
1119
	) {
1120
		List<ClientTooltipComponent> components = tooltip.stream().map(ClientTooltipComponent::create).collect(Collectors.toList());
1121
		component.ifPresent(tooltipComponent -> components.add(components.isEmpty() ? 0 : 1, ClientTooltipComponent.create(tooltipComponent)));
1122
		this.setTooltipForNextFrameInternal(font, components, xo, yo, positioner, style, replaceExisting);
1123
	}
1124
1125
	public void setTooltipForNextFrame(final Font font, final Component text, final int xo, final int yo) {
1126
		this.setTooltipForNextFrame(font, text, xo, yo, null);
1127
	}
1128
1129
	public void setTooltipForNextFrame(final Font font, final Component text, final int xo, final int yo, final @Nullable Identifier style) {
1130
		this.setTooltipForNextFrame(font, List.of(text.getVisualOrderText()), xo, yo, style);
1131
	}
1132
1133
	public void setComponentTooltipForNextFrame(final Font font, final List<Component> lines, final int xo, final int yo) {
1134
		this.setComponentTooltipForNextFrame(font, lines, xo, yo, null);
1135
	}
1136
1137
	public void setComponentTooltipForNextFrame(final Font font, final List<Component> lines, final int xo, final int yo, final @Nullable Identifier style) {
1138
		this.setTooltipForNextFrameInternal(
1139
			font,
1140
			lines.stream().map(Component::getVisualOrderText).map(ClientTooltipComponent::create).toList(),
1141
			xo,
1142
			yo,
1143
			DefaultTooltipPositioner.INSTANCE,
1144
			style,
1145
			false
1146
		);
1147
	}
1148
1149
	public void setTooltipForNextFrame(final Font font, final List<? extends FormattedCharSequence> lines, final int xo, final int yo) {
1150
		this.setTooltipForNextFrame(font, lines, xo, yo, null);
1151
	}
1152
1153
	public void setTooltipForNextFrame(
1154
		final Font font, final List<? extends FormattedCharSequence> lines, final int xo, final int yo, final @Nullable Identifier style
1155
	) {
1156
		this.setTooltipForNextFrameInternal(
1157
			font, lines.stream().map(ClientTooltipComponent::create).collect(Collectors.toList()), xo, yo, DefaultTooltipPositioner.INSTANCE, style, false
1158
		);
1159
	}
1160
1161
	public void setTooltipForNextFrame(
1162
		final Font font,
1163
		final List<FormattedCharSequence> tooltip,
1164
		final ClientTooltipPositioner positioner,
1165
		final int xo,
1166
		final int yo,
1167
		final boolean replaceExisting
1168
	) {
1169
		this.setTooltipForNextFrameInternal(
1170
			font, tooltip.stream().map(ClientTooltipComponent::create).collect(Collectors.toList()), xo, yo, positioner, null, replaceExisting
1171
		);
1172
	}
1173
1174
	private void setTooltipForNextFrameInternal(
1175
		final Font font,
1176
		final List<ClientTooltipComponent> lines,
1177
		final int xo,
1178
		final int yo,
1179
		final ClientTooltipPositioner positioner,
1180
		final @Nullable Identifier style,
1181
		final boolean replaceExisting
1182
	) {
1183
		this.setTooltipForNextFrameInternal(font, lines, xo, yo, positioner, style, replaceExisting, false);
1184
	}
1185
1186
	private void setTooltipForNextFrameInternal(
1187
		final Font font,
1188
		final List<ClientTooltipComponent> lines,
1189
		final int xo,
1190
		final int yo,
1191
		final ClientTooltipPositioner positioner,
1192
		final @Nullable Identifier style,
1193
		final boolean replaceExisting,
1194
		final boolean extraSpaceAfterFirstLine
1195
	) {
1196
		if (!lines.isEmpty()) {
1197
			if (this.deferredTooltip == null || replaceExisting) {
1198
				this.deferredTooltip = () -> this.tooltip(font, lines, xo, yo, positioner, style, extraSpaceAfterFirstLine);
1199
			}
1200
		}
1201
	}
1202
1203
	public void tooltip(
1204
		final Font font,
1205
		final List<ClientTooltipComponent> lines,
1206
		final int xo,
1207
		final int yo,
1208
		final ClientTooltipPositioner positioner,
1209
		final @Nullable Identifier style,
1210
		boolean extraSpaceAfterFirstLine
1211
	) {
1212
		int textWidth = 0;
1213
		int tempHeight = extraSpaceAfterFirstLine && lines.size() != 1 ? 0 : -2;
1214
1215
		for (ClientTooltipComponent line : lines) {
1216
			int lineWidth = line.getWidth(font);
1217
			if (lineWidth > textWidth) {
1218
				textWidth = lineWidth;
1219
			}
1220
1221
			tempHeight += line.getHeight(font);
1222
		}
1223
1224
		int w = textWidth;
1225
		int h = tempHeight;
1226
		Vector2ic positionedTooltip = positioner.positionTooltip(this.guiWidth(), this.guiHeight(), xo, yo, w, h);
1227
		int x = positionedTooltip.x();
1228
		int y = positionedTooltip.y();
1229
		this.pose.pushMatrix();
1230
		TooltipRenderUtil.extractTooltipBackground(this, x, y, w, h, style);
1231
		int localY = y;
1232
1233
		for (int i = 0; i < lines.size(); i++) {
1234
			ClientTooltipComponent line = lines.get(i);
1235
			line.extractText(this, font, x, localY);
1236
			localY += line.getHeight(font) + (extraSpaceAfterFirstLine && i == 0 ? 2 : 0);
1237
		}
1238
1239
		localY = y;
1240
1241
		for (int i = 0; i < lines.size(); i++) {
1242
			ClientTooltipComponent line = lines.get(i);
1243
			line.extractImage(font, x, localY, w, h, this);
1244
			localY += line.getHeight(font) + (extraSpaceAfterFirstLine && i == 0 ? 2 : 0);
1245
		}
1246
1247
		this.pose.popMatrix();
1248
	}
1249
1250
	public void setPreeditOverlay(final Renderable preeditOverlay) {
1251
		this.preeditOverlay = preeditOverlay;
1252
	}
1253
1254
	public void extractDeferredElements(final int mouseX, final int mouseY, final float a) {
1255
		if (this.hoveredTextStyle != null) {
1256
			this.componentHoverEffect(this.minecraft.font, this.hoveredTextStyle, mouseX, mouseY);
1257
		}
1258
1259
		if (this.clickableTextStyle != null && this.clickableTextStyle.getClickEvent() != null) {
1260
			this.requestCursor(CursorTypes.POINTING_HAND);
1261
		}
1262
1263
		if (this.preeditOverlay != null) {
1264
			this.nextStratum();
1265
			this.preeditOverlay.extractRenderState(this, mouseX, mouseY, a);
1266
		}
1267
1268
		if (this.deferredTooltip != null) {
1269
			this.nextStratum();
1270
			this.deferredTooltip.run();
1271
			this.deferredTooltip = null;
1272
		}
1273
	}
1274
1275
	private void componentHoverEffect(final Font font, final Style hoveredStyle, final int xMouse, final int yMouse) {
1276
		if (hoveredStyle.getHoverEvent() != null) {
1277
			switch (hoveredStyle.getHoverEvent()) {
1278
				case ShowItem(ItemStackTemplate item):
1279
					this.setTooltipForNextFrame(font, item.create(), xMouse, yMouse);
1280
					break;
1281
				case ShowEntity(EntityTooltipInfo entity):
1282
					if (this.minecraft.options.advancedItemTooltips) {
1283
						this.setComponentTooltipForNextFrame(font, entity.getTooltipLines(), xMouse, yMouse);
1284
					}
1285
					break;
1286
				case ShowText(Component text):
1287
					this.setTooltipForNextFrame(font, font.split(text, Math.max(this.guiWidth() / 2, 200)), xMouse, yMouse);
1288
					break;
1289
				default:
1290
			}
1291
		}
1292
	}
1293
1294
	public TextureAtlasSprite getSprite(final SpriteId sprite) {
1295
		return this.sprites.get(sprite);
1296
	}
1297
1298
	public ActiveTextCollector textRendererForWidget(final AbstractWidget owner, final GuiGraphicsExtractor.HoveredTextEffects hoveredTextEffects) {
1299
		return new GuiGraphicsExtractor.RenderingTextCollector(this.createDefaultTextParameters(owner.getAlpha()), hoveredTextEffects, null);
1300
	}
1301
1302
	public ActiveTextCollector textRenderer() {
1303
		return this.textRenderer(GuiGraphicsExtractor.HoveredTextEffects.TOOLTIP_ONLY);
1304
	}
1305
1306
	public ActiveTextCollector textRenderer(final GuiGraphicsExtractor.HoveredTextEffects hoveredTextEffects) {
1307
		return this.textRenderer(hoveredTextEffects, null);
1308
	}
1309
1310
	public ActiveTextCollector textRenderer(
1311
		final GuiGraphicsExtractor.HoveredTextEffects hoveredTextEffects, final @Nullable Consumer<Style> additionalHoverStyleConsumer
1312
	) {
1313
		return new GuiGraphicsExtractor.RenderingTextCollector(this.createDefaultTextParameters(1.0F), hoveredTextEffects, additionalHoverStyleConsumer);
1314
	}
1315
1316
	private ActiveTextCollector.Parameters createDefaultTextParameters(final float opacity) {
1317
		return new ActiveTextCollector.Parameters(new Matrix3x2f(this.pose), opacity, this.scissorStack.peek());
1318
	}
1319
1320
	@Environment(EnvType.CLIENT)
1321
	public enum HoveredTextEffects {
1322
		NONE(false, false),
1323
		TOOLTIP_ONLY(true, false),
1324
		TOOLTIP_AND_CURSOR(true, true);
1325
1326
		public final boolean allowTooltip;
1327
		public final boolean allowCursorChanges;
1328
1329
		HoveredTextEffects(final boolean allowTooltip, final boolean allowCursorChanges) {
1330
			this.allowTooltip = allowTooltip;
1331
			this.allowCursorChanges = allowCursorChanges;
1332
		}
1333
1334
		public static GuiGraphicsExtractor.HoveredTextEffects notClickable(final boolean canTooltip) {
1335
			return canTooltip ? TOOLTIP_ONLY : NONE;
1336
		}
1337
	}
1338
1339
	@Environment(EnvType.CLIENT)
1340
	private class RenderingTextCollector implements ActiveTextCollector, Consumer<Style> {
1341
		private ActiveTextCollector.Parameters defaultParameters;
1342
		private final GuiGraphicsExtractor.HoveredTextEffects hoveredTextEffects;
1343
		private final @Nullable Consumer<Style> additionalConsumer;
1344
1345
		private RenderingTextCollector(
1346
			final ActiveTextCollector.Parameters initialParameters,
1347
			final GuiGraphicsExtractor.HoveredTextEffects hoveredTextEffects,
1348
			final @Nullable Consumer<Style> additonalConsumer
1349
		) {
1350
			this.defaultParameters = initialParameters;
1351
			this.hoveredTextEffects = hoveredTextEffects;
1352
			this.additionalConsumer = additonalConsumer;
1353
		}
1354
1355
		@Override
1356
		public ActiveTextCollector.Parameters defaultParameters() {
1357
			return this.defaultParameters;
1358
		}
1359
1360
		@Override
1361
		public void defaultParameters(final ActiveTextCollector.Parameters newParameters) {
1362
			this.defaultParameters = newParameters;
1363
		}
1364
1365
		public void accept(final Style style) {
1366
			if (this.hoveredTextEffects.allowTooltip && style.getHoverEvent() != null) {
1367
				GuiGraphicsExtractor.this.hoveredTextStyle = style;
1368
			}
1369
1370
			if (this.hoveredTextEffects.allowCursorChanges && style.getClickEvent() != null) {
1371
				GuiGraphicsExtractor.this.clickableTextStyle = style;
1372
			}
1373
1374
			if (this.additionalConsumer != null) {
1375
				this.additionalConsumer.accept(style);
1376
			}
1377
		}
1378
1379
		@Override
1380
		public void accept(
1381
			final TextAlignment alignment, final int anchorX, final int y, final ActiveTextCollector.Parameters parameters, final FormattedCharSequence text
1382
		) {
1383
			boolean needsFullStyleScan = this.hoveredTextEffects.allowCursorChanges || this.hoveredTextEffects.allowTooltip || this.additionalConsumer != null;
1384
			int leftX = alignment.calculateLeft(anchorX, GuiGraphicsExtractor.this.minecraft.font, text);
1385
			GuiTextRenderState renderState = new GuiTextRenderState(
1386
				GuiGraphicsExtractor.this.minecraft.font,
1387
				text,
1388
				parameters.pose(),
1389
				leftX,
1390
				y,
1391
				ARGB.white(parameters.opacity()),
1392
				0,
1393
				true,
1394
				needsFullStyleScan,
1395
				parameters.scissor()
1396
			);
1397
			if (ARGB.as8BitChannel(parameters.opacity()) != 0) {
1398
				GuiGraphicsExtractor.this.guiRenderState.addText(renderState);
1399
			}
1400
1401
			if (needsFullStyleScan) {
1402
				ActiveTextCollector.findElementUnderCursor(renderState, GuiGraphicsExtractor.this.mouseX, GuiGraphicsExtractor.this.mouseY, this);
1403
			}
1404
		}
1405
1406
		@Override
1407
		public void acceptScrolling(
1408
			final Component message,
1409
			final int centerX,
1410
			final int left,
1411
			final int right,
1412
			final int top,
1413
			final int bottom,
1414
			final ActiveTextCollector.Parameters parameters
1415
		) {
1416
			int lineWidth = GuiGraphicsExtractor.this.minecraft.font.width(message);
1417
			int lineHeight = 9;
1418
			this.defaultScrollingHelper(message, centerX, left, right, top, bottom, lineWidth, lineHeight, parameters);
1419
		}
1420
	}
1421
1422
	/**
1423
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
1424
	 */
1425
	@Environment(EnvType.CLIENT)
1426
	public static class ScissorStack {
1427
		private final ScreenRectangle screenSize;
1428
		private final Deque<ScreenRectangle> stack = new ArrayDeque<>();
1429
1430
		private ScissorStack(final ScreenRectangle screenSize) {
1431
			this.screenSize = screenSize;
1432
		}
1433
1434
		public void push(final ScreenRectangle rectangle) {
1435
			ScreenRectangle lastRectangle = Objects.requireNonNullElse(this.stack.peekLast(), this.screenSize);
1436
			ScreenRectangle intersection = Objects.requireNonNullElse(rectangle.intersection(lastRectangle), ScreenRectangle.empty());
1437
			this.stack.addLast(intersection);
1438
		}
1439
1440
		public void pop() {
1441
			if (this.stack.isEmpty()) {
1442
				throw new IllegalStateException("Scissor stack underflow");
1443
			}
1444
1445
			this.stack.removeLast();
1446
		}
1447
1448
		public @Nullable ScreenRectangle peek() {
1449
			return this.stack.peekLast();
1450
		}
1451
1452
		public boolean containsPoint(final int x, final int y) {
1453
			return this.stack.isEmpty() ? true : this.stack.peek().containsPoint(x, y);
1454
		}
1455
	}
1456
}
1457

Decompiled Minecraft 26.3 source of GuiGraphicsExtractor (net/minecraft/client/gui/GuiGraphicsExtractor.java) with Mojang official mappings, stored verbatim on the site.