Apache License 2.0

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

Brikster/glyphs 深度技术分析

项目背景与痛点

Brikster/glyphs 是一个用于管理 Minecraft 资源包中位图纹理的库。对于 Minecraft 资源包的开发者来说,管理像素样式 (glyph) 数据的需求非常明确。这些数据不仅庞大且重复,传统的工具和方法在处理这些数据时效率低下。因此,开发者需要一个更加高效和便捷的工具来解决这一痛点。

位图纹理文件在资源包中存储大量的图形信息,包括字体、图标和其他自定义图形。这些图形需要被正确管理和加载,以确保它们在游戏中的表现。同时,资源包开发者需要保持这些图形的一致性和版本兼容性,这对传统工具来说是一个挑战。因此,一个方便的库能够自动化和简化这一过程,提供对这些文件更直接、更高效的操作手段。

核心技术揭秘

Brikster/glyphs 的设计核心在于提供一种标准化的方式来存储和访问 Minecraft 资源包中的位图纹理。以下是对其技术实现的分析:

graph TD A[初始化资源] --> B{"加载资源包"} B -->|"成功"| C[解析纹理数据] B -->|"失败"| D[处理错误] C --> E[管理纹理对象] E --> F[纹理实例化] F --> G[应用到实用工具]

图中的流程如下:

  1. 初始化资源:程序启动后,根据用户配置或其他环境变量,准备加载 Minecraft 资源包。
  2. 资源包加载:系统尝试加载指定的资源包,每次加载尝试都会对其版本及兼容性进行验证。
  3. 纹理解析:成功加载的资源包中的位图纹理数据会被解析并转换成可以调用和管理的数据结构。
  4. 纹理管理:解析后的纹理数据被编入一个高效的纹理管理器中,以便后续提取和使用。
  5. 纹理实例化:根据游戏需求将纹理数据实例化,应用于实际的渲染或逻辑中。
  6. 实际应用:纹理实例最终被应用到资源包工具或游戏中,提供优化的加载和显示功能。

功能亮点与差异

Brikster/glyphs 与其他竞品相比,最大的优势在于其高效率和灵活性。它不仅提供针对位图纹理的解析和管理功能,还允许开发者自定义如何处理这些数据,从而实现更高的性能优化和定制化需求。此外,库的文档完善,提供了丰富的示例和详细的API介绍,让开发者能够快速上手并深入使用。

应用场景与落地建议

在生产环境使用 Brikster/glyphs 时,特别需要关注磁盘性能和内存使用情况。由于要处理大量的纹理数据,有必要考虑数据索引和缓存机制以提高加载速度。适合的业务场景包括Minecraft资源包的批量转换、个性化皮肤和图标设计、以及增强游戏资源包的管理和维护。

综合评价

Brikster/glyphs 为处理 Minecraft 资源包中的位图纹理提供了高效且灵活的解决方案。强大的功能和开放的设计允许开发者针对不同需求进行自定义处理。然而,也需注意到加载大量数据时可能会遇到的性能瓶颈,因此在实际部署过程中应注重性能优化措施。总体而言,这是一个非常实用且价值显著的开源项目,对于资源包社区的开发者来说是不可或缺的工具。

关于

GitHub 原始描述(英文)

Library for convenient management of bitmap textures from Minecraft resourcepacks.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
131
价值分
73
活跃状态
活跃

语言占比

Java

Release

README

glyphs

Apache 2.0 License Maven Central GitHub code size in bytes

Library for convenient management of bitmap textures from Minecraft resourcepacks. Vanilla provides you ability to create bitmap fonts with images of bigger sizes (up to 256x256), but they work as a text - you can’t render texture at the necessary place.

glyphs give the opportunity to make decorated chat messages, menus etc. with absolutely positioned textures. It based on @unnamed’s “creative” & @Kyori’s “adventure” libraries, so glyphs is platform-independent.

Examples

Decorated chat message

Decorated chat message

At the left part of message you can see the texture with Minecraft® logo (all rights belong to their respective owners, that’s just an example).

How to reproduce
var spaces = MojangSpacesGlyph.create();
var exampleLogo = ImageGlyph.of(Texture.of(
            Key.key(Glyph.DEFAULT_NAMESPACE, "chat/example_logo"),
            GlyphResources.resourceFromJar("example_logo.png")),
        new TextureProperties(/* height */ 50, /* ascent */ 56));

