TiledBlitRenderState .java

net.minecraft.client.renderer.state.gui.TiledBlitRenderState (record): members: pipeline, textureSetup, pose, tileWidth, tileHeight, x0, y0, x1, y1, u0.

net.minecraft.client.renderer.state.guirecord100 linesclient3.1 KB

Implements

API Surface (1)

void buildVertices(final VertexConsumer vertexConsumer)

Fields & Constants (14)

pipeline
textureSetup
pose
tileWidth
tileHeight
x0
y0
x1
y1
u0
u1
v0
v1
color

Code Graph: Dependencies (6)

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

Full Source

TiledBlitRenderState.java100 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.state.gui;
2
3
import com.mojang.blaze3d.vertex.VertexConsumer;
4
import com.mojang.renderpearl.api.pipeline.RenderPipeline;
5
import net.fabricmc.api.EnvType;
6
import net.fabricmc.api.Environment;
7
import net.minecraft.client.gui.navigation.ScreenRectangle;
8
import net.minecraft.client.gui.render.TextureSetup;
9
import net.minecraft.util.Mth;
10
import org.joml.Matrix3x2f;
11
import org.jspecify.annotations.Nullable;
12
13
@Environment(EnvType.CLIENT)
14
public record TiledBlitRenderState(
15
	RenderPipeline pipeline,
16
	TextureSetup textureSetup,
17
	Matrix3x2f pose,
18
	int tileWidth,
19
	int tileHeight,
20
	int x0,
21
	int y0,
22
	int x1,
23
	int y1,
24
	float u0,
25
	float u1,
26
	float v0,
27
	float v1,
28
	int color,
29
	@Nullable ScreenRectangle scissorArea,
30
	@Nullable ScreenRectangle bounds
31
) implements GuiElementRenderState {
32
	public TiledBlitRenderState(
33
		final RenderPipeline pipeline,
34
		final TextureSetup textureSetup,
35
		final Matrix3x2f pose,
36
		final int tileWidth,
37
		final int tileHeight,
38
		final int x0,
39
		final int y0,
40
		final int x1,
41
		final int y1,
42
		final float u0,
43
		final float u1,
44
		final float v0,
45
		final float v1,
46
		final int color,
47
		final @Nullable ScreenRectangle scissorArea
48
	) {
49
		this(pipeline, textureSetup, pose, tileWidth, tileHeight, x0, y0, x1, y1, u0, u1, v0, v1, color, scissorArea, getBounds(x0, y0, x1, y1, pose, scissorArea));
50
	}
51
52
	@Override
53
	public void buildVertices(final VertexConsumer vertexConsumer) {
54
		int width = this.x1() - this.x0();
55
		int height = this.y1() - this.y0();
56
57
		for (int tileX = 0; tileX < width; tileX += this.tileWidth()) {
58
			int remainingWidth = width - tileX;
59
			int tileWidth;
60
			float u1;
61
			if (this.tileWidth() <= remainingWidth) {
62
				tileWidth = this.tileWidth();
63
				u1 = this.u1();
64
			} else {
65
				tileWidth = remainingWidth;
66
				u1 = Mth.lerp((float)remainingWidth / this.tileWidth(), this.u0(), this.u1());
67
			}
68
69
			for (int tileY = 0; tileY < height; tileY += this.tileHeight()) {
70
				int remainingHeight = height - tileY;
71
				int tileHeight;
72
				float v1;
73
				if (this.tileHeight() <= remainingHeight) {
74
					tileHeight = this.tileHeight();
75
					v1 = this.v1();
76
				} else {
77
					tileHeight = remainingHeight;
78
					v1 = Mth.lerp((float)remainingHeight / this.tileHeight(), this.v0(), this.v1());
79
				}
80
81
				int x0 = this.x0() + tileX;
82
				int x1 = this.x0() + tileX + tileWidth;
83
				int y0 = this.y0() + tileY;
84
				int y1 = this.y0() + tileY + tileHeight;
85
				vertexConsumer.addVertexWith2DPose(this.pose(), x0, y0).setUv(this.u0(), this.v0()).setColor(this.color());
86
				vertexConsumer.addVertexWith2DPose(this.pose(), x0, y1).setUv(this.u0(), v1).setColor(this.color());
87
				vertexConsumer.addVertexWith2DPose(this.pose(), x1, y1).setUv(u1, v1).setColor(this.color());
88
				vertexConsumer.addVertexWith2DPose(this.pose(), x1, y0).setUv(u1, this.v0()).setColor(this.color());
89
			}
90
		}
91
	}
92
93
	private static @Nullable ScreenRectangle getBounds(
94
		final int x0, final int y0, final int x1, final int y1, final Matrix3x2f pose, final @Nullable ScreenRectangle scissorArea
95
	) {
96
		ScreenRectangle bounds = new ScreenRectangle(x0, y0, x1 - x0, y1 - y0).transformMaxBounds(pose);
97
		return scissorArea != null ? scissorArea.intersection(bounds) : bounds;
98
	}
99
}
100

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