如何简化Minecraft结构生成BlockPos变量

时间:2016-06-15 18:10:11

标签: java minecraft minecraft-forge

我在Minecraft中有一个结构类。 结构中有79个街区。 每个块的位置都声明为变量:

int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
BlockPos pos1 = new BlockPos(x + 3, y + -1, z + 0);
BlockPos pos2 = new BlockPos(x + 4, y + -1, z + 0);
BlockPos pos3 = new BlockPos(x + 5, y + -1, z + 0);
BlockPos pos4 = new BlockPos(x + 2, y + -1, z + 1);
BlockPos pos5 = new BlockPos(x + 3, y + -1, z + 1);
BlockPos pos6 = new BlockPos(x + 4, y + -1, z + 1);
BlockPos pos7 = new BlockPos(x + 5, y + -1, z + 1);
BlockPos pos8 = new BlockPos(x + 6, y + -1, z + 1);
BlockPos pos9 = new BlockPos(x + 1, y + -1, z + 2);
BlockPos pos10 = new BlockPos(x + 2, y + -1, z + 2);
BlockPos pos11 = new BlockPos(x + 3, y + -1, z + 2);
BlockPos pos12 = new BlockPos(x + 4, y + -1, z + 2);
BlockPos pos13 = new BlockPos(x + 5, y + -1, z + 2);
BlockPos pos14 = new BlockPos(x + 6, y + -1, z + 2);
BlockPos pos15 = new BlockPos(x + 7, y + -1, z + 2);
BlockPos pos16 = new BlockPos(x + 0, y + -1, z + 3);
BlockPos pos17 = new BlockPos(x + 1, y + -1, z + 3);
BlockPos pos18 = new BlockPos(x + 2, y + -1, z + 3);
BlockPos pos19 = new BlockPos(x + 3, y + -1, z + 3);
BlockPos pos20 = new BlockPos(x + 4, y + -1, z + 3);
BlockPos pos21 = new BlockPos(x + 5, y + -1, z + 3);
BlockPos pos22 = new BlockPos(x + 6, y + -1, z + 3);
BlockPos pos23 = new BlockPos(x + 7, y + -1, z + 3);
BlockPos pos24 = new BlockPos(x + 8, y + -1, z + 3);
BlockPos pos25 = new BlockPos(x + 0, y + -1, z + 4);
BlockPos pos26 = new BlockPos(x + 1, y + -1, z + 4);
BlockPos pos27 = new BlockPos(x + 2, y + -1, z + 4);
BlockPos pos28 = new BlockPos(x + 3, y + -1, z + 4);
BlockPos pos29 = new BlockPos(x + 4, y + -1, z + 4);
BlockPos pos30 = new BlockPos(x + 5, y + -1, z + 4);
BlockPos pos31 = new BlockPos(x + 6, y + -1, z + 4);
BlockPos pos32 = new BlockPos(x + 7, y + -1, z + 4);
BlockPos pos33 = new BlockPos(x + 8, y + -1, z + 4);
BlockPos pos34 = new BlockPos(x + 0, y + -1, z + 5);
BlockPos pos35 = new BlockPos(x + 1, y + -1, z + 5);
BlockPos pos36 = new BlockPos(x + 2, y + -1, z + 5);
BlockPos pos37 = new BlockPos(x + 3, y + -1, z + 5);
BlockPos pos38 = new BlockPos(x + 4, y + -1, z + 5);
BlockPos pos39 = new BlockPos(x + 5, y + -1, z + 5);
BlockPos pos40 = new BlockPos(x + 6, y + -1, z + 5);
BlockPos pos41 = new BlockPos(x + 7, y + -1, z + 5);
BlockPos pos42 = new BlockPos(x + 8, y + -1, z + 5);
BlockPos pos43 = new BlockPos(x + 1, y + -1, z + 6);
BlockPos pos44 = new BlockPos(x + 2, y + -1, z + 6);
BlockPos pos45 = new BlockPos(x + 3, y + -1, z + 6);
BlockPos pos46 = new BlockPos(x + 4, y + -1, z + 6);
BlockPos pos47 = new BlockPos(x + 5, y + -1, z + 6);
BlockPos pos48 = new BlockPos(x + 6, y + -1, z + 6);
BlockPos pos49 = new BlockPos(x + 7, y + -1, z + 6);
BlockPos pos50 = new BlockPos(x + 2, y + -1, z + 7);
BlockPos pos51 = new BlockPos(x + 3, y + -1, z + 7);
BlockPos pos52 = new BlockPos(x + 4, y + -1, z + 7);
BlockPos pos53 = new BlockPos(x + 5, y + -1, z + 7);
BlockPos pos54 = new BlockPos(x + 6, y + -1, z + 7);
BlockPos pos55 = new BlockPos(x + 3, y + -1, z + 8);
BlockPos pos56 = new BlockPos(x + 4, y + -1, z + 8);
BlockPos pos57 = new BlockPos(x + 5, y + -1, z + 8);
BlockPos pos58 = new BlockPos(x + 2, y + 0, z + 2);
BlockPos pos59 = new BlockPos(x + 6, y + 0, z + 2);
BlockPos pos60 = new BlockPos(x + 3, y + 0, z + 3);
BlockPos pos61 = new BlockPos(x + 4, y + 0, z + 3);
BlockPos pos62 = new BlockPos(x + 5, y + 0, z + 3);
BlockPos pos63 = new BlockPos(x + 3, y + 0, z + 4);
BlockPos pos64 = new BlockPos(x + 4, y + 0, z + 4);
BlockPos pos65 = new BlockPos(x + 5, y + 0, z + 4);
BlockPos pos66 = new BlockPos(x + 3, y + 0, z + 5);
BlockPos pos67 = new BlockPos(x + 4, y + 0, z + 5);
BlockPos pos68 = new BlockPos(x + 5, y + 0, z + 5);
BlockPos pos69 = new BlockPos(x + 2, y + 0, z + 6);
BlockPos pos70 = new BlockPos(x + 6, y + 0, z + 6);
BlockPos pos71 = new BlockPos(x + 3, y + 1, z + 3);
BlockPos pos72 = new BlockPos(x + 5, y + 1, z + 3);
BlockPos pos73 = new BlockPos(x + 3, y + 1, z + 5);
BlockPos pos74 = new BlockPos(x + 5, y + 1, z + 5);
BlockPos pos75 = new BlockPos(x + 4, y + 2, z + 3);
BlockPos pos76 = new BlockPos(x + 3, y + 2, z + 4);
BlockPos pos77 = new BlockPos(x + 5, y + 2, z + 4);
BlockPos pos78 = new BlockPos(x + 4, y + 2, z + 5);
BlockPos pos79 = new BlockPos(x + 4, y + 3, z + 4);