Collection<FileResource> resources = GlyphCompiler.instance()
        .compile(spaces, exampleLogo);

// Method that generates archive with "creative" library
createResourcepack(resources);

// Indent component with 14 spaces
Component logoIndentComponent = Component.text(" ".repeat(14));

// GlyphComponentBuilder#build returns "Component"'s instance from "adventure" library
Component resultComponent = GlyphComponentBuilder.universal(spaces)
        .append(exampleLogo)
        .build()
        .append(Component.newline().append(logoIndentComponent))
        .append(Component.newline()
            .append(logoIndentComponent)
            .append(Component.text("Glyphs", TextColor.fromHexString("#d84aff"), 
                TextDecoration.BOLD)))
        .append(Component.newline()
            .append(logoIndentComponent)
            .append(Component.text("<--- ", NamedTextColor.GRAY))
            .append(Component.text("Here you can see Minecraft® logo", NamedTextColor.YELLOW)))
        .append(Component.newline().append(logoIndentComponent))
        .append(Component.newline().append(logoIndentComponent));

// and so on to send it to a player

Example menu

That’s the simple menu with rendered texts of various sizes and the custom button.

How to reproduce
// Glyphs objects
var spaces = MojangSpacesGlyph.create();

var guiBackground = ImageGlyph.of(Texture.of(
            Key.key(Glyph.DEFAULT_NAMESPACE, "gui/gui_background"),
            GlyphResources.resourceFromJar("gui_background.png")),
        new TextureProperties(/* height */ 256, /* ascent */ 19));

var exampleButton = ImageGlyph.of(Texture.of(
            Key.key(Glyph.DEFAULT_NAMESPACE, "gui/example_button"),
            GlyphResources.resourceFromJar("example_button.png")),
        new TextureProperties(/* height */ 22, /* ascent */ -56));

var font = GlyphResources.minecraftFontGlyphCollection(
        List.of(new TextureProperties(/* height */ 12, /* ascent */ -6),
            new TextureProperties(/* height */ 8, /* ascent */ -24),
            new TextureProperties(/* height */ 8, /* ascent */ -36)));

Collection<FileResource> resources = GlyphCompiler.instance()
        .compile(spaces, guiBackground, exampleButton, font);
resources.addAll(GlyphResources.blankSlotResources());

// Method that generates archive with "creative" library
createResourcepack(resources);

// Building component for inventory title
Component titleComponent = GlyphComponentBuilder.gui(spaces)
        .append(guiBackground)
        .append(/* position */ 131, exampleButton)
        .append(/* position */ 16, font.translate(/* height */ 12, /* ascent */ -6, "Example text"))
        .append(/* position */ 16, font.translate(/* height */ 8, /* ascent */ -24, "Hello "))
        .append(PositionType.RELATIVE, font.translate(/* height */ 8, /* ascent */ -24, "world..."))
        .append(PositionType.ABSOLUTE, /* position */ 16, font.translate(/* height */ 8, /* ascent */ -36, "Hello world...", NamedTextColor.LIGHT_PURPLE))
        .build()
        .append(Component.text("Test menu with glyphs", NamedTextColor.DARK_GRAY, TextDecoration.UNDERLINED));

// and so on to open chest GUI

See full code of Bukkit plugin with both examples.

Usage

You need an implementation of Minecraft server with adventure library support. Also, that’s required Minecraft 1.19 and higher to support all the library features.

Add dependency

glyphs is published to Maven Central repository.

Gradle (releases)
repositories {
    mavenCentral()
}

dependencies {
    // Main dependency with GlyphComponentBuilder and GlyphCompiler
    implementation "ru.brikster:glyphs-api:$version"
    // Optional dependency with some frequently used resources (Minecraft font etc.)
    implementation "ru.brikster:glyphs-resources:$version"
}
Gradle (snapshots)
repositories {
    maven { 
        name "ossrh-snapshots"
        url "https://s01.oss.sonatype.org/content/repositories/snapshots/" 
    }
}

dependencies {
    // Main dependency with GlyphComponentBuilder and GlyphCompiler
    implementation "ru.brikster:glyphs-api:$version"
    // Optional dependency with some frequently used resources (Minecraft font etc.)
    implementation "ru.brikster:glyphs-resources:$version"
}

You can check out for latest snapshot versions in gradle.properties or at OSSRH Snapshots.

GitHub Repo stars GitHub forks

评论

暂无评论