aternos / renderchest
PHP 库,用于从 Minecraft 资源中直接渲染 Minecraft 项目的图标
Requires
- php: >=8.1
- ext-imagick: *
- ext-json: *
- aternos/taskmaster: ^1.1.3
- vanilla/garden-cli: ^3.1
This package is auto-updated.
Last update: 2024-09-18 14:16:25 UTC
README
Renderchest 是一个 PHP 库,用于从 Minecraft 资源中直接渲染 Minecraft 项目的图标。同时,还生成一个 CSS 库,以便在网页中使用这些图标。
内置模型
尽管现在 Minecraft 中的大多数方块/项目模型都保存在 Minecraft 的 JSON 模型格式中,但一些模型仍然以 Java 编码(例如,箱子、储物盒)。
这些模型无法通过游戏资源包系统访问,也无法由 renderchest 渲染。因此,renderchest 包含一些内置模型文件来替换这些硬编码的模型。
Renderchest 还包含大多数怪物头部的模型文件。这些模型可以通过渲染 mobheads
命名空间来使用。
着色
某些纹理由游戏动态着色(例如,植被和草方块)。这些信息无法从资产文件中提取,因此 renderchest 中硬编码了这些信息。
要求
- PHP 8.1+
- ext-imagick
- ext-pcntl(可选,允许更高效的线程多任务处理)
Windows 支持
虽然 Renderchest 通常可以在 Windows 上运行,但由于不支持异步任务,它将非常慢。因此,建议使用 Windows Subsystem for Linux 来在 Windows 上运行 renderchest。
用法
要使用 renderchest,需要一个有效的 Minecraft 资源目录。它可以从 Minecraft 客户端 jar 文件中提取。
CLI 用法
安装
git clone https://github.com/aternosorg/renderchest.git
cd renderchest
composer install
渲染图标
./renderchest --assets path/to/assets/root --output path/to/output/dir --namespace minecraft
OPTIONS
--assets, -a Assets folder to use. Multiple assets folders are possible,
but a base assets folder extracted from the Minecraft jar
should always be included.
--fallback Create a set of fallback textures as PNGs. Default: false
--format, -f Output image format. Default: webp
--help, -? Display this help.
--item-list, -i Create a JSON file containing the names of all rendered
items.
--namespace, -n Asset namespace that the items should be rendered from.
Default: minecraft
--output, -o Output directory
--prefix, -p Prefix to use for CSS classes. Default: rc-
--quality, -q When generating very small icons, small issues (like
z-fighting of faces close to each other) can occur. This
option allows rendering images in a higher resolution and
scaling them down for the final icon. Default: 2
--size, -s Size of the generated item icons. Default: 64
Renderchest 使用 Taskmaster 进行异步任务,这可以通过环境变量进行配置 使用环境变量。
使用资源包
可以通过指定多个资产路径来添加资源包。同时,始终包含从 Minecraft jar 中提取的基资产文件夹也很重要。
./renderchest --assets path/to/resource-pack/assets --assets path/to/assets/root --output path/to/output/dir --namespace minecraft
请确保使用资源包中资产文件夹的路径,而不是资源包的根目录。
使用生成的 CSS 库
生成的 CSS 库可以用于在网页中显示渲染的图标。默认情况下,所有生成的 CSS 类都以前缀 rc-
开头。当 CSS 类名称包含命名空间 ID 时,命名空间与 ID 之间通过下划线分隔(例如,minecraft:stone
-> minecraft_stone
)。
<div class="rc-item rc-minecraft_magma_block" style="width: 64px; height: 64px"></div>
所有图标都需要 rc-item
类。另外,还需要项目/方块类。
附魔物品可以通过添加 rc-enchanted
类来显示。
<div class="rc-item rc-minecraft_diamond_sword rc-enchanted" style="width: 64px; height: 64px"></div>
装备装饰
可以通过添加 rc-trim-[材料]
类来显示装备装饰。
<div class="rc-item rc-minecraft_diamond_helmet rc-trim-minecraft_gold" style="width: 64px; height: 64px"></div>
装饰罐
装饰罐可以通过添加 rc-pot-1-[材料-1]
和 rc-pot-2-[材料-3]
类来显示。
<div class="rc-item rc-minecraft_decorated_pot rc-pot-1-minecraft_prize_pottery_sherd rc-pot-2-minecraft_angler_pottery_sherd" style="width: 64px; height: 64px"></div>
只需要第一个和第三个材料,因为罐子的其他侧面是不可见的。
弩箭矢
可以通过添加 rc-projectile-[材料]
类来显示弩箭矢。
<div class="rc-item rc-minecraft_crossbow rc-projectile-minecraft_tipped_arrow" style="width: 64px; height: 64px"></div>
动态着色
图标可以由两层组成,可以使用 CSS 分别对这两层进行着色。当基于项目属性的颜色可以动态更改时,这很有必要(例如,染色的皮革盔甲或药水)。
可以通过设置 --rc-layer-1-tint
和 --rc-layer-2-tint
CSS 变量来添加动态颜色。
<div class="rc-item rc-minecraft_leather_helmet" style="--rc-layer-1-tint: #b02e26;width: 64px; height: 64px"></div>
将 renderchest 作为库使用
安装
composer require aternos/renderchest
当将 renderchest 作为库使用时,可以使用 ItemLibraryGenerator
类来复现 CLI 工具的功能。
(new ItemLibraryGenerator(["path/to/assets"], "path/to/output")) ->setNamespaces(["minecraft"]) ->setSize(64) ->setQuality(2) ->setFormat("webp") ->render();
还可以从资源管理器中加载特定的模型,而不是渲染所有内容。
$resourceManager = new \Aternos\Renderchest\Resource\FolderResourceManager(["path/to/assets"]); $model = $resourceManager->getModel(new \Aternos\Renderchest\Resource\ResourceLocator("minecraft", "item/stone")); $image = $model->render(64, 64);