Skip to content

Virtual Chunk

Shane Bee edited this page Apr 12, 2020 · 1 revision

Virtual chunks are just chunks used to handle tiles. When a Minecraft/Bukkit chunk is loaded, a virtual chunk is loaded, and the tiles within that chunk are ticked.
Don't worry, these chunks are TEENY TINY classes that will not affect RAM in a negative manner.

For the most part, API users will not have to deal with these virtual chunks, they're mainly handled internally.

How They Work

When the server starts up, and tiles are loaded from file, as well as when new tiles are created, they are assigned to their specific virtual chunks.
When a Minecraft chunk loads (ie: when a player moves into it), the virtual chunk is loaded and begins to tick the tiles it contains. If a virtual chunk does not contain tiles, it is unloaded/removed.
Virtual chunks are only created for areas in the world where tiles exist.

What You Can Do

There isn't much to do in this class right now. Possibly in the future we can add more.

Plugin Chunk Tickets

Similar to Bukkit's plugin chunk ticket system, you can also add tickets to chunks. These will keep the chunks loaded and ticking until either you remove the ticket or the plugin shuts down (ie: reload or your server stops).

In this example, we can add a ticket to keep the chunk at the player loaded.

public void addTicket(Player player) {
    // Get the Bukkit chunk at the player
    Chunk chunk = player.getLocation().getChunk();
    // Grab the virtual chunk related to this chunk
    VirtualChunk virtualChunk = tileManager.getChunk(chunk);
    // Add a ticket
    // this = a reference to your plugin
    virtualChunk.addPluginChunkTicket(this);
}

You can also remove a ticket

public void removeTicket(Player player) {
    // Get the Bukkit chunk at the player
    Chunk chunk = player.getLocation().getChunk();
    // Grab the virtual chunk related to this chunk
    VirtualChunk virtualChunk = tileManager.getChunk(chunk);
    // Remove a ticket
    // this = a reference to your plugin
    virtualChunk.removePluginChunkTicket(this);
}

Many of the methods in this class are used mainly for internal use, so please be careful when using these methods.

Clone this wiki locally