feat: 为 /particlex text 添加 scaling 参数以提升文本显示清晰度#12
Merged
hackermdch merged 2 commits intohackermdch:mainfrom Mar 23, 2026
Merged
feat: 为 /particlex text 添加 scaling 参数以提升文本显示清晰度#12hackermdch merged 2 commits intohackermdch:mainfrom
hackermdch merged 2 commits intohackermdch:mainfrom
Conversation
hackermdch
approved these changes
Mar 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
为 /particlex text 命令添加 scaling 参数,支持文本渲染缩放以提升复杂中文字符的粒子显示清晰度
背景
遇到问题
当使用
/particlex text命令渲染包含中文的文本时(例如/particlex text ... {"text":"测试"}),生成的粒子无法清晰显示汉字,笔画模糊甚至难以辨认。而英文字符(如 "Abc")则显示正常。原因分析
TextUtil.toImage方法利用Minecraft.font.drawInBatch将文本绘制到一个离屏纹理(TextureTarget)上,纹理尺寸为font.width(text)×font.lineHeight(高 9 像素)。uniform字体),每个字形设计为 16×16 像素,但被强制压缩到 9 像素高度内(实际有效部分可能只有 8 像素),导致笔画细节严重丢失。解决方案
通过增加
scaling参数,可以按比例放大文本渲染尺寸,生成更高分辨率的图像,从而让每个字符拥有更多粒子细节,显著提升显示效果。改动内容
TextCommand.java
为
text子命令添加scaling参数(SuggestDoubleArgumentType,默认值1.0),作为第二个参数插入在text之后。所有命令分支均支持该参数,并向下传递。TextPayload.java
新增
double scaling字段,在构造函数、序列化/反序列化方法中读写该字段,并在网络处理中传递给ParticleUtil.spawnTextParticle。ParticleUtil.java
spawnTextParticle方法增加double scaling参数,并将其转换为float后调用TextUtil.toImage。同时,将粒子生成从spawnParticle改为CustomParticleBuilder.buildParticle,并将颜色、速度、年龄等属性写入ParticleStruct,使其可以用expression来固定文本的每个像素(粒子)大小。TextUtil.java
toImage方法新增float scale参数,实现按比例放大渲染:scale == 0时返回 1×1 图像)。效果
使用
scaling参数(例如scaling设为 2)后,文本会被渲染为更大尺寸的图像,每个字符的像素点增多,笔画细节更清晰,尤其适合中文等复杂字形。许可证
我同意以 LGPL-3.0 许可证贡献此代码。