API reference / @jsprismarine/prismarine / world/Proximity
world/Proximity
Interfaces
Point3
Defined in: packages/prismarine/src/world/Proximity.ts:16
Anything with block coordinates: a Vector3, a Position, or a stand-in in a test.
Methods
getX()
getX():
number
Defined in: packages/prismarine/src/world/Proximity.ts:17
Returns
number
getY()
getY():
number
Defined in: packages/prismarine/src/world/Proximity.ts:18
Returns
number
getZ()
getZ():
number
Defined in: packages/prismarine/src/world/Proximity.ts:19
Returns
number
ViewTest
Defined in: packages/prismarine/src/world/Proximity.ts:85
Properties
event
readonlyevent:Point3
Defined in: packages/prismarine/src/world/Proximity.ts:87
Where the thing happened, in block coordinates.
margin?
readonlyoptionalmargin?:number
Defined in: packages/prismarine/src/world/Proximity.ts:98
Chunks of slack; defaults to VIEW_MARGIN_CHUNKS. Negative tightens.
radius?
readonlyoptionalradius?:number
Defined in: packages/prismarine/src/world/Proximity.ts:100
A tighter cap in blocks. Like range, it can only narrow.
range?
readonlyoptionalrange?:number
Defined in: packages/prismarine/src/world/Proximity.ts:96
A cap in chunks belonging to the subject rather than the viewer - an entity type's own tracking range. It can only narrow the result, never widen it past what the viewer sees.
viewDistance
readonlyviewDistance:number
Defined in: packages/prismarine/src/world/Proximity.ts:91
The recipient's negotiated chunk radius; zero means it has not asked yet.
viewer
readonlyviewer:Point3
Defined in: packages/prismarine/src/world/Proximity.ts:89
Where the candidate recipient is, in block coordinates.
Variables
DEFAULT_VIEW_DISTANCE_CHUNKS
constDEFAULT_VIEW_DISTANCE_CHUNKS:4=4
Defined in: packages/prismarine/src/world/Proximity.ts:40
The radius assumed for a client that has not negotiated one yet.
A player is spawned and can be sent things before RequestChunkRadiusPacket arrives, and PlayerSession.getViewDistance is zero until it does. Treating that zero literally would give a brand new player an audience of nothing and an empty world; this is the same fallback the chunk path already uses, so the audience matches the terrain that was actually sent.
SOUND_RADIUS
constSOUND_RADIUS:32=32
Defined in: packages/prismarine/src/world/Proximity.ts:43
Vanilla plays block sounds within about sixteen blocks; a little more is kind to latency.
VIEW_MARGIN_CHUNKS
constVIEW_MARGIN_CHUNKS:1=1
Defined in: packages/prismarine/src/world/Proximity.ts:30
Chunks of slack added to every view test.
Three things make the true edge ragged: the client's copy of a position is up to a tick behind the server's, terrain is loaded on a circular test but unloaded on a square one, and a chunk is only recorded as sent once its batch has finished compressing. One extra ring of packets costs less than an entity blinking in and out along that edge.
WORLD_EVENT_RADIUS
constWORLD_EVENT_RADIUS:32=32
Defined in: packages/prismarine/src/world/Proximity.ts:46
Block cracking and destroy particles: cosmetic, dense, and pointless at a distance.
Functions
chunkDistanceSquared()
chunkDistanceSquared(
a,b):number
Defined in: packages/prismarine/src/world/Proximity.ts:70
The squared distance between two points, in chunk columns, ignoring height.
Height is left out on purpose: terrain is streamed by column, so a client that has a chunk has all of it. Squared because the only thing anyone does with it is compare it to a radius.
Parameters
a
One point, in block coordinates.
b
The other, in block coordinates.
Returns
number
The squared horizontal distance in chunks.
effectiveViewDistance()
effectiveViewDistance(
viewDistance):number
Defined in: packages/prismarine/src/world/Proximity.ts:81
The chunk radius a viewer is treated as having.
Parameters
viewDistance
number
The radius the client negotiated; zero if it has not yet.
Returns
number
The radius to use, never zero.
isInView()
isInView(
test):boolean
Defined in: packages/prismarine/src/world/Proximity.ts:112
Whether a viewer should be told about something that happened at event.
The circular chunk test, not a square one, because needNewChunks loads on dx² + dz² > viewDistance² - the chunks a client holds are a disc, so a square test would send updates for four corners it has no ground for. Both forms cost the same.
Parameters
test
Event, viewer, and the radii that apply.
Returns
boolean
true if the viewer is near enough.
toChunk()
toChunk(
blockCoordinate):number
Defined in: packages/prismarine/src/world/Proximity.ts:57
The chunk column a block coordinate falls in.
Floored before the shift rather than shifted directly - >> converts through ToInt32, which truncates towards zero, so a bare shift puts everything between -1 and 0 in chunk 0 instead of chunk -1. Entity positions are floats, so that case is reached constantly.
Parameters
blockCoordinate
number
A block coordinate, whole or fractional.
Returns
number
The chunk coordinate containing it.