AtlasGlyphProvider.java

net.minecraft.client.gui.font.AtlasGlyphProvider

信息

  • 全限定名:net.minecraft.client.gui.font.AtlasGlyphProvider
  • 类型:public class
  • 包:net.minecraft.client.gui.font
  • 源码路径:src/main/java/net/minecraft/client/gui/font/AtlasGlyphProvider.java
  • 起始行号:L24
  • 职责:

    TODO

字段/常量

  • GLYPH_INFO

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

      TODO

  • atlas

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

      TODO

  • renderTypes

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

      TODO

  • missingWrapper

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

      TODO

  • wrapperCache

    • 类型: Map<Identifier,GlyphSource>
    • 修饰符: private final
    • 源码定位: L29
    • 说明:

      TODO

  • spriteResolver

    • 类型: Function<Identifier,GlyphSource>
    • 修饰符: private final
    • 源码定位: L30
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.font.AtlasGlyphProvider.Instance
    • 类型: record
    • 修饰符: private
    • 源码定位: L78
    • 说明:

      TODO

构造器

public AtlasGlyphProvider(TextureAtlas atlas) @ L32

  • 构造器名:AtlasGlyphProvider
  • 源码定位:L32
  • 修饰符:public

参数:

  • atlas: TextureAtlas

说明:

TODO

方法

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

public GlyphSource sourceForSprite(Identifier spriteId) @ L43

  • 方法名:sourceForSprite
  • 源码定位:L43
  • 返回类型:GlyphSource
  • 修饰符:public

参数:

  • spriteId: Identifier

说明:

TODO

private GlyphSource createSprite(TextureAtlasSprite sprite) @ L47

  • 方法名:createSprite
  • 源码定位:L47
  • 返回类型:GlyphSource
  • 修饰符:private

参数:

  • sprite: TextureAtlasSprite

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class AtlasGlyphProvider {
    private static final GlyphInfo GLYPH_INFO = GlyphInfo.simple(8.0F);
    private final TextureAtlas atlas;
    private final GlyphRenderTypes renderTypes;
    private final GlyphSource missingWrapper;
    private final Map<Identifier, GlyphSource> wrapperCache = new HashMap<>();
    private final Function<Identifier, GlyphSource> spriteResolver;
 
    public AtlasGlyphProvider(TextureAtlas atlas) {
        this.atlas = atlas;
        this.renderTypes = GlyphRenderTypes.createForColorTexture(atlas.location());
        TextureAtlasSprite missingSprite = atlas.missingSprite();
        this.missingWrapper = this.createSprite(missingSprite);
        this.spriteResolver = id -> {
            TextureAtlasSprite sprite = atlas.getSprite(id);
            return sprite == missingSprite ? this.missingWrapper : this.createSprite(sprite);
        };
    }
 
    public GlyphSource sourceForSprite(Identifier spriteId) {
        return this.wrapperCache.computeIfAbsent(spriteId, this.spriteResolver);
    }
 
    private GlyphSource createSprite(TextureAtlasSprite sprite) {
        return new SingleSpriteSource(
            new BakedGlyph() {
                {
                    Objects.requireNonNull(AtlasGlyphProvider.this);
                }
 
                @Override
                public GlyphInfo info() {
                    return AtlasGlyphProvider.GLYPH_INFO;
                }
 
                @Override
                public TextRenderable.Styled createGlyph(float x, float y, int color, int shadowColor, Style style, float boldOffset, float shadowOffset) {
                    return new AtlasGlyphProvider.Instance(
                        AtlasGlyphProvider.this.renderTypes,
                        AtlasGlyphProvider.this.atlas.getTextureView(),
                        sprite,
                        x,
                        y,
                        color,
                        shadowColor,
                        shadowOffset,
                        style
                    );
                }
            }
        );
    }
 
    @OnlyIn(Dist.CLIENT)
    private record Instance(
        GlyphRenderTypes renderTypes,
        GpuTextureView textureView,
        TextureAtlasSprite sprite,
        float x,
        float y,
        int color,
        int shadowColor,
        float shadowOffset,
        Style style
    ) implements PlainTextRenderable {
        @Override
        public void renderSprite(Matrix4fc pose, VertexConsumer buffer, int packedLightCoords, float offsetX, float offsetY, float z, int color) {
            float x0 = offsetX + this.left();
            float x1 = offsetX + this.right();
            float y0 = offsetY + this.top();
            float y1 = offsetY + this.bottom();
            buffer.addVertex(pose, x0, y0, z).setUv(this.sprite.getU0(), this.sprite.getV0()).setColor(color).setLight(packedLightCoords);
            buffer.addVertex(pose, x0, y1, z).setUv(this.sprite.getU0(), this.sprite.getV1()).setColor(color).setLight(packedLightCoords);
            buffer.addVertex(pose, x1, y1, z).setUv(this.sprite.getU1(), this.sprite.getV1()).setColor(color).setLight(packedLightCoords);
            buffer.addVertex(pose, x1, y0, z).setUv(this.sprite.getU1(), this.sprite.getV0()).setColor(color).setLight(packedLightCoords);
        }
 
        @Override
        public RenderType renderType(Font.DisplayMode displayMode) {
            return this.renderTypes.select(displayMode);
        }
 
        @Override
        public RenderPipeline guiPipeline() {
            return this.renderTypes.guiPipeline();
        }
    }
}

引用的其他类