How to copy chunks in api version 1.14

Discussion in 'Plugin Development' started by coddyfish, Sep 25, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    coddyfish

    I am trying to copy chunks from one world to another, however when I try it is copying one slice and then pasting it to fill the rest of the chunk. Here is my methood.


    Code:
    public static void copyChunk(Chunk from, Chunk to) {
            Block fromBlock;
            Block toBlock;
            Block[][][] xyz = new Block[16][16][256];
            for (int x = 0; x < 16; x++) {
                for (int y = 0; y < 256; y++) {
                    for (int z = 0; z < 16; z++) {
                        xyz[x][y][z] = from.getBlock(x, y, z);
                    }
                }
            }
            for (int i = 0; i < xyz.length; i++) {
                for (int j = 0; j < xyz[i].length; j++) {
                    for (int k = 0; k < xyz[j].length; k++) {
                        int x = i;
                        int z = j;
                        int y = k;
                        fromBlock = from.getBlock(x, y, z);
                        toBlock = to.getBlock(x, y, z);
                        toBlock.setType(fromBlock.getType());
                        toBlock.getState().setType(toBlock.getState().getType());
                        toBlock.getState().setData(fromBlock.getState().getData().clone());
                        toBlock.getState().update();
                    }
                }
            }
        }
     
  2. Online

    timtower Administrator Administrator Moderator

    @coddyfish 1. Don't use double variables, just loop over x, y, and z
    2. Do you get all positions if you debug it?
     
  3. Offline

    coddyfish

    It seems like the code stops at the for loops this code does not run.

    Code:
            Block fromBlock;
            Block toBlock;
            Block[][][] xyz = new Block[16][16][256];
            p.sendMessage(":(");
            for (int x = 0; x < 16; x++) {
                p.sendMessage(":(x");
                for (int y = 0; y < 256; y++) {
                    p.sendMessage(":(xy");
                    for (int z = 0; z < 16; z++) {
                        p.sendMessage(":(xyz");
                        xyz[x][y][z] = from.getBlock(x, y, z);
                        p.sendMessage(":((((((((");
                    }
                }
            }
          
            for (int x = 0; x < xyz.length; x++) {
                for (int y = 0; y < xyz[x].length; y++) {
                    for (int z = 0; z < xyz[x][y].length; z++) {
                        p.sendMessage(Integer.toString(x) + " " + Integer.toString(y) + " " + Integer.toString(z));
                        fromBlock = from.getBlock(x, y, z);
                        toBlock = to.getBlock(x, y, z);
                        toBlock.setType(fromBlock.getType());
                        toBlock.getState().setType(toBlock.getState().getType());
                        toBlock.getState().setData(fromBlock.getState().getData().clone());
                        toBlock.getState().update();
                    }
                }
            }
        }
    I am not getting any of the p.sendMessage commands that are inside the for loops
     
    Last edited by a moderator: Sep 25, 2019
  4. Online

    timtower Administrator Administrator Moderator

    @coddyfish Why do you have the array to start with? You don't need it.
     
Thread Status:
Not open for further replies.

Share This Page