BakedSheetGlyph.java

net.minecraft.client.gui.font.glyphs.BakedSheetGlyph

信息

  • 全限定名:net.minecraft.client.gui.font.glyphs.BakedSheetGlyph
  • 类型:public class
  • 包:net.minecraft.client.gui.font.glyphs
  • 源码路径:src/main/java/net/minecraft/client/gui/font/glyphs/BakedSheetGlyph.java
  • 起始行号:L17
  • 实现:EffectGlyph, BakedGlyph
  • 职责:

    TODO

字段/常量

  • Z_FIGHTER

    • 类型: float
    • 修饰符: public static final
    • 源码定位: L18
    • 说明:

      TODO

  • info

    • 类型: GlyphInfo
    • 修饰符: private final
    • 源码定位: L19
    • 说明:

      TODO

  • renderTypes

    • 类型: GlyphRenderTypes
    • 修饰符: private final
    • 源码定位: L20
    • 说明:

      TODO

  • textureView

    • 类型: GpuTextureView
    • 修饰符: private final
    • 源码定位: L21
    • 说明:

      TODO

  • u0

    • 类型: float
    • 修饰符: private final
    • 源码定位: L22
    • 说明:

      TODO

  • u1

    • 类型: float
    • 修饰符: private final
    • 源码定位: L23
    • 说明:

      TODO

  • v0

    • 类型: float
    • 修饰符: private final
    • 源码定位: L24
    • 说明:

      TODO

  • v1

    • 类型: float
    • 修饰符: private final
    • 源码定位: L25
    • 说明:

      TODO

  • left

    • 类型: float
    • 修饰符: private final
    • 源码定位: L26
    • 说明:

      TODO

  • right

    • 类型: float
    • 修饰符: private final
    • 源码定位: L27
    • 说明:

      TODO

  • up

    • 类型: float
    • 修饰符: private final
    • 源码定位: L28
    • 说明:

      TODO

  • down

    • 类型: float
    • 修饰符: private final
    • 源码定位: L29
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.font.glyphs.BakedSheetGlyph.EffectInstance

    • 类型: record
    • 修饰符: private
    • 源码定位: L178
    • 说明:

      TODO

  • net.minecraft.client.gui.font.glyphs.BakedSheetGlyph.GlyphInstance

    • 类型: record
    • 修饰符: private
    • 源码定位: L226
    • 说明:

      TODO

构造器

public BakedSheetGlyph(GlyphInfo info, GlyphRenderTypes renderTypes, GpuTextureView textureView, float u0, float u1, float v0, float v1, float left, float right, float up, float down) @ L31

  • 构造器名:BakedSheetGlyph
  • 源码定位:L31
  • 修饰符:public

参数:

  • info: GlyphInfo
  • renderTypes: GlyphRenderTypes
  • textureView: GpuTextureView
  • u0: float
  • u1: float
  • v0: float
  • v1: float
  • left: float
  • right: float
  • up: float
  • down: float

说明:

TODO

方法

下面的方法块按源码顺序生成。

private float left(BakedSheetGlyph.GlyphInstance instance) @ L57

  • 方法名:left
  • 源码定位:L57
  • 返回类型:float
  • 修饰符:private

参数:

  • instance: BakedSheetGlyph.GlyphInstance

说明:

TODO

private float top(BakedSheetGlyph.GlyphInstance instance) @ L64

  • 方法名:top
  • 源码定位:L64
  • 返回类型:float
  • 修饰符:private

参数:

  • instance: BakedSheetGlyph.GlyphInstance

说明:

TODO

private float right(BakedSheetGlyph.GlyphInstance instance) @ L68

  • 方法名:right
  • 源码定位:L68
  • 返回类型:float
  • 修饰符:private

参数:

  • instance: BakedSheetGlyph.GlyphInstance

说明:

TODO

private float bottom(BakedSheetGlyph.GlyphInstance instance) @ L76

  • 方法名:bottom
  • 源码定位:L76
  • 返回类型:float
  • 修饰符:private

参数:

  • instance: BakedSheetGlyph.GlyphInstance

说明:

TODO

private void renderChar(BakedSheetGlyph.GlyphInstance glyphInstance, Matrix4fc pose, VertexConsumer buffer, int packedLightCoords, boolean flat) @ L80

  • 方法名:renderChar
  • 源码定位:L80
  • 返回类型:void
  • 修饰符:private

