Hello!
I need to save the building and the coordinates of the required blocks.
For example, this is how the building looks like. And the block coordinate that I need to save looks like this.
I use this code to get building blocks. The first and second blocks are redstone blocks that are located at the edges of the building.
int maxY = firstBlockXYZ[1];
int firstBlockX = firstBlockXYZ[0];
int firstBlockZ = firstBlockXYZ[2];
int secondBlockX = secondBlockXYZ[0];
int secondBlockZ = secondBlockXYZ[2];
List<String> blocks = new ArrayList<>();
for(int x=firstBlockX; x>=secondBlockX; x--) {
for(int z=firstBlockZ; z>=secondBlockZ; z--) {
BlockPos blockPos = new BlockPos(x, maxY, z);
Block block = world.getBlockState(blockPos).getBlock();
blocks.add(String.valueOf(block));
}
}
Further, to get the coordinates of the necessary blocks, I manually take the coordinates of the necessary blocks and subtract these coordinates from the first redstone block.
Finally, I save the list of blocks and the required coordinates to a json file.
{
"name": "building",
"blocks": [
"Block{minecraft:redstone_block}",
"Block{minecraft:stone}",
...
],
"coordinates": [
"-11 -7 -6",
"XXX",
"XXX"
]
}
This works great for one degree. If need to rotate the building, it won't work.
I somehow need to change the block indices in the json file and, accordingly, change the coordinates of the necessary blocks.
Maybe I should change the format for saving blocks and necessary blocks from a json file to a schematic file? But, I have never used the schematic and do not understand it.