SpriteResourceLoader.java

net.minecraft.client.renderer.texture.atlas.SpriteResourceLoader

信息

  • 全限定名:net.minecraft.client.renderer.texture.atlas.SpriteResourceLoader
  • 类型:public interface
  • 包:net.minecraft.client.renderer.texture.atlas
  • 源码路径:src/main/java/net/minecraft/client/renderer/texture/atlas/SpriteResourceLoader.java
  • 起始行号:L26
  • 职责:

    TODO

字段/常量

  • LOGGER
    • 类型: Logger
    • 修饰符: package-private
    • 源码定位: L27
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

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

static SpriteResourceLoader create(Set<MetadataSectionType<?>> additionalMetadataSections) @ L29

  • 方法名:create
  • 源码定位:L29
  • 返回类型:SpriteResourceLoader
  • 修饰符:static

参数:

  • additionalMetadataSections: Set<MetadataSectionType<?>>

说明:

TODO

SpriteContents loadSprite(Identifier spriteLocation, Resource resource) @ L75

  • 方法名:loadSprite
  • 源码定位:L75
  • 返回类型:SpriteContents
  • 修饰符:package-private

参数:

  • spriteLocation: Identifier
  • resource: Resource

说明:

TODO

代码

@FunctionalInterface
@OnlyIn(Dist.CLIENT)
public interface SpriteResourceLoader {
    Logger LOGGER = LogUtils.getLogger();
 
    static SpriteResourceLoader create(Set<MetadataSectionType<?>> additionalMetadataSections) {
        return (spriteLocation, resource) -> {
            Optional<AnimationMetadataSection> animationInfo;
            Optional<TextureMetadataSection> textureInfo;
            List<MetadataSectionType.WithValue<?>> additionalMetadata;
            try {
                ResourceMetadata metadata = resource.metadata();
                animationInfo = metadata.getSection(AnimationMetadataSection.TYPE);
                textureInfo = metadata.getSection(TextureMetadataSection.TYPE);
                additionalMetadata = metadata.getTypedSections(additionalMetadataSections);
            } catch (Exception var11) {
                LOGGER.error("Unable to parse metadata from {}", spriteLocation, var11);
                return null;
            }
 
            NativeImage image;
            try (InputStream is = resource.open()) {
                image = NativeImage.read(is);
            } catch (IOException var13) {
                LOGGER.error("Using missing texture, unable to load {}", spriteLocation, var13);
                return null;
            }
 
            FrameSize frameSize;
            if (animationInfo.isPresent()) {
                frameSize = animationInfo.get().calculateFrameSize(image.getWidth(), image.getHeight());
                if (!Mth.isMultipleOf(image.getWidth(), frameSize.width()) || !Mth.isMultipleOf(image.getHeight(), frameSize.height())) {
                    LOGGER.error(
                        "Image {} size {},{} is not multiple of frame size {},{}",
                        spriteLocation,
                        image.getWidth(),
                        image.getHeight(),
                        frameSize.width(),
                        frameSize.height()
                    );
                    image.close();
                    return null;
                }
            } else {
                frameSize = new FrameSize(image.getWidth(), image.getHeight());
            }
 
            return new SpriteContents(spriteLocation, frameSize, image, animationInfo, additionalMetadata, textureInfo);
        };
    }
 
    @Nullable SpriteContents loadSprite(Identifier spriteLocation, Resource resource);
}

引用的其他类

  • NativeImage

    • 引用位置: 方法调用
    • 关联成员: NativeImage.read()
  • SpriteContents

    • 引用位置: 构造调用/返回值
    • 关联成员: SpriteContents()
  • FrameSize

    • 引用位置: 构造调用
    • 关联成员: FrameSize()
  • Identifier

    • 引用位置: 参数
  • MetadataSectionType

    • 引用位置: 参数
  • Resource

    • 引用位置: 参数
  • Mth

    • 引用位置: 方法调用
    • 关联成员: Mth.isMultipleOf()