渲染位置栅格
基本信息
| 属性 |
值 |
| 枚举类 |
alexiil.mods.load.json.EPosition |
| 取值数 |
9(3×3 栅格) |
| 字段 |
private final int x, y;(取 -1 / 0 / 1) |
枚举值
| 值 |
x 系数 |
y 系数 |
行为 |
TOP_LEFT |
-1 |
-1 |
原点对齐左上角 |
TOP_CENTER |
0 |
-1 |
水平居中 |
TOP_RIGHT |
1 |
-1 |
靠右 |
CENTER_LEFT |
-1 |
0 |
垂直居中,靠左 |
CENTER |
0 |
0 |
屏幕中心 |
CENTER_RIGHT |
1 |
0 |
垂直居中,靠右 |
BOTTOM_LEFT |
-1 |
1 |
靠左下角 |
BOTTOM_CENTER |
0 |
1 |
水平居中,靠下 |
BOTTOM_RIGHT |
1 |
1 |
右下角 |
变换规则
transformX(x, screenWidth) / transformY(y, screenHeight) 调用 transform(coefficient, coord, screenThing):
| coefficient |
返回值 |
| -1 |
coord(使用原始坐标) |
| 0 |
screenThing / 2 - coord(中心对齐) |
| 1 |
screenThing - coord(靠右/靠下) |
非 -1/0/1 时抛 Error(枚举不可能出现,但防御性检查)。
ImageRender 适配
public int transformX(int screenWidth) {
if (position == null || positionType == null) return 0;
int trueX = position.width;
if (trueX == 0) trueX = screenWidth; // width=0 时按全屏处理
return positionType.transformX(position.x, screenWidth - trueX);
}
transformX 输入 screenWidth - trueX,因此 positionType=TOP_LEFT, position.x=10, trueX=300 → 10 像素处开始绘制。
transformY 直接用 screenHeight - position.height,配合 positionType 系数把 9 宫对齐转化为像素坐标。
使用场景
ImageRender.positionType:每个渲染元素的锚点。
MinecraftDisplayer.baseTipsTextPos(默认 "BOTTOM_CENTER"):tip 文本的基础锚点(注释明确"其它元素固定用 CENTER")。
相关条目