API reference Obsidian.API.World
ILevel interface
public interface ILevel : IAsyncDisposable, ISignalReader
In Obsidian.API.
Remarks
Its redstone signals (see ISignalReader) are read as its blocks are, waiting for the block updates running at the time.
Properties
int ChunksToGenCount { get; }int DayTime { get; set; }GameMode DefaultGamemode { get; }DimensionName
string DimensionName { get; }The level's name, which clients know it by: its dimension's identifier, like minecraft:the_nether.
DimensionType
DimensionCodec DimensionType { get; }The level's dimension type. Vanilla's dimensions are named after theirs; plugins' dimensions may use any.
IEventDispatcher EventDispatcher { get; }string FolderPath { get; }LevelData LevelData { get; }string LevelDataFilePath { get; }bool Loaded { get; }int LoadedChunkCount { get; }string Name { get; }IPacketBroadcaster PacketBroadcaster { get; }ConcurrentDictionary<Guid, IPlayer> Players { get; }int RegionCount { get; }string Seed { get; }long Time { get; set; }Methods
AddChunkTicket(int, int, int, bool)
IDisposable AddChunkTicket(int chunkX, int chunkZ, int radius = 0, bool ticking = true);Keeps a square of chunks loaded, optionally ticking without players. Radius is in chunks (0 means one), at most 8. Ticking tickets also load a one-chunk border for block and fluid updates. Loading and generation start on the next chunk-management pass; the handle does not mean the chunks are ready yet.
Remarks
Dispose to release. Tickets acquired by plugin code are automatically released when that plugin unloads. Tickets are not saved. Each level allows at most 256 handles and 1024 distinct retained chunks, including borders. A loaded-only ticket does not prevent simulation caused by a player or another ticket.
AddTicker(Func<ValueTask>)
IDisposable AddTicker(Func<ValueTask> tick);Runs tick once every tick of the level, like NeoForge's post level tick event: for what spans many block entities, such as a network that ticks once rather than once per member. It runs on the level's tick, after the block entities ticked and before their changes are saved and sent, so it may use the level's block entities as their own ticks do. It runs whether or not any chunk ticks.
Remarks
Dispose the handle to stop it. Tickers run in the order they were added, from the next tick on (or this one if added before the level's tickers run). A plugin's run inside calls into the plugin, and are removed when it unloads. A tick that throws is logged and the ticker keeps running.
DestroyBlock(Vector, bool, IEntity)
bool DestroyBlock(Vector position, bool dropItems, IEntity breaker = null);Requests destruction of a loaded block on the next level tick, with optional loot and its fluid left behind. Returns whether it was queued. A changed block or block entity cancels the request before it runs. Player break hooks and tool checks do not run. Container removal still spills ordinary contents.
ValueTask<bool> DestroyEntityAsync(IEntity entity);DoWorldTickAsync()
Task DoWorldTickAsync();Ticks the level once. The server does, every tick; a plugin rarely needs to.
FlushRegionsAsync()
Task FlushRegionsAsync();Saves the level's regions: its chunks and their entities.
Remarks
It waits for the level to be between ticks.
GenerateAsync(CancellationToken)
Task GenerateAsync(CancellationToken cancellationToken = null);Generates a new level's chunks around its spawn. Cancelling stops starting new chunks and throws OperationCanceledException; chunks already generating finish in the background.
ValueTask<IBlock> GetBlockAsync(int x, int y, int z);ValueTask<IBlock> GetBlockAsync(Vector location);ValueTask<IBlockEntity> GetBlockEntityAsync(int x, int y, int z);ValueTask<IBlockEntity> GetBlockEntityAsync(Vector blockPosition);GetChunkAsync(int, int, bool)
ValueTask<IChunk> GetChunkAsync(int x, int z, bool scheduleGeneration = true);Gets a Chunk from a Region. If the Chunk doesn't exist, it will be scheduled for generation unless scheduleGeneration is false.
Parameters
x- The chunk's X coordinate.
z- The chunk's Z coordinate.
scheduleGeneration- Whether to enqueue a job to generate the chunk if it doesn't exist and return null. When set to false, a partial Chunk is returned.
Returns
Null if the region or chunk doesn't exist yet. Otherwise the full chunk or a partial chunk.
GetChunkAsync(Vector, bool)
ValueTask<IChunk> GetChunkAsync(Vector worldLocation, bool scheduleGeneration = true);Gets a Chunk from a Region. If the Chunk doesn't exist, it will be scheduled for generation unless scheduleGeneration is false.
Parameters
worldLocation- The chunk's coordinates; only X and Z are used.
scheduleGeneration- Whether to enqueue a job to generate the chunk if it doesn't exist and return null. When set to false, a partial Chunk is returned.
Returns
Null if the region or chunk doesn't exist yet. Otherwise the full chunk or a partial chunk.
IEnumerable<IEntity> GetEntitiesInRange(VectorD location, float distance);GetItemAccess(Vector, BlockFace?)
IItemAccess GetItemAccess(Vector position, BlockFace? side);The items of the block at position as another block reaches them through its side face (or from no particular side when null), like NeoForge's item handler capability: a plugin block's own (see IBlockBehavior.GetItemAccess), else its block entity's (see IItemAccessProvider), with both halves of a double chest as one. Null when it has none from that side, or its chunk isn't loaded and complete. Synchronous: it never loads a chunk.
GetLoadedBlock(Vector)
IBlock GetLoadedBlock(Vector position);The block state at position if its chunk is loaded and complete, without loading or generating anything. Null otherwise; void air outside the build range of a loaded chunk.
Remarks
Safe to call from any thread: reads published chunk sections, like ILevel.GetBlockAsync. A read racing an edit may see the state before or after it; several reads aren't an atomic snapshot. It does not wait for block updates or acquire the level's tick lock. Inside a block hook, use IBlockLevel.GetBlock, whose reads stay stable until the hook returns.
GetLoadedBlockEntity(Vector)
IBlockEntity GetLoadedBlockEntity(Vector position);The block entity at position if its chunk is loaded and complete, without loading or generating anything, like IBlockLevel.GetBlockEntity: for following a cable or network across block entities from a tick. Null otherwise, or once the block entity was removed or its chunk unloaded.
Remarks
ILevel.GetBlockEntityAsync, by contrast, loads the chunk from disk, and adds an ungenerated one where none was saved. Use what this returns on the level's tick, as block entity ticks and tickers do.
IEntitySpawner GetNewEntitySpawner();IEnumerable<IEntity> GetNonPlayerEntitiesInRange(VectorD location, float distance);IEnumerable<IPlayer> GetPlayersInChunkRange(Vector worldPosition);IEnumerable<IPlayer> GetPlayersInRange(VectorD location, float distance);GetSavedData<TValue>(SavedDataType<TValue>, Func<TValue>, SavedDataScope)
SavedData<TValue> GetSavedData<TValue>(SavedDataType<TValue> type, Func<TValue> create, SavedDataScope scope = 0);Gets the load's live instance, reading its file lazily. World scope shares across dimensions. Access plugin objects on the level tick or synchronize them yourself; call MarkDirty to publish changes for saving.
ValueTask<int?> GetWorldSurfaceHeightAsync(int x, int z);Initialize(DimensionCodec)
void Initialize(DimensionCodec codec);Initializes the level with the given dimension codec. This is only used when a new world is being created, otherwise LoadAsync is used.
Parameters
codec- The dimension codec to use for initialization.
IsFaceSturdy(Vector, BlockFace, SupportType)
bool IsFaceSturdy(Vector position, BlockFace face, SupportType support = 0);Whether the block's face supports the requested area, like vanilla's BlockState.isFaceSturdy. Reads state shapes and published block entity shapes synchronously, without loading or generating chunks. Returns false outside the build range or complete loaded chunks. Use on the level tick or during block hooks.
Task<bool> LoadAsync(DimensionCodec codec);IEnumerable<IPlayer> PlayersInRange(Vector location);SaveAsync()
Task SaveAsync();Saves the level's state: for a world, its level data and maps; for a dimension, its regions and its state.
Remarks
A dimension's save waits for it to be between ticks, to save its regions; a world's writes its level data while the levels tick, after any save of the world under way, which may itself be waiting for them.
ScheduleBlockTick(Vector, IBlock, int, TickPriority)
void ScheduleBlockTick(Vector location, IBlock block, int delay, TickPriority priority = 0);Schedules a tick of block's block at location in delay game ticks, unless one is scheduled there already, like vanilla's scheduleTick. It runs if that block is still there then (a plugin block's IBlockBehavior.Tick), and is saved with the chunk as vanilla's block_ticks. Ignored where the chunk isn't loaded and complete.
ValueTask SetBlockAsync(int x, int y, int z, IBlock block);ValueTask SetBlockAsync(int x, int y, int z, IBlock block, bool doBlockUpdate);ValueTask SetBlockAsync(Vector location, IBlock block);SetBlockAsync(Vector, IBlock, BlockUpdateFlags)
ValueTask SetBlockAsync(Vector location, IBlock block, BlockUpdateFlags flags);Changes the block at location, with the side effects flags ask for, like vanilla's setBlock: BlockUpdateFlags.All is what a player placing a block does, and what doBlockUpdate asks for; without it, a change has no side effects besides players seeing it.
ValueTask SetBlockAsync(Vector location, IBlock block, bool doBlockUpdate);ValueTask SetBlockEntity(int x, int y, int z, IBlockEntity tileEntityData);ValueTask SetBlockEntity(Vector blockPosition, IBlockEntity tileEntityData);ValueTask SetBlockUntrackedAsync(int x, int y, int z, IBlock block, bool doBlockUpdate = false);ValueTask SetBlockUntrackedAsync(Vector location, IBlock block, bool doBlockUpdate = false);IEntity SpawnEntity(IEntity entity);SpawnEntity(VectorD, EntityDefinition, VectorD, IEntity)
IEntity SpawnEntity(VectorD position, EntityDefinition definition, VectorD motion = null, IEntity owner = null);Spawns an entity of a plugin's entity type, moving at motion blocks per tick; a projectile remembers owner as what shot it.
IEntity SpawnEntity(VectorD position, EntityType type);void SpawnExperienceOrbs(VectorD position, short count);IEntity SpawnFallingBlock(VectorD position, IBlock block);SpawnItem(VectorD, ItemStack)
bool SpawnItem(VectorD position, ItemStack stack);Spawns a host-owned item entity from a detached copy of stack, independent of plugin lifetime. Returns false for an empty stack or a failed insertion. This direct helper does not apply creative or block-drop rules.
SpawnParticles(ParticleData, VectorD, int, VectorF, float, bool)
void SpawnParticles(ParticleData particle, VectorD position, int count = 1, VectorF spread = null, float speed = 0f, bool force = false);Shows particles to the players within 32 blocks of position, like vanilla's /particle: with a count of 0, one particle moving along spread times speed; otherwise count particles scattered around the position by up to about spread on each axis, moving randomly at up to about speed.
Parameters
particle- The particle: a plugin's
ParticleDefinition, or vanilla's particle data. position- Where the particles appear.
count- How many particles appear.
spread- How far they're scattered on each axis, or the direction of a single particle.
speed- How fast they move.
force- Whether players up to 512 blocks away see them too, whatever their particle setting.
bool TryAddEntity(IEntity entity);bool TryAddPlayer(IPlayer player);TryLightPortalAsync(PortalType, Vector)
ValueTask<bool> TryLightPortalAsync(PortalType type, Vector position);Lights an empty registered frame containing position (an interior block). Item/block callbacks may call this to implement their own ignition rules.
bool TryRemovePlayer(IPlayer player);UpdateNeighbors(Vector, IBlock)
void UpdateNeighbors(Vector position, IBlock source);Tells the six neighbours of position that it changed, from source, like vanilla's updateNeighborsAt and IBlockLevel.UpdateNeighbors: redstone components, comparators and plugin blocks' IBlockBehavior.NeighborChanged react as to a block change. For a block entity whose power changed, say, from its tick or a level ticker.
Remarks
The updates run at once, under the level's tick lock, like those of a block change: from any thread, waiting for the block updates running at the time, and within a block hook, after the hook's own. Don't call it while holding a lock that block hooks may wait on, such as a window's. Neighbours outside the complete loaded chunks aren't told.