ChunkHelper
com.jsmacrosce.jsmacros.client.api.helper.world.ChunkHelper
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
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
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 blockscallback: the callback function
Returns: self for chaining.
getBiome
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 coordinatey: absolute y coordinatezOffset: local z coordinate
Returns: the biome registry id.
getChunkX
Returns this chunk's x coordinate in chunk units, as accepted by
World.getChunk.Returns: the chunk x coordinate.
getChunkZ
Returns this chunk's z coordinate in chunk units, as accepted by
World.getChunk.Returns: the chunk z coordinate.
getEntities
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
Returns the chunk's build height in blocks.
Returns: the number of blocks between the lower and upper build-height boundaries.
getHeightmaps
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
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
Returns the chunk's upper build-height boundary.
Returns: the exclusive upper y boundary.
getMinBuildHeight
Returns the chunk's lower build-height boundary.
Returns: the inclusive lower y boundary.
getMotionBlockingHeightmap
getMotionBlockingNoLeavesHeightmap
getOceanFloorHeightmap
getOffsetBlock
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 (normally0..15)y: absolute y coordinatezOffset: local z coordinate (normally0..15)
Returns: the resulting world block position.
getStartingBlock
Returns the world position of this chunk's local origin.
Returns: the block position at local
(0, 0, 0).getSurfaceHeightmap
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
Returns the positions of block entities stored in this chunk.
Returns: the collected block-entity positions.
getTopYAt
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 coordinatezOffset: local z coordinateheightmap: heightmap to query
Returns: the first available y value for the column.