参数:

  • glyphInstance: BakedSheetGlyph.GlyphInstance
  • pose: Matrix4fc
  • buffer: VertexConsumer
  • packedLightCoords: int
  • flat: boolean

说明:

TODO

private void render(boolean italic, float x, float y, float z, Matrix4fc pose, VertexConsumer builder, int color, boolean bold, int packedLightCoords) @ L117

  • 方法名:render
  • 源码定位:L117
  • 返回类型:void
  • 修饰符:private

参数:

  • italic: boolean
  • x: float
  • y: float
  • z: float
  • pose: Matrix4fc
  • builder: VertexConsumer
  • color: int
  • bold: boolean
  • packedLightCoords: int

说明:

TODO

private static float extraThickness(boolean bold) @ L131

  • 方法名:extraThickness
  • 源码定位:L131
  • 返回类型:float
  • 修饰符:private static

参数:

  • bold: boolean

说明:

TODO

private float shearBottom() @ L135

  • 方法名:shearBottom
  • 源码定位:L135
  • 返回类型:float
  • 修饰符:private

参数:

说明:

TODO

private float shearTop() @ L139

  • 方法名:shearTop
  • 源码定位:L139
  • 返回类型:float
  • 修饰符:private

参数:

说明:

TODO

private void renderEffect(BakedSheetGlyph.EffectInstance effect, Matrix4fc pose, VertexConsumer buffer, int packedLightCoords, boolean flat) @ L143

  • 方法名:renderEffect
  • 源码定位:L143
  • 返回类型:void
  • 修饰符:private

参数:

  • effect: BakedSheetGlyph.EffectInstance
  • pose: Matrix4fc
  • buffer: VertexConsumer
  • packedLightCoords: int
  • flat: boolean

说明:

TODO

private void buildEffect(BakedSheetGlyph.EffectInstance effect, float offset, float z, int color, VertexConsumer buffer, int packedLightCoords, Matrix4fc pose) @ L153

  • 方法名:buildEffect
  • 源码定位:L153
  • 返回类型:void
  • 修饰符:private

参数:

  • effect: BakedSheetGlyph.EffectInstance
  • offset: float
  • z: float
  • color: int
  • buffer: VertexConsumer
  • packedLightCoords: int
  • pose: Matrix4fc

说明:

TODO

public GlyphInfo info() @ L162

  • 方法名:info
  • 源码定位:L162
  • 返回类型:GlyphInfo
  • 修饰符:public

参数:

说明:

TODO

public TextRenderable.Styled createGlyph(float x, float y, int color, int shadowColor, Style style, float boldOffset, float shadowOffset) @ L167

  • 方法名:createGlyph
  • 源码定位:L167
  • 返回类型:TextRenderable.Styled
  • 修饰符:public

参数:

  • x: float
  • y: float
  • color: int
  • shadowColor: int
  • style: Style
  • boldOffset: float
  • shadowOffset: float

说明:

TODO

public TextRenderable createEffect(float x0, float y0, float x1, float y1, float depth, int color, int shadowColor, float shadowOffset) @ L172

  • 方法名:createEffect
  • 源码定位:L172
  • 返回类型:TextRenderable
  • 修饰符:public

