79 lines
3.2 KiB
Java
79 lines
3.2 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 glyphInstance, Matrix4f matrix4f, VertexConsumer vertexConsumer, int i) {
|
|
Style style = glyphInstance.style();
|
|
boolean bl = style.isItalic();
|
|
float f = glyphInstance.x();
|
|
float g = glyphInstance.y();
|
|
int j = glyphInstance.color();
|
|
this.render(bl, f, g, matrix4f, vertexConsumer, j, i);
|
|
if (style.isBold()) {
|
|
this.render(bl, f + glyphInstance.boldOffset(), g, matrix4f, vertexConsumer, j, i);
|
|
}
|
|
}
|
|
|
|
private void render(boolean bl, float f, float g, Matrix4f matrix4f, VertexConsumer vertexConsumer, int i, int j) {
|
|
float h = f + this.left;
|
|
float k = f + this.right;
|
|
float l = g + this.up;
|
|
float m = g + this.down;
|
|
float n = bl ? 1.0F - 0.25F * this.up : 0.0F;
|
|
float o = bl ? 1.0F - 0.25F * this.down : 0.0F;
|
|
vertexConsumer.addVertex(matrix4f, h + n, l, 0.0F).setColor(i).setUv(this.u0, this.v0).setLight(j);
|
|
vertexConsumer.addVertex(matrix4f, h + o, m, 0.0F).setColor(i).setUv(this.u0, this.v1).setLight(j);
|
|
vertexConsumer.addVertex(matrix4f, k + o, m, 0.0F).setColor(i).setUv(this.u1, this.v1).setLight(j);
|
|
vertexConsumer.addVertex(matrix4f, k + n, l, 0.0F).setColor(i).setUv(this.u1, this.v0).setLight(j);
|
|
}
|
|
|
|
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) {
|
|
}
|
|
}
|