minecraft-src/net/minecraft/client/gui/font/glyphs/BakedGlyph.java
2025-07-04 02:49:36 +03:00

79 lines
3.1 KiB
Java

package net.minecraft.client.gui.font.glyphs;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.font.GlyphRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.Style;
import org.joml.Matrix4f;
@Environment(EnvType.CLIENT)
public class BakedGlyph {
private final GlyphRenderTypes renderTypes;
private final float u0;
private final float u1;
private final float v0;
private final float v1;
private final float left;
private final float right;
private final float up;
private final float down;
public BakedGlyph(GlyphRenderTypes renderTypes, float u0, float u1, float v0, float v1, float left, float right, float up, float down) {
this.renderTypes = renderTypes;
this.u0 = u0;
this.u1 = u1;
this.v0 = v0;
this.v1 = v1;
this.left = left;
this.right = right;
this.up = up;
this.down = down;
}
public void renderChar(BakedGlyph.GlyphInstance glyph, Matrix4f pose, VertexConsumer buffer, int packedLight) {
Style style = glyph.style();
boolean bl = style.isItalic();
float f = glyph.x();
float g = glyph.y();
int i = glyph.color();
this.render(bl, f, g, pose, buffer, i, packedLight);
if (style.isBold()) {
this.render(bl, f + glyph.boldOffset(), g, pose, buffer, i, packedLight);
}
}
private void render(boolean italic, float x, float y, Matrix4f pose, VertexConsumer buffer, int color, int packedLight) {
float f = x + this.left;
float g = x + this.right;
float h = y + this.up;
float i = y + this.down;
float j = italic ? 1.0F - 0.25F * this.up : 0.0F;
float k = italic ? 1.0F - 0.25F * this.down : 0.0F;
buffer.addVertex(pose, f + j, h, 0.0F).setColor(color).setUv(this.u0, this.v0).setLight(packedLight);
buffer.addVertex(pose, f + k, i, 0.0F).setColor(color).setUv(this.u0, this.v1).setLight(packedLight);
buffer.addVertex(pose, g + k, i, 0.0F).setColor(color).setUv(this.u1, this.v1).setLight(packedLight);
buffer.addVertex(pose, g + j, h, 0.0F).setColor(color).setUv(this.u1, this.v0).setLight(packedLight);
}
public void renderEffect(BakedGlyph.Effect effect, Matrix4f matrix, VertexConsumer buffer, int packedLight) {
buffer.addVertex(matrix, effect.x0, effect.y0, effect.depth).setColor(effect.color).setUv(this.u0, this.v0).setLight(packedLight);
buffer.addVertex(matrix, effect.x1, effect.y0, effect.depth).setColor(effect.color).setUv(this.u0, this.v1).setLight(packedLight);
buffer.addVertex(matrix, effect.x1, effect.y1, effect.depth).setColor(effect.color).setUv(this.u1, this.v1).setLight(packedLight);
buffer.addVertex(matrix, effect.x0, effect.y1, effect.depth).setColor(effect.color).setUv(this.u1, this.v0).setLight(packedLight);
}
public RenderType renderType(Font.DisplayMode displayMode) {
return this.renderTypes.select(displayMode);
}
@Environment(EnvType.CLIENT)
public record Effect(float x0, float y0, float x1, float y1, float depth, int color) {
}
@Environment(EnvType.CLIENT)
public record GlyphInstance(float x, float y, int color, BakedGlyph glyph, Style style, float boldOffset) {
}
}