/igdebug 指令
模拟 随机奖励 的概率分布,用于验证整合包的平衡性。
- 类:
iguanaman.iguanatweakstconstruct.debug.DebugCommand - 权限等级:
2(OP) - 用法:
getCommandUsage返回null(无用法提示) - 模块:脉冲
Debug
实现
EntityPlayerMP player = astring.length >= 1 ? getPlayer(icommandsender, astring[0])
: getCommandSenderAsPlayer(icommandsender);
ItemStack equipped = player.getCurrentEquippedItem();
if (equipped != null && equipped.getItem() instanceof ToolCore) { ... }
前置条件与 /leveluptool、/toolxp 不同:执行者自己必须手持一件 ToolCore(虽然指令内部实际并不会用到 equipped 的数据)。
模拟循环
HashMap<RandomBonuses.Modifier, Integer> foo = new HashMap<>();
for (int i = 0; i < 1000; i++) {
ItemStack head = new ItemStack(TinkerTools.toolRod, 0, 2);
ItemStack handle = new ItemStack(TinkerTools.bowstring, 0, 0);
ItemStack accessory = new ItemStack(TinkerTools.toolRod, 0, 4);
ItemStack tool = ToolBuilder.instance.buildTool(head, handle, accessory, "testtool");
for (int j = 0; j < 5; j++) {
RandomBonuses.Modifier mod = RandomBonuses.tryModifying(player, tool);
if (!foo.containsKey(mod)) foo.put(mod, 1);
else foo.put(mod, foo.get(mod) + 1);
}
}
for (Map.Entry<...> bar : foo.entrySet())
sender.addChatMessage(new ChatComponentText(bar.getKey().toString() + ": " + bar.getValue()));
| 参数 | 值 |
|---|---|
| 外层循环 | 1000 次 |
| 内层循环 | 5 次 |
| 工具 | toolRod + bowstring + toolRod = 弓(三段弓身) |
| 工具名 | "testtool" |
| 总抽奖次数 | 5000 |
每次抽奖后把结果计入 HashMap<Modifier, Integer>,最后按 Modifier.toString(): 次数 逐行输出到聊天栏。
因为构建的是弓,抽奖遵循
bowWeights表——预期输出中Redstone(权重 100)与Reinforced(65)会占大头,而Critical(权重 0)应完全不出现。实际输出可以直接与 弓权重表 对照验证。
源码中注释掉的分支
指令内有两处被注释的配置强制与工具模板:
// Config.randomBonusesAreUseful = true;
// Config.randomBonusesAreRandom = false;
...
// pick
// ItemStack head = new ItemStack(TinkerTools.pickaxeHead, 0, 2);
// ItemStack handle = new ItemStack(TinkerTools.toolRod, 0, 3);
// ItemStack accessory = new ItemStack(TinkerTools.binding, 0, 4);
// sword
// ItemStack head = new ItemStack(TinkerTools.swordBlade, 0, 2);
// ItemStack handle = new ItemStack(TinkerTools.toolRod, 0, 3);
// ItemStack accessory = new ItemStack(TinkerTools.wideGuard, 0, 4);
即原本支持临时强制 UsefulBonuses / CompletelyRandomBonuses 并测试镐、剑、弓三种工具,当前版本硬编码为弓。
另有一段被注释的 NBT dump,用于逐条打印工具 tooltip:
// NBTTagCompound tags = equipped.getTagCompound().getCompoundTag("InfiTool");
// int tipNum = 0;
// while (true) {
// tipNum++;
// String tip = "Tooltip" + tipNum;
// String modTip = "ModifierTip" + tipNum;
// ...
// }
副作用
RandomBonuses.tryModifying 会真的调用修饰符的 addMatchingEffect / modify,因此模拟过程会:
- 向聊天栏发送随机奖励消息(
message.levelup.*) - 播放
iguanatweakstconstruct:chime音效 - 实际修改
testtool的 NBT(该工具不存在于世界中,因此不污染玩家物品)
这是在线执行的,会刷屏 5000 次聊天消息与音效,仅建议在测试环境使用。