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
identifier
string
options?
HarnessOptions = {}
Returns
FamilyHarness
Properties
dimension
readonlydimension:VoxelDimension
Defined in: block-behaviors/src/harness.ts:114
The dimension the events report, which is where the blocks live.
family
readonlyfamily:BlockFamily
Defined in: block-behaviors/src/harness.ts:119
identifier
readonlyidentifier:string
Defined in: block-behaviors/src/harness.ts:120
world
readonlyworld: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
Returns
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
options?
What the breaker held, which decides silk touch and shears, and who broke it. Absent brokenBy is TEST_PLAYER.
brokenBy?
itemStack?
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
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
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
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?
itemStack?
player?
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
face
"down" | "up" | "north" | "south" | "west" | "east"
neighbor?
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
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
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
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
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
state
string
previousValue
newValue
Returns
void
stepOn()
stepOn(
position,entity?):void
Defined in: block-behaviors/src/harness.ts:239
Dispatches onStepOn.
Parameters
position
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
tick?
number = 0
Returns
void