[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / world/Proximity

# world/Proximity

## Interfaces

### Point3

Defined in: [packages/prismarine/src/world/Proximity.ts:16](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L16)

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L17)

###### Returns

`number`

##### getY()

> **getY**(): `number`

Defined in: [packages/prismarine/src/world/Proximity.ts:18](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L18)

###### Returns

`number`

##### getZ()

> **getZ**(): `number`

Defined in: [packages/prismarine/src/world/Proximity.ts:19](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L19)

###### Returns

`number`

***

### ViewTest

Defined in: [packages/prismarine/src/world/Proximity.ts:85](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L85)

#### Properties

##### event

> `readonly` **event**: [`Point3`](#point3)

Defined in: [packages/prismarine/src/world/Proximity.ts:87](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L87)

Where the thing happened, in block coordinates.

##### margin?

> `readonly` `optional` **margin?**: `number`

Defined in: [packages/prismarine/src/world/Proximity.ts:98](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L98)

Chunks of slack; defaults to [VIEW\_MARGIN\_CHUNKS](#view-margin-chunks). Negative tightens.

##### radius?

> `readonly` `optional` **radius?**: `number`

Defined in: [packages/prismarine/src/world/Proximity.ts:100](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L100)

A tighter cap in blocks. Like `range`, it can only narrow.

##### range?

> `readonly` `optional` **range?**: `number`

Defined in: [packages/prismarine/src/world/Proximity.ts:96](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L96)

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

> `readonly` **viewDistance**: `number`

Defined in: [packages/prismarine/src/world/Proximity.ts:91](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L91)

The recipient's negotiated chunk radius; zero means it has not asked yet.

##### viewer

> `readonly` **viewer**: [`Point3`](#point3)

Defined in: [packages/prismarine/src/world/Proximity.ts:89](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L89)

Where the candidate recipient is, in block coordinates.

## Variables

### DEFAULT\_VIEW\_DISTANCE\_CHUNKS

> `const` **DEFAULT\_VIEW\_DISTANCE\_CHUNKS**: `4` = `4`

Defined in: [packages/prismarine/src/world/Proximity.ts:40](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L40)

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

> `const` **SOUND\_RADIUS**: `32` = `32`

Defined in: [packages/prismarine/src/world/Proximity.ts:43](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L43)

Vanilla plays block sounds within about sixteen blocks; a little more is kind to latency.

***

### VIEW\_MARGIN\_CHUNKS

> `const` **VIEW\_MARGIN\_CHUNKS**: `1` = `1`

Defined in: [packages/prismarine/src/world/Proximity.ts:30](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L30)

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

> `const` **WORLD\_EVENT\_RADIUS**: `32` = `32`

Defined in: [packages/prismarine/src/world/Proximity.ts:46](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L46)

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L70)

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

[`Point3`](#point3)

One point, in block coordinates.

##### b

[`Point3`](#point3)

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L81)

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L112)

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

[`ViewTest`](#viewtest)

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/Proximity.ts#L57)

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.
