API reference Obsidian.API.Blocks
IBlockBehavior interface
What a plugin's block does: when a player uses or places it, when it or a neighbour changes, when it ticks and when entities touch it, and the redstone power it gives. Implement the methods the block needs; the others leave the block to Obsidian's default handling, which does nothing.
public interface IBlockBehavior
In Obsidian.API.
Remarks
The behaviour belongs to the plugin and is dropped when the plugin unloads, while the block stays registered (it stays in the world and keeps its states' ids), so keep state in the block's state or the plugin, not here. Every method runs as a call into the plugin, and none runs once the plugin is unloading.
The hooks given an IBlockLevel (placement, changes, updates and ticks) run synchronously while the level's block updates wait for them, like vanilla's: keep them short, and change blocks through that level, not through ILevel. Updates they cause run after them, in vanilla's order.
Methods
BreakAsync(BlockBreakContext)
ValueTask BreakAsync(BlockBreakContext context);Runs before a player breaks this block. Set IsCancelled to keep it, for example after removing one part. The hit comes from the server's outline raycast, since vanilla's break packet carries no hit location. Runs on the level tick, in turn with block entity callbacks and the resulting break transaction.
EntityInsideAsync(EntityBlockContext)
ValueTask EntityInsideAsync(EntityBlockContext context);Called each tick an entity is inside the block (its box overlaps the block's cube), like vanilla's entityInside.
GetAnalogOutput(SignalContext)
int GetAnalogOutput(SignalContext context);The power, from 0 to 15, a comparator facing away from the block reads from it, like vanilla's getAnalogOutputSignal: how full a container is, say. When it changes other than with the block's state, tell comparators with IBlockLevel.UpdateAnalogOutput.
GetDirectSignal(SignalContext)
int GetDirectSignal(SignalContext context);The strong redstone power the block gives the neighbour asking, which also powers through that neighbour when it's a conductor, like vanilla's getDirectSignal. Tell the neighbours of that neighbour too when it changes.
GetItemAccess(ItemAccessContext)
IItemAccess GetItemAccess(ItemAccessContext context);The block's items as another block reaches them through ItemAccessContext.Side, for a block that holds items without a block entity (like vanilla's composter), or that answers for its block entity. Null, the default, leaves it to the block entity (see IItemAccessProvider).
Remarks
The server calls the access it returns inside calls into the plugin, from any thread: make it thread-safe.
GetSignal(SignalContext)
int GetSignal(SignalContext context);The weak redstone power the block gives the neighbour asking, from 0 to 15, like vanilla's getSignal (see ISignalReader). Runs whenever a neighbour reads its power, so keep it a quick read of the state; when it changes, tell the neighbours with IBlockLevel.UpdateNeighbors.
GetStateForPlacement(BlockPlaceContext)
IBlock GetStateForPlacement(BlockPlaceContext context);The state a player places the block in, like vanilla's getStateForPlacement: from where they clicked and where they look, say a facing property from BlockPlaceContext.HorizontalDirection.
Returns
The state to place, or null to not place the block (the player keeps the item).
HasAnalogOutput(IBlock)
bool HasAnalogOutput(IBlock state);Whether comparators read the block's IBlockBehavior.GetAnalogOutput, like vanilla's hasAnalogOutputSignal.
IsSignalSource(IBlock)
bool IsSignalSource(IBlock state);Whether the block gives redstone power, like vanilla's isSignalSource: redstone dust connects to it from every side, and comparators read it from their sides. The same for every state of the block.
NeighborChanged(NeighborChangedContext)
void NeighborChanged(NeighborChangedContext context);Called when a neighbour changed with neighbour updates, or something else updated the block's neighbours, like vanilla's neighborChanged: the place to react to power or to a block it needs disappearing.
OnPlaced(BlockPlacedContext)
void OnPlaced(BlockPlacedContext context);Called when the block is placed or changes state, like vanilla's onPlace, unless the change skips it (BlockUpdateFlags.SkipOnPlace). BlockPlacedContext.OldState tells which: another block, or another state of this one.
OnRemoved(BlockRemovedContext)
void OnRemoved(BlockRemovedContext context);Called when another block replaces the block with neighbour updates (BlockUpdateFlags.Neighbors), like vanilla's affectNeighborsAfterRemoval; the new block is already there.
RandomTick(BlockContext)
void RandomTick(BlockContext context);Runs a random tick, like vanilla's randomTick, for a block registered with BlockProperties.RandomlyTicks: the game rule's number of blocks a tick in each section near players, about once every 68 seconds for each block at the default speed.
SteppedOnAsync(EntityBlockContext)
ValueTask SteppedOnAsync(EntityBlockContext context);Called each tick an entity stands on the block, like vanilla's stepOn.
Tick(BlockContext)
void Tick(BlockContext context);Runs a tick scheduled with IBlockLevel.ScheduleTick or ILevel.ScheduleBlockTick, like vanilla's tick, while the block is still there.
UpdateShape(ShapeUpdateContext)
IBlock UpdateShape(ShapeUpdateContext context);The block's state after its neighbour in ShapeUpdateContext.Direction changed, like vanilla's updateShape: a fence connecting to it, or a torch losing its support. Returning air queues destruction with loot on the next level tick, leaving the fluid it held. Replacing the block or its block entity before then cancels destruction. Player break hooks and tool checks do not run.
Returns
The new state, or BlockContext.State to keep it.
UseAsync(BlockUseContext)
ValueTask<bool> UseAsync(BlockUseContext context);Called when a player uses the block (right-clicks it without sneaking), before the item in their hand is used.
Returns
Whether the behaviour handled the use, which skips using the item.