BlockSnapshot don't restore in unloaded chunks

Why BlockSnapshot doesn’t restore in unloaded areas of the world, where there is no player? I generate huge structures using this class, and they are clipped exactly at the boundaries of the chunks. The restore method always returns true.

So the work around is to load the chunk of the location first.

    BlockSnapshot snapshot;
    Vector3i vector = snapshot.getPosition();
    UUID uuid = snapshot.getWorldUniqueId();
    World world = Sponge.getServer().loadWorld(uuid).get();
    Location<World> loc = world.getLocation(vector);
    world.loadChunk(loc.getChunkPosition(), true);
    snapshot.restore(true, BlockChangeFlags.ALL);
1 Like

I already tried that. Well, I’ll try again. I will answer later.

make sure the boolean value on loadChunk is true, the code worked for me back in API 4 bu the boolean value needed to be true even if the chunk was generated. It will not change the chunk itself.

It’s useless … This method doesn’t work, as it was, it remains. Cuts exactly at the border of chunks. :frowning_face:

UPD: The problem is solved. It turned out that I called getChunkPosition() from the source position of snapshot, but it was necessary from the target position already calculated. Thanks for the help! :+1:

1 Like