Skip to main content
Version: Minecraft 26.2

World

World view​

A WorldView is one dimension. Use the view that a callback (event, action, tick) receives only during that call.

AreaMethods
Basicsdimension(), isClientSide(), gameTime(), players()
BlocksblockAt(pos), setBlock(pos, block), stateAt(pos), setProperty(pos, property, value), blockEntityAt(pos), emittedLight(pos)
EntitiesspawnEntity(type, x, y, z), entitiesNear(x, y, z, radius)
EffectsplaySound(pos, sound, volume, pitch), spawnParticles(particle, x, y, z, count, spread)
Game rulesgameRule(key), setGameRule(key, value)
Storagestorage(id), storage(id, options)
Schedulingschedule(ticks, task)
Chunks and biomessetChunkForced(x, z, forced), isChunkLoaded(x, z), biomeAt(pos), naturalSpawns(pos, category)
DimensionsotherDimension(id)
Tagstags(), isBlockIn(pos, tag) (Tags)
world.setBlock(pos, ResourceId.minecraft("stone"));
world.spawnEntity(ResourceId.minecraft("pig"), x, y, z);
Optional<WorldView> pocket = world.otherDimension(ResourceId.of("my_mod", "pocket"));

Create a BlockPos with BlockPos.of(x, y, z) and move it with offset, above, and below.

World storage​

mod.events().register(WorldEvents.READY, world -> {
StoredData stats = world.storage(ResourceId.of("my_mod", "stats")); // per dimension, saved with the world
stats.data().putInt("loads", stats.data().getInt("loads", 0) + 1);
stats.markChanged();
});

DataTree​

StoredData.data(), block entity data, and entity data are all a DataTree.

MethodMeaning
getInt/putInt, getLong/putLong, getDouble/putDouble, getBoolean/putBoolean, getString/putStringRead a value (you give a default) and write a value. put… can be chained
getBytes/putBytesByte array
child(key), findChild(key)Subtree (creates it if missing / returns an Optional)
has, remove, keys, clear, copyKey management

Scheduling tasks​

world.schedule(20, () -> world.setBlock(pos, ResourceId.minecraft("stone"))); // after 20 ticks, on the server thread
world.schedule(20, () -> world.playSound(pos, ResourceId.minecraft("block.note_block.bell"), 1, 1));
  • Scheduled tasks disappear when the server stops. They are not saved.
  • If a scheduled task throws an exception, Poly Mod Loader logs POLY-SCHEDULE-001 and keeps running the next tasks.

Force-loading chunks​

world.setChunkForced(chunkX, chunkZ, true); // same as /forceload, saved with the world
world.isChunkLoaded(chunkX, chunkZ);
world.biomeAt(pos);
mod.events().register(WorldEvents.CHUNK_LOADED, (w, chunkX, chunkZ) -> { /* … */ }); // CHUNK_UNLOADED exists too

World events​

On the server, each dimension goes through LOADED → READY → SAVING (on every save) → UNLOADED per server start. LOADED, SAVING, and UNLOADED share one listener type, WorldListener (world -> …).

mod.events().register(WorldEvents.LOADED, world -> { /* every dimension exists, before the first tick */ });
mod.events().register(WorldEvents.SAVING, world -> { /* changes made now are saved with the world */ });
mod.events().register(WorldEvents.UNLOADED, world -> { /* the last moment to read it while stopping */ });
  • SAVING fires before autosaves, /save-all, and the save while stopping, before chunks and level data are written.
  • Changes made in UNLOADED are not saved any more.

Timings, CHUNK_LOADED, CHUNK_UNLOADED, and the other events are listed in Events.

Buy me a coffee