PlayerGlyphProvider.java

net.minecraft.client.gui.font.PlayerGlyphProvider

信息

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

    TODO

字段/常量

  • GLYPH_INFO

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

      TODO

  • playerSkinRenderCache

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

      TODO

  • wrapperCache

    • 类型: LoadingCache<FontDescription.PlayerSprite,GlyphSource>
    • 修饰符: private final public final final public public
    • 源码定位: L27
    • 说明:

      TODO

内部类/嵌套类型

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

      TODO

构造器

public PlayerGlyphProvider(PlayerSkinRenderCache playerSkinRenderCache) @ L55

  • 构造器名:PlayerGlyphProvider
  • 源码定位:L55
  • 修饰符:public

参数:

  • playerSkinRenderCache: PlayerSkinRenderCache

说明:

TODO

方法

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

public GlyphSource sourceForPlayer(FontDescription.PlayerSprite playerInfo) @ L59

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

参数:

  • playerInfo: FontDescription.PlayerSprite

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class PlayerGlyphProvider {
    private static final GlyphInfo GLYPH_INFO = GlyphInfo.simple(8.0F);
    private final PlayerSkinRenderCache playerSkinRenderCache;
    private final LoadingCache<FontDescription.PlayerSprite, GlyphSource> wrapperCache = CacheBuilder.newBuilder()
        .expireAfterAccess(PlayerSkinRenderCache.CACHE_DURATION)
        .build(new CacheLoader<FontDescription.PlayerSprite, GlyphSource>() {
            {
                Objects.requireNonNull(PlayerGlyphProvider.this);
            }
 
            public GlyphSource load(FontDescription.PlayerSprite playerInfo) {
                final Supplier<PlayerSkinRenderCache.RenderInfo> skin = PlayerGlyphProvider.this.playerSkinRenderCache.createLookup(playerInfo.profile());
                final boolean hat = playerInfo.hat();
                return new SingleSpriteSource(new BakedGlyph() {
                    {
                        
                    }
 
                    @Override
                    public GlyphInfo info() {
                        return PlayerGlyphProvider.GLYPH_INFO;
                    }
 
                    @Override
                    public TextRenderable.Styled createGlyph(float x, float y, int color, int shadowColor, Style style, float boldOffset, float shadowOffset) {
                        return new PlayerGlyphProvider.Instance(skin, hat, x, y, color, shadowColor, shadowOffset, style);
                    }
                });
            }
        });
 
    public PlayerGlyphProvider(PlayerSkinRenderCache playerSkinRenderCache) {
        this.playerSkinRenderCache = playerSkinRenderCache;
    }
 
    public GlyphSource sourceForPlayer(FontDescription.PlayerSprite playerInfo) {
        return this.wrapperCache.getUnchecked(playerInfo);
    }
 
    @OnlyIn(Dist.CLIENT)
    private record Instance(
        Supplier<PlayerSkinRenderCache.RenderInfo> skin, boolean hat, 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();
            renderQuad(pose, buffer, packedLightCoords, x0, x1, y0, y1, z, color, 8.0F, 8.0F, 8, 8, 64, 64);
            if (this.hat) {
                renderQuad(pose, buffer, packedLightCoords, x0, x1, y0, y1, z, color, 40.0F, 8.0F, 8, 8, 64, 64);
            }
        }
 
        private static void renderQuad(
            Matrix4fc pose,
            VertexConsumer buffer,
            int packedLightCoords,
            float x0,
            float x1,
            float y0,
            float y1,
            float z,
            int color,
            float u,
            float v,
            int srcWidth,
            int srcHeight,
            int textureWidth,
            int textureHeight
        ) {
            float u0 = (u + 0.0F) / textureWidth;
            float u1 = (u + srcWidth) / textureWidth;
            float v0 = (v + 0.0F) / textureHeight;
            float v1 = (v + srcHeight) / textureHeight;
            buffer.addVertex(pose, x0, y0, z).setUv(u0, v0).setColor(color).setLight(packedLightCoords);
            buffer.addVertex(pose, x0, y1, z).setUv(u0, v1).setColor(color).setLight(packedLightCoords);
            buffer.addVertex(pose, x1, y1, z).setUv(u1, v1).setColor(color).setLight(packedLightCoords);
            buffer.addVertex(pose, x1, y0, z).setUv(u1, v0).setColor(color).setLight(packedLightCoords);
        }
 
        @Override
        public RenderType renderType(Font.DisplayMode displayMode) {
            return this.skin.get().glyphRenderTypes().select(displayMode);
        }
 
        @Override
        public RenderPipeline guiPipeline() {
            return this.skin.get().glyphRenderTypes().guiPipeline();
        }
 
        @Override
        public GpuTextureView textureView() {
            return this.skin.get().textureView();
        }
    }
}

引用的其他类