# ChunkHelper

`com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper`

**Since:** 1.8.4

Provides access to a chunk. `World.getChunk(x, z)` takes chunk coordinates, while
 [getOffsetBlock(int, int, int)](#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getOffsetBlock-int-int-int-) uses local `x`/`z` offsets and absolute
 `y` coordinates.  
 ```js
const player = Player.getPlayer();  
const chunk = World.getChunk(Math.floor(player.getX() / 16), Math.floor(player.getZ() / 16));  
if (chunk !== null) {
  Chat.log(`chunk ${chunk.getChunkX()}, ${chunk.getChunkZ()}`);  
  Chat.log(`its low corner is ${chunk.getStartingBlock()}`);  
  Chat.log(`it runs from y ${chunk.getMinBuildHeight()} to ${chunk.getMaxBuildHeight()}`);  

  // offsets are relative to the chunk, not to the world
  const corner = chunk.getOffsetBlock(0, chunk.getMaxBuildHeight(), 0);  
  const block = World.getBlock(corner);  
  if (block !== null) {
    Chat.log(`the top of the corner column is ${block.getId()}`);  
  }
}
 ```

## Constructors

### new ChunkHelper {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_constructor-ChunkAccess-}

```js
new ChunkHelper(ChunkAccess base)
```

Wraps the supplied chunk access reference without loading or looking up a chunk.

**Parameters:**
- `base`: raw chunk access to wrap

## Methods

### containsAll {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_containsAll-String[]-}

```js
containsAll(String... blocks): boolean
```

Tests whether the chunk contains every requested block. Block ids may omit the
 `minecraft` namespace. An id absent from the registry resolves to air, which can make
 the result true for an unintended reason. An empty argument list also returns true.

**Parameters:**
- `blocks`: the blocks to search for

**Returns:** `true` if the chunk contains all the specified blocks, `false`
 otherwise.

**Since:** 1.8.4

### containsAny {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_containsAny-String[]-}

```js
containsAny(String... blocks): boolean
```

Tests whether the chunk contains any requested block. Block ids may omit the
 `minecraft` namespace; an id absent from the registry resolves to air. The current
 implementation compares each block state with a set of blocks, so ordinary nonempty valid
 requests do not match and return `false`.

**Parameters:**
- `blocks`: the blocks to search for

**Returns:** `false` for ordinary nonempty valid requests; otherwise, whether a requested
 block was found.

**Since:** 1.8.4

### forEach {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_forEach-boolean-MethodWrapper-}

```js
forEach(boolean includeAir, MethodWrapper<BlockDataHelper, ?, ?, ?> callback): ChunkHelper
```

Calls `callback` for each included block, in local `x`, then `z`, then
 ascending absolute `y` order. The y range includes both build-height bounds. The walk
 always visits the full chunk; the callback cannot stop it early.

**Parameters:**
- `includeAir`: whether to call the callback for air blocks
- `callback`: the callback function

**Returns:** self for chaining.

**Since:** 1.8.4

### getBiome {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getBiome-int-int-int-}

```js
getBiome(int xOffset, int y, int zOffset): String
```

Returns the registry id of the biome at a position in the loaded world. X and z are local
 offsets from this chunk's origin; y is an absolute coordinate.

**Parameters:**
- `xOffset`: local x coordinate
- `y`: absolute y coordinate
- `zOffset`: local z coordinate

**Returns:** the biome registry id.

**Since:** 1.8.4

### getChunkX {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getChunkX-}

```js
getChunkX(): int
```

Returns this chunk's x coordinate in chunk units, as accepted by `World.getChunk`.

**Returns:** the chunk x coordinate.

**Since:** 1.8.4

### getChunkZ {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getChunkZ-}

```js
getChunkZ(): int
```

Returns this chunk's z coordinate in chunk units, as accepted by `World.getChunk`.

**Returns:** the chunk z coordinate.

**Since:** 1.8.4

### getEntities {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getEntities-}

```js
getEntities(): List<? extends EntityHelper<?>>
```

Returns entities currently exposed by the client rendering iterable whose chunk position
 equals this chunk's position. This is a newly collected list, not the chunk's entity storage.

**Returns:** the collected entities whose chunk position matches this chunk.

**Since:** 1.8.4

### getHeight {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getHeight-}

```js
getHeight(): int
```

Returns the chunk's build height in blocks.

**Returns:** the number of blocks between the lower and upper build-height boundaries.

**Since:** 1.8.4

### getHeightmaps {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getHeightmaps-}

```js
getHeightmaps(): Collection<Map.Entry<Heightmap.Types, Heightmap>>
```

Returns the heightmaps currently stored for this chunk as type/map entries. The returned
 collection is unmodifiable; it reflects only maps currently present.

**Returns:** a map of the raw heightmap data.

**Since:** 1.8.4

### getInhabitedTime {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getInhabitedTime-}

```js
getInhabitedTime(): long
```

Returns the chunk's cumulative inhabited time in ticks. The counter is maintained by the
 game; reading it here does not advance it.

**Returns:** the cumulative inhabited time, in ticks.

**Since:** 1.8.4

### getMaxBuildHeight {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getMaxBuildHeight-}

```js
getMaxBuildHeight(): int
```

Returns the chunk's upper build-height boundary.

**Returns:** the exclusive upper y boundary.

**Since:** 1.8.4

### getMinBuildHeight {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getMinBuildHeight-}

```js
getMinBuildHeight(): int
```

Returns the chunk's lower build-height boundary.

**Returns:** the inclusive lower y boundary.

**Since:** 1.8.4

### getMotionBlockingHeightmap {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getMotionBlockingHeightmap-}

```js
getMotionBlockingHeightmap(): Heightmap
```

Returns the chunk's motion-blocking heightmap, which counts blocks that block motion or
 contain fluid. A new map is created if needed; until populated, its columns return the chunk's
 minimum build height.

**Returns:** the raw motion blocking heightmap.

**Since:** 1.8.4

### getMotionBlockingNoLeavesHeightmap {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getMotionBlockingNoLeavesHeightmap-}

```js
getMotionBlockingNoLeavesHeightmap(): Heightmap
```

Returns the chunk's motion-blocking heightmap, excluding leaves blocks. A new map is created
 if needed; until populated, its columns return the chunk's minimum build height.

**Returns:** the raw motion blocking heightmap without leaves.

**Since:** 1.8.4

### getOceanFloorHeightmap {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getOceanFloorHeightmap-}

```js
getOceanFloorHeightmap(): Heightmap
```

Returns the chunk's ocean-floor heightmap, which counts blocks that block motion. A new map
 is created if needed; until populated, its columns return the chunk's minimum build height.

**Returns:** the raw ocean floor heightmap.

**Since:** 1.8.4

### getOffsetBlock {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getOffsetBlock-int-int-int-}

```js
getOffsetBlock(int xOffset, int y, int zOffset): BlockPosHelper
```

Returns a block position from local `x`/`z` offsets and an absolute `y`.  
 Offsets outside `0..15` on `x` or `z` produce positions in another chunk.

**Parameters:**
- `xOffset`: local x coordinate (normally `0..15`)
- `y`: absolute y coordinate
- `zOffset`: local z coordinate (normally `0..15`)

**Returns:** the resulting world block position.

**Since:** 1.8.4

### getStartingBlock {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getStartingBlock-}

```js
getStartingBlock(): BlockPosHelper
```

Returns the world position of this chunk's local origin.

**Returns:** the block position at local `(0, 0, 0)`.

**Since:** 1.8.4

### getSurfaceHeightmap {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getSurfaceHeightmap-}

```js
getSurfaceHeightmap(): Heightmap
```

Returns the `WORLD_SURFACE` heightmap, counting non-air blocks. Creates an unprimed
 map when none exists; until populated, its columns return the chunk's minimum build height.  
 Use [getTopYAt(int, int, Heightmap)](#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getTopYAt-int-int-Heightmap-) to query a column.

**Returns:** the raw surface heightmap.

**Since:** 1.8.4

### getTileEntities {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getTileEntities-}

```js
getTileEntities(): List<BlockPosHelper>
```

Returns the positions of block entities stored in this chunk.

**Returns:** the collected block-entity positions.

**Since:** 1.8.4

### getTopYAt {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_getTopYAt-int-int-Heightmap-}

```js
getTopYAt(int xOffset, int zOffset, Heightmap heightmap): int
```

Returns the first available y value in the given heightmap column; x and z are local offsets.  
 This is the free space above the heightmap's highest counted block, not that block's y value.

**Parameters:**
- `xOffset`: local x coordinate
- `zOffset`: local z coordinate
- `heightmap`: heightmap to query

**Returns:** the first available y value for the column.

**Since:** 1.8.4

### toString {#com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper_toString-}

```js
toString(): String
```

Returns a diagnostic string containing this chunk's x and z chunk coordinates.

**Returns:** the diagnostic representation of this wrapped chunk, including its x and z chunk coordinates.
