试验大量的锻造场箱子的笔记:Minecraft 1.12.2

环境

    forgeSrc-1.12.2-14.23.4.2705

背景: 提供中文本地化的唯一选择

由于通常情况下每个村庄只有最多两个铁匠铺,因此要调查铁匠铺中会出现什么物品是困难的。

原理可以用中文来解释。

将以下代码直接插入到net.minecraft.world.gen.structure.StructureVillagePieces.House2.addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn)方法的this.hasMadeChest = true;语句之后,即可进行大量尝试。

ArrayList<Tuple3<Long, String, Integer>> hash2 = new ArrayList<>();
for (long seed = 0; seed <= 0xffff; seed++) {
    this.generateChest(worldIn, structureBoundingBoxIn, new Random(seed * 47861474789L), 5, 1, 5, LootTableList.CHESTS_VILLAGE_BLACKSMITH);

    BlockPos blockpos = new BlockPos(this.getXWithOffset(5, 5), this.getYWithOffset(1), this.getZWithOffset(5, 5));

    TileEntity tileEntity = worldIn.getTileEntity(blockpos);
    if (tileEntity instanceof TileEntityChest) {
        TileEntityChest tileEntity2 = (TileEntityChest) tileEntity;
        HashMap<String, Integer> hash = new HashMap<>();
        IntStream.range(0, tileEntity2.getSizeInventory())
            .mapToObj(i -> tileEntity2.getStackInSlot(i))
            .filter(s -> !s.isEmpty())
            .forEach(s -> hash.put(s.getDisplayName(), hash.getOrDefault(s.getDisplayName(), 0) + s.getCount()));

        hash2.add(new Tuple3<>(seed, hash.entrySet().stream()
            .sorted((a, b) -> a.getKey().compareTo(b.getKey()))
            .map(e -> e.getKey() + "*" + e.getValue())
            .collect(Collectors.joining(",")), hash.getOrDefault("Diamond", 0)));
    }

    worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 6);
}

hash2.stream()
    .filter(t -> t._3() > 0)
    .sorted((a, b) -> -a._3().compareTo(b._3()))
    .forEach(t -> System.out.println(String.format("%s %s %s",
        t._3(),
        t._1(),
        t._2())));

通过在generateChest中使用randomIn来确定chest的种子,chest的内容是由该种子设定的。但是,仅仅设置种子并不会设置实际的物品。chest的内容是在调用getStackInSlot时确定的。

补充:Tuple3可能是指的Scala中的那个。

实验条件

检查种子范围在0到65535之间的宝箱内容。按钻石数量对宝箱内物品进行排序,并查看前10个最高数量的钻石。

结果

9 37210 Apple*1,Bread*3,Diamond*9,Gold Ingot*3,Iron Pickaxe*2
9 46216 Apple*4,Bread*5,Diamond*9,Diamond Horse Armor*1
9 51971 Apple*2,Diamond*9,Diamond Horse Armor*1,Iron Leggings*1,Oak Sapling*4
9 54626 Apple*2,Bread*3,Diamond*9,Iron Boots*1,Iron Chestplate*1,Iron Pickaxe*1
8 1955 Apple*6,Diamond*8,Diamond Horse Armor*1,Iron Sword*1
8 15514 Apple*3,Diamond*8,Iron Boots*2,Iron Pickaxe*1,Obsidian*3
8 18847 Diamond*8,Diamond Horse Armor*1,Iron Ingot*5,Obsidian*3,Saddle*1
8 57533 Apple*2,Diamond*8,Saddle*1
8 63605 Apple*10,Diamond*8
7 59266 Bread*2,Diamond*7,Iron Boots*1,Iron Pickaxe*1

只需一種選擇來將其改寫成中文:即使只測試了65536種情況,也存在9顆鑽石等優質掉落物。不確定是否有上限,但如果測試了48位元的種子可能還會出現含有20顆鑽石的寶箱。