Good Asset Fetcher
适用于 StationAPI 的库模组,它为其他模组提供了一个接口,用于在游戏启动时从 Mojang 官方 JAR 包中动态获取资源;这使得模组能够利用游戏资产而不会违反许可证规定。
目前仅支持客户端资产(不支持数据包)。

依赖要求
使用方法(面向开发者)
-
从 Maven 导入 pw.tmpim.mygoodmods:good-asset-fetcher(请参阅上方的版本徽章以获取最新版本):
repositories {
maven("https://repo.lem.sh/releases") {
name = "Lemmmy Repo"
content {
includeGroupAndSubgroups("sh.lem")
includeGroupAndSubgroups("pw.tmpim")
}
}
}
dependencies {
modImplementation("pw.tmpim.mygoodmods:good-asset-fetcher:1.0.4")
}
-
如果你还没有为模组注册 仅限客户端 的入口点,请在 fabric.mod.json 中进行注册:
{
"entrypoints": {
"stationapi:event_bus_client": "com.example.yourmod.ExampleModClientListener"
},
"depends": {
"good-asset-fetcher": "1.x"
}
}
-
监听 GoodAssetFetcherRegistryEvent 事件并调用 addResourceFile、addBlock 或 addItem:
public class ExampleEventListener {
@Entrypoint.Namespace
public static Namespace NAMESPACE;
@EventListener
public void onRegisterGoodAssets(GoodAssetFetcherRegistryEvent event) {
// 方块和物品的快捷方法:
event.addBlock(NAMESPACE, "1.12.2", "redstone_block");
event.addItem(NAMESPACE, "1.12.2", "stick");
// 通过完整路径加载资产:
event.addResourceFile(NAMESPACE, "1.12.2", "assets/minecraft/textures/blocks/stone.png");
}
}
-
在 assets/your-mod/stationapi/textures/block/stone.png 下使用这些纹理:
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "your-mod:block/stone"
}
}
工作原理
在游戏初始化阶段,加载资源包之前,Good Asset Fetcher 会从 Minecraft 启动器加载版本清单,以获取所有游戏版本的列表。该列表会被无限期地缓存到
.minecraft/mods/good-asset-fetcher/asset-cache/versionManifest-$modVersion.json。
随后,触发 GoodAssetFetcherRegistryEvent 以获取每个模组的资源定义。模组可以请求获取(几乎?)任何游戏版本的资产。
当资源包被加载时,该模组会在运行时注入其自己的动态资源包。在会话期间 首次 加载此资源包时,它会检查模组缓存目录
.minecraft/mods/good-asset-fetcher/asset-cache 中是否有任何缺失的资产。
在掌握了所有缺失资产及其关联的游戏版本信息后,good-asset-fetcher 会将每个版本的清单和 JAR 文件下载到内存中,验证哈希值,并提取所需的文件。此过程在资源包加载时执行,因此第一次发生时会导致游戏阻塞,之后理想情况下会永久缓存于 .minecraft/mods/good-asset-fetcher/asset-cache 中。
由于 StationAPI 存储资产的位置与大多数原版版本略有不同,该模组会自动执行以下路径转换至目标文件路径:
| 源路径 |
缓存路径 |
assets/minecraft/textures/blocks |
assets/${namespace}/stationapi/textures/block |
assets/minecraft/textures/items |
assets/${namespace}/stationapi/textures/item |
如果你的用例未得到适当覆盖,可以使用 addResourceFile(Namespace namespace, String gameVersion, String sourcePath, String destPath) 重载方法来指定你自己的目标路径。请注意,它仍然会经过上述相同的字符串替换处理。
许可证
本模组根据 MIT 许可证 授权。
Good Asset Fetcher
Library mod for StationAPI that provides an interface for other mods to fetch resources from official Mojang jars on the
fly when starting the game; this allows mods to utilise the game's assets without incurring license violations.
Currently only supports clientside assets (not datapacks).

Requirements
Usage (for developers)
-
Import pw.tmpim.mygoodmods:good-asset-fetcher from Maven (see the version badge above for the latest version):
repositories {
maven("https://repo.lem.sh/releases") {
name = "Lemmmy Repo"
content {
includeGroupAndSubgroups("sh.lem")
includeGroupAndSubgroups("pw.tmpim")
}
}
}
dependencies {
modImplementation("pw.tmpim.mygoodmods:good-asset-fetcher:1.0.4")
}
-
Register a client-only endpoint for your mod in fabric.mod.json if you don't already have one:
{
"entrypoints": {
"stationapi:event_bus_client": "com.example.yourmod.ExampleModClientListener"
},
"depends": {
"good-asset-fetcher": "1.x"
}
}
-
Listen to the GoodAssetFetcherRegistryEvent and call addResourceFile, addBlock, or addItem:
public class ExampleEventListener {
@Entrypoint.Namespace
public static Namespace NAMESPACE;
@EventListener
public void onRegisterGoodAssets(GoodAssetFetcherRegistryEvent event) {
// shorthands for blocks and items:
event.addBlock(NAMESPACE, "1.12.2", "redstone_block");
event.addItem(NAMESPACE, "1.12.2", "stick");
// load an asset by full path:
event.addResourceFile(NAMESPACE, "1.12.2", "assets/minecraft/textures/blocks/stone.png");
}
}
-
Use the textures under assets/your-mod/stationapi/textures/block/stone.png:
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "your-mod:block/stone"
}
}
How it works
During the game's init phase, before resource packs are loaded, Good Asset Fetcher loads the version manifest from the
Minecraft Launcher to get a listing of all game versions. This listing is then cached indefinitely at
.minecraft/mods/good-asset-fetcher/asset-cache/versionManifest-$modVersion.json.
Then, GoodAssetFetcherRegistryEvent is called to fetch the resource definitions for every mod. Mods may request to
fetch assets from (almost?) any version of the game.
When resource packs are loaded, the mod injects its own dynamic resource pack at runtime. When this is first loaded
during a session, it checks for any missing assets in the mod's cache directory,
.minecraft/mods/good-asset-fetcher/asset-cache.
Armed with the knowledge of all the missing assets and their associated game versions, good-asset-fetcher will
download each version's manifest and jar in-memory, validate the hash, and extract the required files. This process is
done during resource pack load, so it will block the game the first time it happens, and then ideally remain cached
permanently in .minecraft/mods/good-asset-fetcher/asset-cache.
Since StationAPI stores assets in a slightly different location to most versions of vanilla, the mod performs the
following path conversions to the destination file path automatically:
| Source path |
Cached path |
assets/minecraft/textures/blocks |
assets/${namespace}/stationapi/textures/block |
assets/minecraft/textures/items |
assets/${namespace}/stationapi/textures/item |
If your use case is not properly covered, the
addResourceFile(Namespace namespace, String gameVersion, String sourcePath, String destPath) overload is available for
you to specify your own destination path. Note, however, that it will still go through the same string replacements as
above.
License
This mod is licensed under the MIT license.
评论 0
登录后参与评分
还没有评论,来抢沙发吧