如何简化此操作?

我向Google咨询过有关Java List s,数组和Map的问题,但要么我无法将它们应用到我的目标中,要么就更复杂了。

1 个答案:

答案 0 :(得分:0)

您可以使用游戏中的结构块来创建一个结构文件,该结构文件可以加载。

  1. 建立世界结构。
  2. 使用结构块
  3. 将结构保存到文件
  4. 将.nbt文件放在正确的文件夹'resource_root / modid / structures /'中 您可以将文件放在子文件夹中。
  5. 将结构生成世界。
  6. 这是一个可以生成结构中的结构的函数,该结构位于尺寸为loc的{​​{1}}位置pos下,且给定world

    settings

    如果可以构建Structure,它将返回true,如果在逻辑客户端上运行或者无法加载模板,它将失败。

    ResourceLocation和Folder的示例:

    示例1:

    Modid =“test”
    结构文件名=“test_struct.nbt”
    文件夹:“resource_root / test / structures /” ResourceLocation:public static boolean placeStructureInWorld(BlockPos pos, World world,ResourceLocation loc, PlacementSettings settings){ if(!world.isRemote && world instanceof WorldServer){ WorldServer worldServer = (WorldServer) world; Template tmp = worldServer .getStructureTemplateManager() .get(worldServer.getMinecraftServer(),loc); if(tmp==null)return false; tmp.addBlocksToWorldChunk(world,pos,settings); return true; } return false; }

    示例2:

    Modid =“test”
    结构文件名=“test_struct.nbt”
    文件夹:“resource_root / test / structures / subfolder /” ResourceLocation:new ResourceLocation("test","test_struct")