Skip to content

API reference Obsidian.API.Blocks

IBlockLevel interface

The level as a block's hooks see it, like the level vanilla passes its blocks: reads and changes blocks at once, with the level's block updates held for the hook, so what it reads stays as it read it until it returns.

public interface IBlockLevel : ISignalReader

In Obsidian.API.

Remarks

Only use it during the hook it's given to, and use it rather than ILevel's asynchronous methods, which wait for the hook to return. It reaches the level's complete loaded chunks: others read as void air and can't be changed. Its redstone signals (see ISignalReader) are read as the blocks are now.

Properties

Level

ILevel Level { get; }

The level.

Random

IRandomSource Random { get; }

The level's random, which vanilla's blocks tick with.

Methods

DestroyBlock(Vector, bool, IEntity)

bool DestroyBlock(Vector position, bool dropItems, IEntity breaker = null);

Requests destruction of a loaded block, optionally with loot, leaving its fluid. The host queues the whole transaction to the level tick to collect block entity components safely. Returns whether it was queued; replacing the block or its block entity before execution cancels it. Does not call the player break hook.

GetBlock(Vector)

IBlock GetBlock(Vector position);

The block at position: void air outside the build range or the loaded chunks.

GetBlockEntity(Vector)

IBlockEntity GetBlockEntity(Vector position);

The block entity at position, like vanilla's getBlockEntity: what a block's hooks read their own data from, a comparator output from a counter, say. Null outside the loaded chunks.

Remarks

Hooks can run while block entities tick (a player's change runs on its own thread), so read what is safe to read so, like a field the block entity writes whole, and change the block entity on its own tick.

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, like ILevel.GetItemAccess, for use during the hook.

Remarks

The level's block updates wait while the hook runs, so here a container that a player's click or the server is using at that moment, or that still waits for its loot table, takes and gives nothing for that call (its loot is rolled on the level's next tick, outside the hook).

HasScheduledTick(Vector, IBlock)

bool HasScheduledTick(Vector position, IBlock block);

Whether a tick of block's block is scheduled at position.

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 without loading chunks or calling shape providers. Returns false outside the build range or complete loaded chunks.

RemoveBlock(Vector)

bool RemoveBlock(Vector position);

Removes the block at position, leaving the fluid it held (air, or water for a waterlogged block), with BlockUpdateFlags.All, like vanilla's removeBlock. It drops nothing.

Returns

Whether the block changed.

ScheduleTick(Vector, IBlock, int, TickPriority)

void ScheduleTick(Vector position, IBlock block, int delay, TickPriority priority = 0);

Schedules a tick of block's block at position in delay game ticks, unless one is scheduled there already, like vanilla's scheduleTick. It runs if that block is still there then.

SetBlock(Vector, IBlock, BlockUpdateFlags)

bool SetBlock(Vector position, IBlock block, BlockUpdateFlags flags = 3);

Changes the block at position, with the side effects flags ask for. The neighbour and shape updates it causes run after the current hook's, like vanilla's chained updates.

Returns

Whether the block changed.

SpawnItem(VectorD, ItemStack)

bool SpawnItem(VectorD position, ItemStack stack);

Spawns a host-owned item entity from a detached copy; it survives plugin unloading.

UpdateAnalogOutput(Vector)

void UpdateAnalogOutput(Vector position);

Tells the comparators reading the block at position that its analog output (see IBlockBehavior.GetAnalogOutput) changed, like vanilla's updateNeighbourForOutputSignal: those beside it and those behind a conductor beside it. A block change with neighbour updates does this for a block with an analog output already.

UpdateNeighbors(Vector, IBlock)

void UpdateNeighbors(Vector position, IBlock source);

Tells the six neighbours of position that it changed, from source, like vanilla's updateNeighborsAt.

On this page