✨ Spell Renderer
面向 Fabric 模组的现代化 2D UI 渲染:圆角面板、液态玻璃、清晰文本和可拖拽 HUD,全部来自一个流畅的 API。

在 Minecraft 中构建美观的界面通常意味着要与 GuiGraphics 搏斗,或者自己编写原始 OpenGL。Spell Renderer 为你提供了一个小巧且可链式调用的构建器。你只需描述形状并调用 .submit(),库便会处理着色器、批处理、缩放和裁剪。
📦 这是一个库模组。 单独安装它不会向游戏添加任何内容。如果其他模组需要它,请安装它;或者使用它来构建你自己的 UI。
🎨 你可以绘制的内容
| 形状 |
用途 |
| 矩形 |
具有圆角的窗格和按钮,每个角落可以有不同半径,以及渐变色 |
| 圆形 |
圆点、指示器、头像 |
| 图像 |
可选圆角的纹理 |
| 文本 |
任意尺寸下保持清晰的文本,使用 MSDF 字体 |
| 图标 |
来自你自己图标字体的命名图标,例如 Builder.icon("settings") |
| 玻璃 |
磨砂或液态玻璃面板,支持调整模糊、折射等效果 |
🧊 新增:液态玻璃
玻璃面板已从底层重新构建。每个面板都有独立的设置:
- 模糊。 从几乎不可见到重度磨砂,且所有半径的成本相同,因此重度模糊不会拖慢你的 UI 性能。
- 折射。 边缘像透镜一样弯曲背景,呈现液态玻璃外观。将其设置为 0 可获得平面磨砂玻璃效果。
- 色散。 边缘处微妙的 RGB 色差条纹。
- 饱和度。 使玻璃后面的背景更加生动,或将其转为灰度。
- 高光。 边缘处的一圈细光。
Builder.glass()
.pos(20, 20)
.size(200, 120)
.radius(16)
.blur(16)
.refraction(0.9f)
.chromatic(4)
.saturation(1.4f)
.highlight(0.3f)
.submit();
现在玻璃在任何 UI 缩放比例下看起来都一致,并且玻璃叠加玻璃的效果也如预期般工作。
⚡ 功能特性
- 🔗 流畅构建器。 在一个可读的链式调用中完成定位、大小、颜色、圆角和淡入淡出。
- 🖱️ 可拖拽形状。 为形状添加
.draggable("id"),玩家即可用鼠标移动它。其子元素会随其一起移动,无法移出屏幕,且位置可以保存和恢复。
- 👪 父子关系。 将形状附加到父级上,它们将跟随父级的位置、深度和不透明度。
- 🚀 批量渲染。 相同类型的形状会在一次绘制调用中一起绘制。
- 🔤 MSDF 文本。 文本在任何缩放比例和任何 GUI 尺寸下都保持清晰。
- ✂️ 剪刀(裁剪)。 将绘制区域限制在指定范围内,这对于滚动列表和蒙版面板非常有用。
- 🔍 缩放。 独立于 Minecraft 的 GUI 缩放比例来缩放整个 UI。
- 🧭 渲染上下文。 在游戏过程中在 HUD 上绘制,或在每个屏幕之上的 GUI 层上绘制。(世界渲染正在开发中。)
🧑💻 代码示例
SpellRenderer.on(RenderContext.HUD, () -> {
var panel = Builder.rect()
.pos(20, 20)
.size(220, 80)
.radius(12)
.color(new Color(30, 30, 40))
.draggable("my-panel"); // 玩家在打开聊天时也可以移动它
panel.submit();
Builder.text("Hello, Spell!")
.pos(12, 12)
.size(24)
.parent(panel) // 随面板一起移动
.submit();
});
📥 快速开始
从 Modrinth Maven 添加依赖:
repositories {
maven { url = "https://api.modrinth.com/maven" }
}
dependencies {
implementation "maven.modrinth:spell-renderer:<version>"
include "maven.modrinth:spell-renderer:<version>" // 可选:将其打包进你的模组中
}
Maven 配置、字体和图标的添加方法以及完整的 API 请参阅 GitHub 上的文档。
📋 要求
- Minecraft 26.2
- Fabric Loader >=0.20.1+
- Fabric API
- Java 25
💬 发现 bug 或有想法?
请在 GitHub 上提交 Issue。欢迎提供反馈和贡献!
✨ Spell Renderer
Modern 2D UI rendering for Fabric mods: rounded panels, liquid glass, crisp text and draggable HUDs, all from one fluent API.

