/toolxp 指令

给玩家手中的 Tinkers’ 工具加指定数量的经验(工具等级与挖掘等级同时加)。

  • 注册:IguanaTweaksTConstruct 的 FMLServerStartingEvent(脉冲 ToolLeveling 加载时)
  • 类:leveling/commands/IguanaCommandToolXP.java
  • 权限等级:2(OP)
  • 用法:/toolxp <数量> [玩家名]

参数解析

源码的参数顺序处理是玩家名在前、数量在后(与 /toolxp <数量> [玩家名] 的直觉相反):

EntityPlayerMP player = astring.length >= 2 ? getPlayer(icommandsender, astring[0])
                                            : getCommandSenderAsPlayer(icommandsender);
int xp = astring.length >= 2 ? parseIntWithMinMax(icommandsender, astring[1], 0, Integer.MAX_VALUE)
                             : parseIntWithMinMax(icommandsender, astring[0], 0, Integer.MAX_VALUE);
参数个数 玩家 数量
1 命令发送者 astring[0]
2 astring[0] astring[1]

数量范围 0 ~ Integer.MAX_VALUE(parseIntWithMinMax 内部走 parseIntBounded)。

流程

1. 前置校验

与 /leveluptool 指令 相同:必须是 ToolCore 且带 ToolLevel 标签,否则:

Player must have a levelable Tinker's Construct tool in hand
Player must have a Tinker's Construct tool in hand

2. 满级判定

if (level >= 1 && level <= 5 || hLevel >= Copper.harvestLevel() || hLevel < Manyullyn.harvestLevel())

不满足则 WrongUsageException("Players tool is already max level")。与 /leveluptool 同样的符号疑似反置问题。

3. 加经验

Long toolXP = tags.hasKey("ToolEXP") ? tags.getLong("ToolEXP") : -1L;
Long headXP = tags.hasKey("HeadEXP") ? tags.getLong("HeadEXP") : -1L;
LevelingLogic.updateXP(equipped, entityplayermp, toolXP + xp, headXP + xp);

与 工具等级系统 的正常累积一致:同一点经验同时加到两条曲线,因此一次调用可能同时触发工具升级和挖掘等级提升。

注意这里走的是 updateXP 而非 addXP,绕过创造模式检查(addXP 首行 if (player.capabilities.isCreativeMode) return;)。因此 /toolxp 对创造模式玩家也有效。

已知的未完成部分

两处 notifyAdmins 同样被注释掉(// TODO: find replacement for notifyAdmins / // possibly RConConsoleSource?),执行后无成功反馈,只通过升级音效与聊天消息体现。

相关