TagPlayerPotion

6 组药水 tag(索引 = 药水 ID)

基本信息

属性 值
路径 com.github.lunatrius.ingameinfo.tag.TagPlayerPotion
行数 222
分类 playerpotion
构造调用数 6 × Potion.potionTypes.length(受 null 过滤)

索引上界来自原版数组

public static final int MAXIMUM_INDEX = Potion.potionTypes.length;   // :18
public boolean isIndexed() { return true; }                          // :43
public int getMaximumIndex() { return MAXIMUM_INDEX - 1; }           // :48

⚠️ 上界不是硬编码,而是读 net.minecraft.potion.Potion.potionTypes.length —— 也就是说上界随其他 mod 注册的药水而变。 装了 potion 扩展后上界自动增大。

⚠️ 但注册循环里 if (potion == null) continue;(:209)—— 数组中未使用的槽位是 null,会被跳过。 所以「上界 = 数组长度」包含了空洞。

6 组 tag

tag 名 内部类 取值
potioneffect Effect 药水名
potionduration Duration 剩余时间(格式化)
potiondurationticks DurationTicks 剩余 tick
potionnegative Negative 是否负面效果
potionicon Icon(large=false) 16×16 药水图标
potionlargeicon Icon(large=true) 大号图标

与 TagNearbyPlayer 相同的两个缺陷

register()(:205-217)对每个非 null 药水重复注册完全相同的名字:

for (int i = 0; i < MAXIMUM_INDEX; i++) {
    final Potion potion = Potion.potionTypes[i];
    if (potion == null) continue;
    TagRegistry.INSTANCE.register(new Effect(i).setName("potioneffect"));
    // ... 6 个都这样
}
  1. 重复注册被拒 —— TagRegistry 的 containsKey 让第 2 次起的注册全部失败,最终只有第一个非 null 药水的实例留在表里。
  2. {potioneffect[3]} 索引语法不被支持 —— Value 的 getVariableValue(:117-132)直接查表、 不剥离 [N],查不到就返回 <ERROR>。 jar 内默认配置也从未使用索引语法。

即:本类的 shouldUpdate / updatePotionEffects 等内部机制 (:200-203 按 Info.identifier 比对药水 ID 来决定是否重建图标) 在当前注册方式下无法被正确触发,因为表里只有一份实例。

资源释放

public static void releaseResources() { potionEffects = null; }   // :218-220

由 Ticker 的 Tag.releaseResources() 间接调用, 断开服务器时也由 TickerManager 调用。

相关