ValueMath
9 个算术函数
基本信息
| 属性 | 值 |
|---|---|
| 路径 | com.github.lunatrius.ingameinfo.value.ValueMath |
| 行数 | 158 |
| 注册函数数 | 9 |
全部 9 个函数
| 主名 | 别名 | 运算 | 参数个数 |
|---|---|---|---|
add |
无 | + |
2 |
sub |
无 | - |
2 |
mul |
无 | * |
2 |
div |
无 | / |
2 |
round |
无 | 四舍五入 | 1 |
mod |
modulo |
%(浮点) |
2 |
modi |
modint、moduloi、moduloint |
%(整数) |
2 |
pct |
percent、percentage |
×100 转百分比 | 1 |
⚠️ mod 与 modi 的别名有重叠风险:
modint / moduloi / moduloint 都是 modi 的别名,
而 modulo 是 mod 的别名。
modulo 与 moduloi 只差一个 i —— 拼写时极易混淆,
且没有互相覆盖(名字不同)。
⚠️ pct 的三个别名(pct / percent / percentage)
与 ValueLogic 的 contains/in 一样属于易记别名风格,
说明本 mod 有意提供短名 + 全名两套写法。
数值来源
所有运算取子节点的已替换值再解析:
Value 的 getIntValue() / getDoubleValue()
(:93-107)内部走 getReplacedValue(),
所以运算两侧可以嵌 {tag}:
<add><var>health</var><num>10</num></add>
⚠️ 但 getIntValue() / getDoubleValue() 无 try/catch ——
若 <var> 指向的 tag 返回空串(如未装备时),
Double.parseDouble("") 抛 NumberFormatException。
三个实现的差异
| 函数 | 返回类型 | 说明 |
|---|---|---|
add/sub/mul |
int |
走 getIntValue,截断为整数 |
div |
int or double |
整除截断 |
mod |
double |
浮点取模 |
modi |
int |
整数取模 |
round |
int |
Math.round 后转 int |
pct |
文本 | value * 100 后拼 % |
⚠️ add / sub / mul 用 getIntValue()(Integer.parseInt),
所以不支持小数。配置里写 <num>1.5</num> 参与加法会抛异常。
需要小数运算得用 div 或 mod(走 double 路径)。
相关
- Value -
getIntValue/getDoubleValue的定义 - ValueLogic - 兄弟类,比较类函数
- ValueComplex - 兄弟类,格式化类函数