Skip to content
ZERNYTH.

World API

Server.getWorlds() returns the current level as a World, with its dimensions and entities.

package dev.example;

import dev.zernyth.api.plugin.JavaPlugin;
import dev.zernyth.api.world.BlockPosition;

public final class WorldPlugin extends JavaPlugin {
    @Override
    public void onEnable() {
        for (var world : getServer().getWorlds()) {
            for (var dimension : world.getDimensions()) {
                dimension.getBlock(new BlockPosition(0, 64, 0)).ifPresent(block -> {
                    getLogger().info(dimension.getIdentifier() + ": " + block.getType());
                });
            }
        }
    }
}

Chunks

Dimension.getBlock returns an empty Optional when the chunk is not loaded. A later access fails if the chunk has been unloaded since. Reads, writes, state updates, teleports and spawning never load chunks implicitly.

Changing blocks

Block.setType and Block.setData change a block directly. setData has an explicit physics flag. captureState returns a BlockState you can edit and apply with update. Close it with try-with-resources.

Was this page helpful?