Skip to content

API reference / @jsprismarine/entity-brains / TestWorld

Class: TestWorld ​

Defined in: testWorld.ts:263

A BrainWorld backed by plain data.

Implements ​

Constructors ​

Constructor ​

new TestWorld(options?): TestWorld

Defined in: testWorld.ts:301

Parameters ​

options? ​

TestWorldOptions = {}

Returns ​

TestWorld

Properties ​

blocks ​

readonly blocks: Map<string, string>

Defined in: testWorld.ts:272

Block ids by x,y,z. Anything unset is minecraft:air.


blockTags ​

readonly blockTags: Map<string, Set<string>>

Defined in: testWorld.ts:274

Block tags by x,y,z.


canBreed ​

canBreed: boolean = false

Defined in: testWorld.ts:559

Whether the host says two villagers may breed.


dayTimeTicks ​

dayTimeTicks: number

Defined in: testWorld.ts:267


dimension ​

readonly dimension: string

Defined in: testWorld.ts:264

The dimension id, used to qualify a GlobalPos.

Implementation of ​

BrainWorld.dimension


entities ​

readonly entities: TestEntity[] = []

Defined in: testWorld.ts:269

Every entity in the world, including the mobs.


farmSpot ​

farmSpot: BlockPos | undefined

Defined in: testWorld.ts:553

Where the farmer's next piece of farming is, which a test sets.


gameEvents ​

readonly gameEvents: object[] = []

Defined in: testWorld.ts:279

Every emitGameEvent call, in order.

event ​

event: string

pos ​

pos: Vec3

source? ​

optional source?: BrainEntity


hero ​

hero: boolean = false

Defined in: testWorld.ts:557

Whether the host counts a player as a hero.


items ​

readonly items: TestItemEntity[] = []

Defined in: testWorld.ts:270


nextRandomPos ​

nextRandomPos: Vec3 | undefined = undefined

Defined in: testWorld.ts:292

What TestWorld.randomPos returns. A test sets it to make a wander deterministic; undefined means the draw found nothing, which is a real outcome in Java too.


pois ​

readonly pois: (PoiRecord & object)[] = []

Defined in: testWorld.ts:275


snifferSeedDrops ​

readonly snifferSeedDrops: string[] = []

Defined in: testWorld.ts:281

Sniffer seed-drop callbacks, in the order they fired.


sonicBooms ​

readonly sonicBooms: object[] = []

Defined in: testWorld.ts:283

Warden sonic-boom callbacks, in the order they fired.

source ​

source: string

target ​

target: string


sounds ​

readonly sounds: object[] = []

Defined in: testWorld.ts:277

Every playSound call, in order.

pos ​

pos: Vec3

sound ​

sound: string


time ​

time: number

Defined in: testWorld.ts:266

Advance with TestWorld.advance.


villagerRaidEffects ​

readonly villagerRaidEffects: object[] = []

Defined in: testWorld.ts:285

Villager raid effects, in the order the host received them.

body ​

body: string

effect ​

effect: VillagerRaidEffect


villagerRestocks ​

readonly villagerRestocks: string[] = []

Defined in: testWorld.ts:287

Villagers that were asked to restock, in order.


villagerShown ​

readonly villagerShown: boolean[] = []

Defined in: testWorld.ts:573

What a villager was showing, in order; undefined is an emptied hand.


villagerTasks ​

readonly villagerTasks: object[] = []

Defined in: testWorld.ts:555

Every villager task the host was asked to carry out, in order.

body ​

body: string

target? ​

optional target?: BlockPos | BrainEntity

task ​

task: VillagerTask

Methods ​

addPoi() ​

addPoi(pos, type): void

Defined in: testWorld.ts:340

Adds a point of interest with a free ticket.

Parameters ​

pos ​

BlockPos

type ​

string

Returns ​

void


advance() ​

advance(ticks?): void

Defined in: testWorld.ts:345

Advances the game time, and the time of day with it.

Parameters ​

ticks? ​

number = 1

Returns ​

void


blockAt() ​

blockAt(pos): string

Defined in: testWorld.ts:424

The block a test placed at the position, or minecraft:air.

Parameters ​

pos ​

BlockPos

Returns ​

string

Implementation of ​

BrainWorld.blockAt


blockTagsAt() ​

blockTagsAt(pos): ReadonlySet<string>

Defined in: testWorld.ts:435

The tags a test placed at the position, or an empty set.

Parameters ​

pos ​

BlockPos

Returns ​

ReadonlySet<string>

Implementation of ​

BrainWorld.blockTagsAt


canSee() ​

canSee(body, target): boolean

Defined in: testWorld.ts:404

Defers to the line-of-sight predicate a test passed in, which is true for everything by default.

Parameters ​

body ​

BrainEntity

target ​

BrainEntity

Returns ​

boolean

Implementation of ​

BrainWorld.canSee


canStandAt() ​

canStandAt(position): boolean

Defined in: testWorld.ts:454

Treats air over a placed block as an empty, supported standing position.

Parameters ​

position ​

BlockPos

