Jump to content

Save and rotate the building


Abdymazhit

Recommended Posts

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.

image.png.579b1de2694cd38605aef7f435f844d8.pngimage.png.037618d8020554007b27f8ae9a57df35.png

 

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.