Skip to content

ChunkHelper ​

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

Since1.8.4

Provides access to a chunk. World.getChunk(x, z) takes chunk coordinates, while 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 ​

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 ​

containsAll(String... blocks): booleanSince1.8.4#
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.

containsAny ​

containsAny(String... blocks): booleanSince1.8.4#
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.

forEach ​

forEach(boolean includeAir, MethodWrapper<BlockDataHelper, ?, ?, ?> callback): ChunkHelperSince1.8.4#
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.

getBiome ​

getBiome(int xOffset, int y, int zOffset): StringSince1.8.4#
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.

getChunkX ​

getChunkX(): intSince1.8.4#
Returns this chunk's x coordinate in chunk units, as accepted by World.getChunk.
Returns: the chunk x coordinate.

getChunkZ ​

getChunkZ(): intSince1.8.4#
Returns this chunk's z coordinate in chunk units, as accepted by World.getChunk.
Returns: the chunk z coordinate.

getEntities ​

getEntities(): List<? extends EntityHelper<?>>Since1.8.4#
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.

getHeight ​

getHeight(): intSince1.8.4#
Returns the chunk's build height in blocks.
Returns: the number of blocks between the lower and upper build-height boundaries.

getHeightmaps ​

getHeightmaps(): Collection<Map.Entry<Heightmap.Types, Heightmap>>Since1.8.4#
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.

getInhabitedTime ​

getInhabitedTime(): longSince1.8.4#
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.

getMaxBuildHeight ​

getMaxBuildHeight(): intSince1.8.4#
Returns the chunk's upper build-height boundary.
Returns: the exclusive upper y boundary.

getMinBuildHeight ​

getMinBuildHeight(): intSince1.8.4#
Returns the chunk's lower build-height boundary.
Returns: the inclusive lower y boundary.

getMotionBlockingHeightmap ​

getMotionBlockingHeightmap(): HeightmapSince1.8.4#
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.

getMotionBlockingNoLeavesHeightmap ​

getMotionBlockingNoLeavesHeightmap(): HeightmapSince1.8.4#
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.

getOceanFloorHeightmap ​

getOceanFloorHeightmap(): HeightmapSince1.8.4#
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.

getOffsetBlock ​

getOffsetBlock(int xOffset, int y, int zOffset): BlockPosHelperSince1.8.4#
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.

getStartingBlock ​

getStartingBlock(): BlockPosHelperSince1.8.4#
Returns the world position of this chunk's local origin.
Returns: the block position at local (0, 0, 0).

getSurfaceHeightmap ​

getSurfaceHeightmap(): HeightmapSince1.8.4#
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) to query a column.
Returns: the raw surface heightmap.

getTileEntities ​

getTileEntities(): List<BlockPosHelper>Since1.8.4#
Returns the positions of block entities stored in this chunk.
Returns: the collected block-entity positions.

getTopYAt ​

getTopYAt(int xOffset, int zOffset, Heightmap heightmap): intSince1.8.4#
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.

toString ​

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.