Returns ​

boolean

Implementation of ​

BrainWorld.canStandAt


claimPoi() ​

claimPoi(pos, claimant): boolean

Defined in: testWorld.ts:493

Takes the ticket at the position, and reports false when there is no record or no space left.

Parameters ​

pos ​

BlockPos

claimant ​

BrainEntity

Returns ​

boolean

Implementation of ​

BrainWorld.claimPoi


dayTime() ​

dayTime(): number

Defined in: testWorld.ts:356

Time of day in ticks, wrapped at 24000.

Returns ​

number

Implementation of ​

BrainWorld.dayTime


drop() ​

drop(item, position, count?): TestItemEntity

Defined in: testWorld.ts:327

Drops an item stack.

Parameters ​

item ​

BrainItem

position ​

Vec3

count? ​

number = 1

Returns ​

TestItemEntity


dropSnifferSeed() ​

dropSnifferSeed(body): void

Defined in: testWorld.ts:528

Records the point at which the sniffer's host would roll its loot table.

Parameters ​

body ​

BrainMob

Returns ​

void

Implementation of ​

BrainWorld.dropSnifferSeed


emitGameEvent() ​

emitGameEvent(event, pos, source?): void

Defined in: testWorld.ts:518

Records the vibration in gameEvents, which is what the warden's sensor reads in a test.

Parameters ​

event ​

string

pos ​

Vec3

source? ​

BrainEntity

Returns ​

void

Implementation of ​

BrainWorld.emitGameEvent


findBlock() ​

findBlock(center, xzRange, yRange, test): BlockPos | undefined

Defined in: testWorld.ts:440

The matching block nearest the center by Manhattan distance, searched over the box a test filled.

Parameters ​

center ​

BlockPos

xzRange ​

number

yRange ​

number

test ​

(block, tags, position) => boolean

Returns ​

BlockPos | undefined

Implementation of ​

BrainWorld.findBlock


gameTime() ​

gameTime(): number

Defined in: testWorld.ts:351

Ticks since the world was built, which TestWorld.advance moves.

Returns ​

number

Implementation of ​

BrainWorld.gameTime


isAttackable() ​

isAttackable(body, target): boolean

Defined in: testWorld.ts:414

Targetable, and allowed by the attackable predicate a test passed in.

Parameters ​

body ​

BrainEntity

target ​

BrainEntity

Returns ​

boolean

Implementation of ​

BrainWorld.isAttackable


isTargetable() ​

isTargetable(body, target): boolean

Defined in: testWorld.ts:409

True for a living, non-spectator target the body can see.

Parameters ​

body ​

BrainEntity

target ​

BrainEntity

Returns ​

boolean

Implementation of ​

BrainWorld.isTargetable


isVillageHero() ​

isVillageHero(_player): boolean

Defined in: testWorld.ts:581

Returns TestWorld.hero.

Parameters ​

_player ​

BrainEntity

Returns ​

boolean

Implementation of ​

BrainWorld.isVillageHero


isWaterAt() ​

isWaterAt(pos): boolean

Defined in: testWorld.ts:429

Whether the block at a position carries Java's water fluid tag.

Parameters ​

pos ​

BlockPos

Returns ​

boolean

Implementation of ​

BrainWorld.isWaterAt


isWithinMeleeRange() ​

isWithinMeleeRange(body, target): boolean

Defined in: testWorld.ts:419

Compares the straight-line distance against the melee range a test set.

Parameters ​

body ​

BrainEntity

target ​

BrainEntity

Returns ​

boolean

Implementation of ​

BrainWorld.isWithinMeleeRange


itemEntitiesNear() ​

itemEntitiesNear(center, xzRange, yRange): readonly BrainItemEntity[]

Defined in: testWorld.ts:394

Item entities inside the box, which is how Java bounds an item search rather than by radius.

Parameters ​

center ​

Vec3

xzRange ​

number

yRange ​

number

Returns ​

readonly BrainItemEntity[]

Implementation of ​

BrainWorld.itemEntitiesNear


livingEntitiesNear() ​

livingEntitiesNear(center, radius, exclude, excludeDimensions?): readonly BrainEntity[]

Defined in: testWorld.ts:373

Every non-item entity whose box intersects the excluded entity's inflated box.

Parameters ​

center ​

Vec3

radius ​

number

exclude ​

BrainEntity

excludeDimensions? ​

EntityDimensions = ...

Returns ​

readonly BrainEntity[]

Implementation of ​

BrainWorld.livingEntitiesNear


place() ​

place(type, position, options?): TestEntity

Defined in: testWorld.ts:320

Places a non-mob entity, such as a player or a target.

Parameters ​

type ​

string

position ​

Vec3

options? ​

TestEntityOptions = {}

Returns ​

TestEntity


players() ​

players(): readonly BrainEntity[]

Defined in: testWorld.ts:389

Every entity a test spawned as minecraft:player, at any distance.

Returns ​

readonly BrainEntity[]

Implementation of ​

BrainWorld.players


playSound() ​

playSound(sound, pos): void

