Solved Pasting Schematics in Block Populator

Discussion in 'Plugin Development' started by MasOS, Jul 24, 2018.

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


    Hello Everyone,

    I've been trying to randomly generate custom structures via the block populator. I've already pre-made the schematic of the build and implemented the pasting methods; however, I don't have any good ideas on how to blend the pasted schematic with the surrounding terrian.

    My current method is to detect the lowest block of the chunk (the structure's size is 1 chunk on x/z axis, and around 20 blocks on the y axis) that the custom structure is being pasted in to avoid floating structures. It works well with flat terrians, but... upon hilly terrians or near water, the flaw of this method appears: it liturally cuts the terrian in half.
    Screenshot (open)

    Does anyone have any idea on how to solve this issue of blending chunks?
    Here's my current code:
    private void pasteSchem(File schem, Chunk chunk) {
            Schematic toPaste;
            try {
                toPaste = ClipboardFormat.SCHEMATIC.load(schem);
            } catch (IOException e) {
                // Schematic fetching failed, exiting the method & logs
            // Finds and adds the 4 corners of the chunk
            ArrayList<Block> corners = new ArrayList<>();
            corners.addAll(Arrays.asList(chunk.getWorld().getHighestBlockAt(chunk.getBlock(0, 80, 0).getLocation()),
                    chunk.getWorld().getHighestBlockAt(chunk.getBlock(15, 80, 0).getLocation()),
                    chunk.getWorld().getHighestBlockAt(chunk.getBlock(0, 80, 15).getLocation()),
                    chunk.getWorld().getHighestBlockAt(chunk.getBlock(15, 80, 5).getLocation())));
            // Compare and get the lowest block
            Block lowestBlock = corners.get(0);
            for (Block b : corners) {
                if (b.getY() >= lowestBlock.getY())
                lowestBlock = b;
            // Paste the schematic onto the lowest block
            toPaste.paste(new BukkitWorld(chunk.getWorld()),
                    new Vector(lowestBlock.getX(), lowestBlock.getY(), lowestBlock.getZ()));
    Thanks in advance!
  2. Offline


    Solved by myself
  3. Offline


    Can you explain/tell others what you did to solve this problem? Maybe other people that will search for this issue can find the answer faster than asking the same question over and over again :)
Thread Status:
Not open for further replies.

Share This Page