1.16.5 Get center of WorldEdit Schematic Paste

Discussion in 'Spigot Plugin Development' started by VrektHF, Jun 9, 2021.

  1. I have a schematic file that I'm pasting into the world. I randomly generate the location to use when pasting the schematic. Everything works fine there but I'm having trouble trying to get/find the center of the schematic after its been pasted at the new location.

    I want to retrieve the center to spawn a variety of mobs, as a challenge for the player.

    Here is my current code I'm using to paste:
    Code (Text):

    private boolean loadSchematic(World world, Location location) {
        final File schematic = findSchematic();
        final ClipboardFormat format = ClipboardFormats.findByFile(schematic);
        if (format == null) {
            Bukkit.getLogger().warning("Failed to load " + schematic.getName());
            return false;

        try (ClipboardReader reader = format.getReader(new FileInputStream(schematic))) {
            final Clipboard clipboard = reader.read();
            final com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(world);
            try (EditSession session = WorldEdit.getInstance().newEditSession(weWorld)) {
                Operation operation = new ClipboardHolder(clipboard)
                        .to(BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()))
        } catch (Exception any) {
            return false;
        return true;
    A few things I've tried to get the center:
    Code (Text):

    // not even within the paste, is off to the side
    final Location center = location.add(clipboard.getDimensions().getX() / 2f, 0, clipboard.getDimensions().getZ() / 2f);

    // is off a substantial amount as-well
    final Location center = location.add(clipboard.getRegion().getWidth() / 2f, 0, clipboard.getRegion().getLength() / 2f);

    // returns just the center of the original schematic, not the center where its been pasted
    If anybody could help me out it would be greatly appreciated, thanks.
  2. Are you running just worldedit on your server, if so what version? Also what version of worldedit are you building this against.
  3. Server is running 7.2.5 and I'm building with 7.2.0 worldedit-bukkit
    • Like Like x 1
  4. Try this:

    Code (Java):
        public Location getCenter(Location loc, Clipboard cd) {
            return new Location(loc.getWorld(),
                    loc.getBlockX() + (cd.getRegion().getCenter().getX() - cd.getOrigin().getBlockX()),
                    loc.getBlockY() + (cd.getRegion().getCenter().getY() - cd.getOrigin().getBlockY()),
                    loc.getBlockZ() + (cd.getRegion().getCenter().getZ() - cd.getOrigin().getBlockZ()));