Building a good-looking interface in Minecraft usually means fighting with GuiGraphics or writing raw OpenGL yourself. Spell Renderer gives you a small, chainable builder instead. You
describe a shape and call .submit(), and the library takes care of shaders, batching, scaling and clipping.
📦 This is a library mod. On its own it adds nothing to the game. Install it if another mod needs it, or use it to build your own UI.
🎨 What you can draw
| Shape |
What it's for |
| Rectangle |
Panels and buttons with rounded corners, a different radius per corner, and gradient colors |
| Circle |
Dots, indicators, avatars |
| Image |
Textures with optional rounded corners |
| Text |
Sharp text at any size, using MSDF fonts |
| Icon |
Named icons from your own icon fonts, e.g. Builder.icon("settings") |
| Glass |
Frosted or liquid glass panels with adjustable blur, refraction and more |
🧊 New: liquid glass
Glass panels have been rebuilt from the ground up. Each panel has its own settings:
- Blur. From barely there to heavily frosted, and every radius costs the same, so heavy blur doesn't slow your UI down.
- Refraction. Edges bend the background like a lens, for the liquid-glass look. Set it to 0 for flat frosted glass.
- Chromatic split. A subtle RGB fringe along the edges.
- Saturation. Make the background behind the glass more vivid, or turn it grayscale.
- Highlight. A thin rim of light along the edge.
Builder.glass()
.pos(20, 20)
.size(200, 120)
.radius(16)
.blur(16)
.refraction(0.9f)
.chromatic(4)
.saturation(1.4f)
.highlight(0.3f)
.submit();
Glass now looks the same at every UI scale, and stacking glass on glass works as you'd expect.
⚡ Features
- 🔗 Fluent builder. Position, size, color, round and fade a shape in one readable chain.
- 🖱️ Draggable shapes. Add
.draggable("id") to a shape and players can move it with the mouse. Its children move with it, it can't leave the screen, and its position can be saved
and restored.
- 👪 Parenting. Attach shapes to a parent and they follow its position, depth and opacity.
- 🚀 Batched rendering. Shapes of the same type are drawn together in one draw call.
- 🔤 MSDF text. Text stays sharp at any scale and any GUI size.
- ✂️ Scissors. Clip drawing to a region, which is handy for scroll lists and masked panels.
- 🔍 Scaling. Scale your whole UI independently of Minecraft's GUI scale.
- 🧭 Render contexts. Draw on the HUD during gameplay or on the GUI layer above every screen. (World rendering is in development.)
🧑💻 How it looks in code
SpellRenderer.on(RenderContext.HUD, () -> {
var panel = Builder.rect()
.pos(20, 20)
.size(220, 80)
.radius(12)
.color(new Color(30, 30, 40))
.draggable("my-panel"); // players can move it while chat is open
panel.submit();
Builder.text("Hello, Spell!")
.pos(12, 12)
.size(24)
.parent(panel) // moves together with the panel
.submit();
});
📥 Getting started
Add it from the Modrinth Maven:
repositories {
maven { url = "https://api.modrinth.com/maven" }
}
dependencies {
implementation "maven.modrinth:spell-renderer:<version>"
include "maven.modrinth:spell-renderer:<version>" // optional: bundle it inside your mod
}
Maven setup, adding fonts and icons, and the full API are in the documentation on GitHub.
📋 Requirements
- Minecraft 26.2
- Fabric Loader >=0.20.1+
- Fabric API
- Java 25
💬 Found a bug or have an idea?
Open an issue on GitHub. Feedback and contributions are welcome!
评论 0
登录后参与评分
还没有评论,来抢沙发吧