Defined in: testWorld.ts:513

Records the sound and where it played in sounds.

Parameters ​

sound ​

string

pos ​

Vec3

Returns ​

void

Implementation of ​

BrainWorld.playSound


pointsOfInterest() ​

pointsOfInterest(center, radius, type): readonly PoiRecord[]

Defined in: testWorld.ts:475

Matching points of interest inside the box, nearest first by horizontal distance.

Parameters ​

center ​

BlockPos

radius ​

number

type ​

(type) => boolean

Returns ​

readonly PoiRecord[]

Implementation of ​

BrainWorld.pointsOfInterest


random() ​

random(): number

Defined in: testWorld.ts:361

The next scripted draw. The last value repeats once the script runs out.

Returns ​

number

Implementation of ​

BrainWorld.random


randomInt() ​

randomInt(bound): number

Defined in: testWorld.ts:368

The next scripted draw scaled into [0, bound), and 0 when the bound is not positive.

Parameters ​

bound ​

number

Returns ​

number

Implementation of ​

BrainWorld.randomInt


randomPos() ​

randomPos(_body, _request): Vec3 | undefined

Defined in: testWorld.ts:470

The position a test parked in nextRandomPos, so a wander target is a fact of the test.

Parameters ​

_body ​

BrainEntity

_request ​

RandomPosRequest

Returns ​

Vec3 | undefined

Implementation of ​

BrainWorld.randomPos


releasePoi() ​

releasePoi(pos, _claimant): void

Defined in: testWorld.ts:504

Frees the ticket at the position. Releasing an unknown position does nothing.

Parameters ​

pos ​

BlockPos

_claimant ​

BrainEntity

Returns ​

void

Implementation of ​

BrainWorld.releasePoi


setBlock() ​

setBlock(pos, block, tags?): void

Defined in: testWorld.ts:334

Sets a block and, optionally, its tags.

Parameters ​

pos ​

BlockPos

block ​

string

tags? ​

readonly string[] = []

Returns ​

void


snifferDigPosition() ​

snifferDigPosition(body): BlockPos

Defined in: testWorld.ts:523

Uses the body's block as the stand-in dig target for brain-only tests.

Parameters ​

body ​

BrainMob

Returns ​

BlockPos

Implementation of ​

BrainWorld.snifferDigPosition


sonicBoom() ​

sonicBoom(body, target): void

Defined in: testWorld.ts:533

Records a sonic boom for tests; the data-driven runtime applies its real damage.

Parameters ​

body ​

BrainMob

target ​

BrainEntity

Returns ​

void

Implementation of ​

BrainWorld.sonicBoom


spawn() ​

spawn(type, position, options?): TestMob

Defined in: testWorld.ts:313

Places a mob and registers it as an entity.

Parameters ​

type ​

string

position ​

Vec3

options? ​

TestEntityOptions = {}

Returns ​

TestMob


villagerCanBreed() ​

villagerCanBreed(_body, _partner): boolean

Defined in: testWorld.ts:586

Returns TestWorld.canBreed.

Parameters ​

_body ​

BrainMob

_partner ​

BrainEntity

Returns ​

boolean

Implementation of ​

BrainWorld.villagerCanBreed


villagerRaidEffect() ​

villagerRaidEffect(body, effect): void

Defined in: testWorld.ts:543

Records a world-owned effect requested by a villager brain.

Parameters ​

body ​

BrainMob

effect ​

VillagerRaidEffect

Returns ​

void

Implementation of ​

BrainWorld.villagerRaidEffect


villagerRaidState() ​

villagerRaidState(_body): VillagerRaidState | undefined

Defined in: testWorld.ts:538

Returns the raid state supplied to this test world.

Parameters ​

_body ​

BrainMob

Returns ​

VillagerRaidState | undefined

Implementation of ​

BrainWorld.villagerRaidState


villagerRestock() ​

villagerRestock(body): void

Defined in: testWorld.ts:548

Records the villagers that were asked to restock their trades.

Parameters ​

body ​

BrainMob

Returns ​

void

Implementation of ​

BrainWorld.villagerRestock


villagerShowTrade() ​

villagerShowTrade(_body, shown): void

Defined in: testWorld.ts:576

Records the change.

Parameters ​

_body ​

BrainMob

shown ​

boolean

Returns ​

void

Implementation of ​

BrainWorld.villagerShowTrade


villagerTask() ​

villagerTask(body, task, target?): boolean

Defined in: testWorld.ts:567

Records the task.

Parameters ​

body ​

BrainMob

task ​

VillagerTask

target? ​

BlockPos | BrainEntity

Returns ​

boolean

Implementation of ​

BrainWorld.villagerTask


villagerWorkSpot() ​

villagerWorkSpot(_body, _task): BlockPos | undefined

Defined in: testWorld.ts:562

Returns TestWorld.farmSpot.

Parameters ​

_body ​

BrainMob

_task ​

"harvest_farmland" | "use_bonemeal"

Returns ​

BlockPos | undefined

Implementation of ​

BrainWorld.villagerWorkSpot