Skip to content

API reference / @jsprismarine/block-behaviors / FamilyHarness

Class: FamilyHarness ​

Defined in: block-behaviors/src/harness.ts:110

One family bound to one block identifier, with a hook dispatcher per hook.

Constructors ​

Constructor ​

new FamilyHarness(family, identifier, options?): FamilyHarness

Defined in: block-behaviors/src/harness.ts:118

Parameters ​

family ​

BlockFamily

identifier ​

string

options? ​

HarnessOptions = {}

Returns ​

FamilyHarness

Properties ​

dimension ​

readonly dimension: VoxelDimension

Defined in: block-behaviors/src/harness.ts:114

The dimension the events report, which is where the blocks live.


family ​

readonly family: BlockFamily

Defined in: block-behaviors/src/harness.ts:119


identifier ​

readonly identifier: string

Defined in: block-behaviors/src/harness.ts:120


world ​

readonly world: VoxelWorld

Defined in: block-behaviors/src/harness.ts:112

The world the family acts on.

Methods ​

block() ​

block(position): HookBlock

Defined in: block-behaviors/src/harness.ts:137

The block at a position as the hooks see it.

Parameters ​

position ​

BlockPosition

Returns ​

HookBlock


breakBlock() ​

breakBlock(position, options?): void

Defined in: block-behaviors/src/harness.ts:176

Dispatches onBreak, with the block as it was before the break.

Parameters ​

position ​

BlockPosition

options? ​

What the breaker held, which decides silk touch and shears, and who broke it. Absent brokenBy is TEST_PLAYER.

brokenBy? ​

HookActor

itemStack? ​

HookItem

Returns ​

void


entityEvent() ​

entityEvent(position, name, entitySource?): void

Defined in: block-behaviors/src/harness.ts:249

Dispatches a named entity event on the block.

Parameters ​

position ​

BlockPosition

name ​

string

entitySource? ​

HookActor = TEST_PLAYER

Returns ​

void


fallOn() ​

fallOn(position, fallDistance, entity?): void

Defined in: block-behaviors/src/harness.ts:244

Dispatches onEntityFallOn.

Parameters ​

position ​

BlockPosition

fallDistance ​

number

entity? ​

HookActor = TEST_PLAYER

Returns ​

void


implements() ​

implements(hook): boolean

Defined in: block-behaviors/src/harness.ts:132

Whether the family implements a hook, so a test can tell silence from absence.

Parameters ​

hook ​

"onPlace" | "onBreak" | "onNeighborChanged" | "onRandomTick" | "onTick" | "onPlayerInteract" | "onStepOn" | "onEntityFallOn" | "onEntity" | "onRedstoneUpdate" | "onBlockStateChange"

Returns ​

boolean


interact() ​

interact(position, options?): boolean | BlockInteractResult | undefined

Defined in: block-behaviors/src/harness.ts:220

Dispatches onPlayerInteract and returns whether the family consumed it.

Parameters ​

position ​

BlockPosition

options? ​

itemStack is what the player held, which decides waxing, scraping, filling and lighting; absent is a bare hand.

face? ​

"down" | "up" | "north" | "south" | "west" | "east"

faceLocation? ​

FaceLocation

itemStack? ​

HookItem

player? ​

HookActor

Returns ​

boolean | BlockInteractResult | undefined


neighborChanged() ​

neighborChanged(position, face, neighbor?): void

Defined in: block-behaviors/src/harness.ts:191

Dispatches onNeighborChanged for the neighbor on a face.

Parameters ​

position ​

BlockPosition

face ​

"down" | "up" | "north" | "south" | "west" | "east"

neighbor? ​

HookBlock

Returns ​

void


place() ​

place(position, options?): void

Defined in: block-behaviors/src/harness.ts:150

Dispatches onPlace for the block now at the position.

Parameters ​

position ​

BlockPosition

options? ​

PlaceOptions = {}

previous is what the placement overwrote, which a slab merge and a candle stack read. Leaving placedBy out uses TEST_PLAYER; passing it as undefined is a world placement. face and faceLocation are the click a pillar, a slab and a pair of stairs read; naming a face with no location clicks its middle.

Returns ​

void


randomTick() ​

randomTick(position, tick?): void

Defined in: block-behaviors/src/harness.ts:200

Dispatches onRandomTick.

Parameters ​

position ​

BlockPosition

tick? ​

number = 0

Returns ​

void


randomTicks() ​

randomTicks(position, times): void

Defined in: block-behaviors/src/harness.ts:205

Dispatches onRandomTick a number of times, which is how a growth rule is driven.

Parameters ​

position ​

BlockPosition

times ​

number

Returns ​

void


redstone() ​

redstone(position, power): void

Defined in: block-behaviors/src/harness.ts:254

Dispatches onRedstoneUpdate with the power now reaching the block.

Parameters ​

position ​

BlockPosition

power ​

number

Returns ​

void


stateChange() ​

stateChange(position, state, previousValue, newValue): void

Defined in: block-behaviors/src/harness.ts:259

Dispatches onBlockStateChange for one state that changed in place.

Parameters ​

position ​

BlockPosition

state ​

string

previousValue ​

BlockStateValue

newValue ​

BlockStateValue

Returns ​

void


stepOn() ​

stepOn(position, entity?): void

Defined in: block-behaviors/src/harness.ts:239

Dispatches onStepOn.

Parameters ​

position ​

BlockPosition

entity? ​

HookActor = TEST_PLAYER

Returns ​

void


tick() ​

tick(position, tick?): void

Defined in: block-behaviors/src/harness.ts:210

Dispatches onTick, which is the scheduled tick a behavior asked for.

Parameters ​

position ​

BlockPosition

tick? ​

number = 0

Returns ​

void