/dumpTools 指令

把当前世界中所有会被原版工具削弱机制影响的物品名导出成文本文件,供整合包制作豁免名单。

  • 类:iguanaman.iguanatweakstconstruct.commands.CommandDumpTools
  • 权限等级:未覆写(继承 CommandBase 默认值 0)
  • 用法:/dumpTools
  • 输出文件:游戏根目录下的 dump_Tools.txt

筛选逻辑

List<String> itemnames = new LinkedList<String>(Item.itemRegistry.getKeys());
Collections.sort(itemnames);
for (Object key : itemnames) {
    Object item = Item.itemRegistry.getObject(key);
    if (item instanceof ItemTool || item instanceof ItemHoe
            || item instanceof ItemSword || item instanceof ItemBow)
        pw.println(key.toString());
}
条件 匹配到的原版类型
instanceof ItemTool 斧、镐、锹
instanceof ItemHoe 锄
instanceof ItemSword 剑
instanceof ItemBow 弓

先排序再输出——源码注释:// we sort the names, otherwise it's quite hard to find something in the list。

被注释掉的更宽松判定

源码中有一段被注释的逻辑,本意是用 getToolClasses 捕获所有「有工具类」的物品(覆盖 mod 自定义工具):

// if it's not one of these, but still has a toolclass, we consider it tool.
// else if(item instanceof Item)
// if(!((Item) item).getToolClasses(null).isEmpty())
// pw.println(key.toString());

因此当前版本只导出原版四类工具,mod 工具(如 Botania 魔力钢镐)不会被导出——这解释了为什么 AllowedTools 配置 的默认豁免列表需要手写 mod 物品名。

失败处理

FileNotFoundException 时:

Log.error("Couldn't create file " + file.getName());
icommandsender.addChatMessage(new ChatComponentText("Couldn't create file " + file.getName()));

即记日志并在聊天栏报错,不抛异常。文件路径是相对路径 new File("dump_Tools.txt"),即相对于 Minecraft 服务端的工作目录。

配合使用

导出结果可直接粘贴进主配置 AllowedTools 分类的 tools / swords / bows / hoes 四个列表。配置项注释明确指向本指令:

To make this easier a /dumpTools command is provided, that dumps the names of all applicable items in your world. Copy'n'Paste away!

相关