参数:

  • x0: float
  • y0: float
  • x1: float
  • y1: float
  • depth: float
  • color: int
  • shadowColor: int
  • shadowOffset: float

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class BakedSheetGlyph implements EffectGlyph, BakedGlyph {
    public static final float Z_FIGHTER = 0.001F;
    private final GlyphInfo info;
    private final GlyphRenderTypes renderTypes;
    private final GpuTextureView textureView;
    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 BakedSheetGlyph(
        GlyphInfo info,
        GlyphRenderTypes renderTypes,
        GpuTextureView textureView,
        float u0,
        float u1,
        float v0,
        float v1,
        float left,
        float right,
        float up,
        float down
    ) {
        this.info = info;
        this.renderTypes = renderTypes;
        this.textureView = textureView;
        this.u0 = u0;
        this.u1 = u1;
        this.v0 = v0;
        this.v1 = v1;
        this.left = left;
        this.right = right;
        this.up = up;
        this.down = down;
    }
 
    private float left(BakedSheetGlyph.GlyphInstance instance) {
        return instance.x
            + this.left
            + (instance.style.isItalic() ? Math.min(this.shearTop(), this.shearBottom()) : 0.0F)
            - extraThickness(instance.style.isBold());
    }
 
    private float top(BakedSheetGlyph.GlyphInstance instance) {
        return instance.y + this.up - extraThickness(instance.style.isBold());
    }
 
    private float right(BakedSheetGlyph.GlyphInstance instance) {
        return instance.x
            + this.right
            + (instance.hasShadow() ? instance.shadowOffset : 0.0F)
            + (instance.style.isItalic() ? Math.max(this.shearTop(), this.shearBottom()) : 0.0F)
            + extraThickness(instance.style.isBold());
    }
 
    private float bottom(BakedSheetGlyph.GlyphInstance instance) {
        return instance.y + this.down + (instance.hasShadow() ? instance.shadowOffset : 0.0F) + extraThickness(instance.style.isBold());
    }
 
    private void renderChar(BakedSheetGlyph.GlyphInstance glyphInstance, Matrix4fc pose, VertexConsumer buffer, int packedLightCoords, boolean flat) {
        Style style = glyphInstance.style();
        boolean italic = style.isItalic();
        float x = glyphInstance.x();
        float y = glyphInstance.y();
        int color = glyphInstance.color();
        boolean bold = style.isBold();
        float zFighter = flat ? 0.0F : 0.001F;
        float depth;
        if (glyphInstance.hasShadow()) {
            int shadowColor = glyphInstance.shadowColor();
            this.render(italic, x + glyphInstance.shadowOffset(), y + glyphInstance.shadowOffset(), 0.0F, pose, buffer, shadowColor, bold, packedLightCoords);
            if (bold) {
                this.render(
                    italic,
                    x + glyphInstance.boldOffset() + glyphInstance.shadowOffset(),
                    y + glyphInstance.shadowOffset(),
                    zFighter,
                    pose,
                    buffer,
                    shadowColor,
                    true,
                    packedLightCoords
                );
            }
 
            depth = flat ? 0.0F : 0.03F;
        } else {
            depth = 0.0F;
        }
 
        this.render(italic, x, y, depth, pose, buffer, color, bold, packedLightCoords);
        if (bold) {
            this.render(italic, x + glyphInstance.boldOffset(), y, depth + zFighter, pose, buffer, color, true, packedLightCoords);
        }
    }
 
    private void render(boolean italic, float x, float y, float z, Matrix4fc pose, VertexConsumer builder, int color, boolean bold, int packedLightCoords) {
        float x0 = x + this.left;
        float x1 = x + this.right;
        float y0 = y + this.up;
        float y1 = y + this.down;
        float shearY0 = italic ? this.shearTop() : 0.0F;
        float shearY1 = italic ? this.shearBottom() : 0.0F;
        float extraThickness = extraThickness(bold);
        builder.addVertex(pose, x0 + shearY0 - extraThickness, y0 - extraThickness, z).setColor(color).setUv(this.u0, this.v0).setLight(packedLightCoords);
        builder.addVertex(pose, x0 + shearY1 - extraThickness, y1 + extraThickness, z).setColor(color).setUv(this.u0, this.v1).setLight(packedLightCoords);
        builder.addVertex(pose, x1 + shearY1 + extraThickness, y1 + extraThickness, z).setColor(color).setUv(this.u1, this.v1).setLight(packedLightCoords);
        builder.addVertex(pose, x1 + shearY0 + extraThickness, y0 - extraThickness, z).setColor(color).setUv(this.u1, this.v0).setLight(packedLightCoords);
    }
 
    private static float extraThickness(boolean bold) {
        return bold ? 0.1F : 0.0F;
    }
 
    private float shearBottom() {
        return 1.0F - 0.25F * this.down;
    }
 
    private float shearTop() {
        return 1.0F - 0.25F * this.up;
    }
 
    private void renderEffect(BakedSheetGlyph.EffectInstance effect, Matrix4fc pose, VertexConsumer buffer, int packedLightCoords, boolean flat) {
        float depth = flat ? 0.0F : effect.depth;
        if (effect.hasShadow()) {
            this.buildEffect(effect, effect.shadowOffset(), depth, effect.shadowColor(), buffer, packedLightCoords, pose);
            depth += flat ? 0.0F : 0.03F;
        }
 
        this.buildEffect(effect, 0.0F, depth, effect.color, buffer, packedLightCoords, pose);
    }
 
    private void buildEffect(
        BakedSheetGlyph.EffectInstance effect, float offset, float z, int color, VertexConsumer buffer, int packedLightCoords, Matrix4fc pose
    ) {
        buffer.addVertex(pose, effect.x0 + offset, effect.y1 + offset, z).setColor(color).setUv(this.u0, this.v0).setLight(packedLightCoords);
        buffer.addVertex(pose, effect.x1 + offset, effect.y1 + offset, z).setColor(color).setUv(this.u0, this.v1).setLight(packedLightCoords);
        buffer.addVertex(pose, effect.x1 + offset, effect.y0 + offset, z).setColor(color).setUv(this.u1, this.v1).setLight(packedLightCoords);
        buffer.addVertex(pose, effect.x0 + offset, effect.y0 + offset, z).setColor(color).setUv(this.u1, this.v0).setLight(packedLightCoords);
    }
 
    @Override
    public GlyphInfo info() {
        return this.info;
    }
 
    @Override
    public TextRenderable.Styled createGlyph(float x, float y, int color, int shadowColor, Style style, float boldOffset, float shadowOffset) {
        return new BakedSheetGlyph.GlyphInstance(x, y, color, shadowColor, this, style, boldOffset, shadowOffset);
    }
 
    @Override
    public TextRenderable createEffect(float x0, float y0, float x1, float y1, float depth, int color, int shadowColor, float shadowOffset) {
        return new BakedSheetGlyph.EffectInstance(this, x0, y0, x1, y1, depth, color, shadowColor, shadowOffset);
    }
 
    @OnlyIn(Dist.CLIENT)
    private record EffectInstance(BakedSheetGlyph glyph, float x0, float y0, float x1, float y1, float depth, int color, int shadowColor, float shadowOffset)
        implements TextRenderable {
        @Override
        public float left() {
            return this.x0;
        }
 
        @Override
        public float top() {
            return this.y0;
        }
 
        @Override
        public float right() {
            return this.x1 + (this.hasShadow() ? this.shadowOffset : 0.0F);
        }
 
        @Override
        public float bottom() {
            return this.y1 + (this.hasShadow() ? this.shadowOffset : 0.0F);
        }
 
        private boolean hasShadow() {
            return this.shadowColor() != 0;
        }
 
        @Override
        public void render(Matrix4fc pose, VertexConsumer buffer, int packedLightCoords, boolean flat) {
            this.glyph.renderEffect(this, pose, buffer, packedLightCoords, false);
        }
 
        @Override
        public RenderType renderType(Font.DisplayMode displayMode) {
            return this.glyph.renderTypes.select(displayMode);
        }
 
        @Override
        public GpuTextureView textureView() {
            return this.glyph.textureView;
        }
 
        @Override
        public RenderPipeline guiPipeline() {
            return this.glyph.renderTypes.guiPipeline();
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    private record GlyphInstance(float x, float y, int color, int shadowColor, BakedSheetGlyph glyph, Style style, float boldOffset, float shadowOffset)
        implements TextRenderable.Styled {
        @Override
        public float left() {
            return this.glyph.left(this);
        }
 
        @Override
        public float top() {
            return this.glyph.top(this);
        }
 
        @Override
        public float right() {
            return this.glyph.right(this);
        }
 
        @Override
        public float activeRight() {
            return this.x + this.glyph.info.getAdvance(this.style.isBold());
        }
 
        @Override
        public float bottom() {
            return this.glyph.bottom(this);
        }
 
        private boolean hasShadow() {
            return this.shadowColor() != 0;
        }
 
        @Override
        public void render(Matrix4fc pose, VertexConsumer buffer, int packedLightCoords, boolean flat) {
            this.glyph.renderChar(this, pose, buffer, packedLightCoords, flat);
        }
 
        @Override
        public RenderType renderType(Font.DisplayMode displayMode) {
            return this.glyph.renderTypes.select(displayMode);
        }
 
        @Override
        public GpuTextureView textureView() {
            return this.glyph.textureView;
        }
 
        @Override
        public RenderPipeline guiPipeline() {
            return this.glyph.renderTypes.guiPipeline();
        }
    }
}

引用的其他类