Skip to content

World ​

com.jsmacrosce.jsmacros.client.api.library.impl.FWorld

Functions for getting and using world data.

An instance of this class is passed to scripts as the World variable.

The client-side World library exposes the currently loaded world. Results reflect client state, and methods document their own null or sentinel behavior. Block-search methods inspect loaded chunks; overloads distinguish chunk coordinates from block positions.

js
// the world has to be loaded before anything here says anything useful
if (World.isWorldLoaded()) {
 // what is the time and where are we
 Chat.log(`${World.getDimension()} at ${World.getTime()}, biome ${World.getBiome()}`);  

 // what is under the player
 const player = Player.getPlayer();  
 if (player !== null) {
   const block = World.getBlock(player.getBlockPos().down());  
   if (block !== null) {
     Chat.log(`standing on ${block.getName()}`);  
   }
 }

 // find diamond ore in the loaded chunks around the player
 const found = World.findBlocksMatching("diamond_ore", 4);  
 if (found !== null) {
   for (const pos of found) {
     Chat.log(`diamond ore at ${pos.getX()}, ${pos.getY()}, ${pos.getZ()}`);  
   }
 }
}

Accessible in scripts via the global World variable.

Fields ​

server15MAverageTPS ​

static server15MAverageTPS: doubleSince1.2.7read-only#
The server's estimated TPS averaged over the last fifteen minutes, using five-minute averages.

server1MAverageTPS ​

static server1MAverageTPS: doubleSince1.2.7read-only#
The server's estimated TPS averaged over the last minute.

server5MAverageTPS ​

static server5MAverageTPS: doubleSince1.2.7read-only#
The server's estimated TPS averaged over the last five minutes, using one-minute averages.

serverInstantTPS ​

static serverInstantTPS: doubleSince1.2.7read-only#
The latest server TPS estimate, calculated from server time updates. Initialized to 20; retains the last estimate until another update is measured.

Methods ​

findBlocksMatching ​

findBlocksMatching(int centerX, int centerZ, String id, int chunkrange): List<Pos3D>Since1.6.4#
Finds positions of a block ID in the square chunk range centered at centerX, centerZ. These are chunk coordinates; a range of 1 covers a 3-by-3 chunk square. Only loaded chunks are scanned, examining their block positions; large ranges can be expensive. IDs may omit the minecraft: namespace. A negative range throws IllegalArgumentException.

Parameters:

  • centerX: the x coordinate of the centre chunk, not the block position
  • centerZ: the z coordinate of the centre chunk, not the block position
  • id: the block id to look for, with or without the minecraft namespace
  • chunkrange: how many chunks out from the centre to search, so one is a three by three
Returns: the positions of every matching block, or null if no world is loaded
findBlocksMatching(String id, int chunkrange): List<Pos3D>Since1.6.4#
Finds positions of a block ID in the square chunk range centered on the player. Returns null if there is no world or player. IDs may omit the minecraft: namespace; only loaded chunks are scanned. A negative range throws IllegalArgumentException.

Parameters:

  • id: the block id to look for, with or without the minecraft namespace
  • chunkrange: how many chunks out from the player's chunk to search
Returns: the positions of every matching block, or null if there is no world or player
findBlocksMatching(String[] ids, int chunkrange): List<Pos3D>Since1.6.4#
Finds positions whose block ID matches any ID in ids, centered on the player. IDs may omit the minecraft: namespace; duplicates do not duplicate results. Returns null if there is no world or player. Only loaded chunks are scanned; a negative range throws IllegalArgumentException.

Parameters:

  • ids: the block ids to look for, with or without the minecraft namespace
  • chunkrange: how many chunks out from the player's chunk to search
Returns: matching positions, or null if there is no world or player
findBlocksMatching(int centerX, int centerZ, String[] ids, int chunkrange): List<Pos3D>Since1.6.4#
Finds positions whose block ID matches any ID in ids, centered at chunk coordinates centerX, centerZ. IDs may omit the namespace; duplicates do not duplicate results. Only loaded chunks are scanned; a negative range throws IllegalArgumentException.

Parameters:

  • centerX: the x coordinate of the centre chunk, not the block position
  • centerZ: the z coordinate of the centre chunk, not the block position
  • ids: the block ids to look for, with or without the minecraft namespace
  • chunkrange: how many chunks out from the centre to search
Returns: the positions of every matching block, or null if no world is loaded
findBlocksMatching(MethodWrapper<BlockHelper, Object, Boolean, ?> blockFilter, MethodWrapper<BlockStateHelper, Object, Boolean, ?> stateFilter, int chunkrange): List<Pos3D>Since1.6.4#
Searches around the player using a required block predicate and an optional state predicate. The callbacks receive BlockHelper and BlockStateHelper, respectively; the state predicate runs only after the block predicate accepts a block. Pass null to omit the state stage. Results are cached by block state, so callbacks need not run once per position. A negative range throws IllegalArgumentException; returns null if there is no world or player.
const found = World.findBlocksMatching(
  JavaWrapper.methodToJava(function (block) {
    return block.getId() === "minecraft:chest";
  }),
  null,
  1
);

Parameters:

  • blockFilter: required predicate selecting blocks; results may be reused for matching states
  • stateFilter: optional predicate selecting states accepted by the block filter, or null
  • chunkrange: how many chunks out from the player's chunk to search
Returns: the positions of every matching block, or null if there is no player or world
findBlocksMatching(int chunkX, int chunkZ, MethodWrapper<BlockHelper, Object, Boolean, ?> blockFilter, MethodWrapper<BlockStateHelper, Object, Boolean, ?> stateFilter, int chunkrange): List<Pos3D>Since1.6.4#
Searches around chunk coordinates chunkX, chunkZ using a required block predicate and an optional state predicate. The callbacks receive BlockHelper and BlockStateHelper; the state predicate runs only after the block predicate accepts a block. Pass null to omit that stage. Results are cached by block state. Returns null if no world is loaded; a negative range throws IllegalArgumentException.

Parameters:

  • chunkX: the x coordinate of the centre chunk, not the block position
  • chunkZ: the z coordinate of the centre chunk, not the block position
  • blockFilter: required predicate selecting blocks; results may be reused for matching states
  • stateFilter: optional predicate selecting states accepted by the block filter, or null
  • chunkrange: how many chunks out from the centre to search
Returns: the positions of every matching block, or null if no world is loaded

getBiome ​

getBiome(): StringSince1.1.5#
Returns the registry ID of the biome at the player's block position, or null if there is no world, player, or registry ID.
Returns: the current biome, or null if no world is loaded

getBiomeAt ​

getBiomeAt(int x, int z): StringSince1.2.3#
Looks up the biome at (x, 10, z); use getBiomeAt(int, int, int) when the vertical coordinate matters. The lookup does not require a loaded chunk, but the result can be null if no world is loaded or the biome has no registered key.
// what biome is this column in
const player = Player.getPlayer();
if (player !== null) {
  Chat.log(`column biome is ${World.getBiomeAt(Math.floor(player.getX()), Math.floor(player.getZ()))}`);
}

Parameters:

  • x: the x block coordinate
  • z: the z block coordinate
Returns: the biome ID at the sampled position, or null if unavailable
getBiomeAt(int x, int y, int z): StringSince1.8.4#
Looks up the biome at the given block coordinates, including the supplied vertical coordinate (unlike getBiomeAt(int, int)). The lookup does not require a loaded chunk, but the result can be null if no world is loaded or the biome has no registered key.

Parameters:

  • x: the x block coordinate
  • y: the y block coordinate
  • z: the z block coordinate
Returns: the biome ID at the sampled position, or null if unavailable

getBlock ​

getBlock(int x, int y, int z): BlockDataHelper#
Returns the block data at block coordinates. A null result means the position resolves to void air or no world is loaded; ordinary air still returns a helper.

Parameters:

  • x: the x block coordinate
  • y: the y block coordinate
  • z: the z block coordinate
Returns: the block data, or null for void air or no loaded world
getBlock(Pos3D pos): BlockDataHelperSince1.8.4#
Returns the block containing pos, flooring each coordinate before lookup. A null result has the same meaning as in getBlock(int, int, int).

Parameters:

  • pos: the point in the world, whose coordinates are rounded down to a block
Returns: The block that point falls inside, or null if the client has no data for it
getBlock(BlockPosHelper pos): BlockDataHelperSince1.8.4#
Returns the block data at pos; a null result has the same meaning as in getBlock(int, int, int).

Parameters:

  • pos: the block position to look up
Returns: The block at that position, or null if the client has no data for it

getBlockLight ​

getBlockLight(int x, int y, int z): intSince1.1.2#
Returns block-emitted light at the block coordinates, independently of sky light. This value alone does not determine the game's lighting or spawning rules.

Parameters:

  • x: the x block coordinate
  • y: the y block coordinate
  • z: the z block coordinate
Returns: the block-light level from 0 to 15, or -1 if no world is loaded

getBossBars ​

getBossBars(): Map<String, BossBarHelper>Since1.2.1#
Copies the client boss overlay's bars into a map keyed by UUID strings. Bars are not restricted to boss fights. The map is a fresh snapshot, but its helpers wrap the existing bar objects rather than frozen copies of their state.
Returns: a non-null map of boss-bar helpers, empty when the overlay has no bars

getChunk ​

getChunk(int x, int z): ChunkHelperSince1.8.4#
Returns the chunk at chunk coordinates x, z; these are not block coordinates. Block coordinates map to chunks by shifting right four bits: 100 >> 4 is chunk 6 (blocks 96–111), while -1 >> 4 is chunk -1. The result is null if no world is loaded. A missing client chunk produces a helper wrapping the client's empty-chunk placeholder, not generated terrain; check isChunkLoaded(int, int) first when you need an already-loaded chunk.
// Convert block coordinates to chunk coordinates, including for negative positions.
const x = -1 >> 4;
const z = 100 >> 4;
if (World.isChunkLoaded(x, z)) {
  const chunk = World.getChunk(x, z);
  if (chunk !== null) Chat.log(`chunk ${x}, ${z} is available`);
}

Parameters:

  • x: the x coordinate of the chunk, not the absolute position
  • z: the z coordinate of the chunk, not the absolute position
Returns: the chunk helper, or null if no world is loaded

getCurrentServerAddress ​

getCurrentServerAddress(): StringSince1.2.2#
Returns the remote address recorded by the current network connection; its string format depends on that address and is not necessarily the hostname entered by the player.
const address = World.getCurrentServerAddress();
if (address !== null) {
  Chat.log(`connected to ${address}`);
}
Returns: the connection's remote address string, or null if no connection exists

getDifficulty ​

getDifficulty(): intSince1.2.6#
Returns the client world's difficulty ID.
Returns: 0 for peaceful, 1 for easy, 2 for normal, 3 for hard, or -1 if no world is loaded

getDimension ​

getDimension(): StringSince1.1.2#
Returns the current dimension identifier as a string, or null if no world is loaded.
Returns: the current dimension, or null if no world is loaded

getEntities ​

getEntities(): List<EntityHelper<?>>#
Returns a snapshot of entities currently available to the client; it is null when no world is loaded. Use getEntities(String...) to filter by type, getEntities(double) to filter by player distance, or getEntities(MethodWrapper) for a custom filter.
const entities = World.getEntities();
if (entities !== null) {
  Chat.log(`${entities.size()} entities available to the client`);
}
Returns: a snapshot of available entities, or null if no world is loaded
getEntities(String... types): List<EntityHelper<?>>Since1.8.4#
Returns entities from the client's rendering collection whose type matches any supplied ID. IDs may omit the minecraft: namespace; returns null without a world.

Parameters:

  • types: the entity types to consider, with or without the minecraft namespace
Returns: matching entities in the client's rendering collection, or null if no world is loaded
getEntities(double distance): List<EntityHelper<?>>Since1.8.4#
Returns entities from the client's rendering collection whose distance from the player is at most distance; negative values match none. Returns null if no player or world is available.

Parameters:

  • distance: the maximum distance to search for entities
Returns: matching entities in the client's rendering collection, or null if no player or world is available
getEntities(double distance, String... types): List<EntityHelper<?>>Since1.8.4#
Returns rendering-collection entities that match any supplied type ID and whose distance from the player is at most distance. IDs may omit the namespace. Returns null if no player or world is available.

Parameters:

  • distance: the maximum distance to search for entities
  • types: the entity types to consider, with or without the minecraft namespace
Returns: matching entities in the client's rendering collection, or null if no player or world is available
getEntities(MethodWrapper<EntityHelper<?>, ?, ?, ?> filter): List<EntityHelper<?>>Since1.8.4#
Applies filter to wrappers for entities in the client's rendering collection and returns those accepted. Returns null without a world. The result list is newly assembled, but its helpers wrap live entities.

Parameters:

  • filter: the entity filter
Returns: matching entities, or null if no world is loaded

getLoadedPlayers ​

getLoadedPlayers(): List<PlayerEntityHelper<Player>>#
Returns wrappers for player entities currently present in the client world. Unlike getPlayers(), this does not include tab-list entries for players without a client-side entity.
Returns: current client-world player entities, or null if no world is loaded

getMoonPhase ​

getMoonPhase(): intSince1.2.6#
Returns the moon phase index from 0 through 7; 0 is full and 4 is new. The phase advances once per 24,000 clock ticks.
Returns: the moon phase index, or -1 if no world is loaded

getPlayerEntry ​

getPlayerEntry(String name): PlayerListEntryHelperSince1.8.4#
Returns the matching online-player entry, or null when there is no connection or no matching name. See getPlayers() for the entry list.

Parameters:

  • name: the name of the player to get the entry for
Returns: player entry for the given player's name or null if not found.

getPlayers ​

Returns a snapshot of the connection's online-player entries. Unlike getLoadedPlayers(), entries need not have a client-side entity; returns null when there is no connection.
Returns: online-player entries, or null if no connection is available

getRaw ​

getRaw(): ClientLevelSince1.9.1#
Returns the raw Minecraft client level rather than a JsMacros wrapper. Its member names depend on the loader and Minecraft target, and shipped typings do not model those game members; see FClient.getMinecraft() for the related raw Minecraft access point.
Returns: the raw client level, or null if no world is loaded

getRespawnPos ​

getRespawnPos(): BlockPosHelperSince1.2.6#
Returns respawn-related position data from the client level; it does not predict the eventual respawn outcome. Before 1.21.9 this is the level's shared spawn position; on 1.21.9 and later it is the position in the level's respawn data, not a personal bed lookup. The result is null if no world is loaded.
Returns: the client-level spawn or respawn-data position, or null if no world is loaded

getScoreboards ​

getScoreboards(): ScoreboardsHelperSince1.2.9#
Returns the current client world's scoreboard, including its objectives, display slots, and teams. The client state reflects scoreboard updates it has received; the result is null when no world is loaded.
const boards = World.getScoreboards();
if (boards !== null) {
  const current = boards.getCurrentScoreboard();
  if (current !== null) {
    Chat.log(`sidebar objective is ${current.getName()}`);
  }
}
Returns: the current scoreboard, or null if no world is loaded

getServer15MAverageTPS ​

getServer15MAverageTPS(): doubleSince1.2.7#
Returns the server's estimated TPS averaged over the last fifteen minutes.
Returns: the fifteen-minute average of five-minute TPS averages

getServer1MAverageTPS ​

getServer1MAverageTPS(): doubleSince1.2.7#
Returns the server's estimated TPS averaged over the last minute.
Returns: the one-minute average of instant TPS estimates

getServer5MAverageTPS ​

getServer5MAverageTPS(): doubleSince1.2.7#
Returns the server's estimated TPS averaged over the last five minutes.
Returns: the five-minute average of one-minute TPS averages

getServerInstantTPS ​

getServerInstantTPS(): doubleSince1.2.7#
Returns the latest server TPS estimate, calculated from server time updates. Initialized to 20 and not reset on world changes.
Returns: the latest server TPS estimate

getServerTPS ​

getServerTPS(): StringSince1.2.7#
Formats the latest server TPS estimate and the one-, five- and fifteen-minute averages. Estimates use server time updates, not a server-reported TPS measurement. The one-minute value averages retained instant estimates; the five-minute value averages one-minute averages sampled at intervals exceeding one minute, and the fifteen-minute value averages five-minute averages sampled at intervals exceeding five minutes. Each update removes at most one expired sample from each window, so older samples can remain after a long gap. Values start at 20 and retain their last reading across world changes. Login clears the sample windows but does not reset the published values; a later time update recalculates them using only samples accumulated since login. Longer averages represent their full periods only after enough new samples accumulate.
Chat.log(`server tps: ${World.getServerTPS()}`);
Returns: the instant, one-, five- and fifteen-minute estimates in one string

getSkyLight ​

getSkyLight(int x, int y, int z): intSince1.1.2#
Returns sky light at the block coordinates. This layer is independent of block light and does not account for sky-darkening effects of time or weather; a position in an unloaded chunk may still return a level.
const player = Player.getPlayer();
if (player !== null) {
  const pos = player.getBlockPos();
  const sky = World.getSkyLight(pos.getX(), pos.getY(), pos.getZ());
  const block = World.getBlockLight(pos.getX(), pos.getY(), pos.getZ());
  Chat.log(`sky light ${sky}, block light ${block}`);
}

Parameters:

  • x: the x block coordinate
  • y: the y block coordinate
  • z: the z block coordinate
Returns: the sky-light level from 0 to 15, or -1 if no world is loaded

getTabListFooter ​

getTabListFooter(): TextHelperSince1.3.1#
Returns the current tab-list footer, normally supplied by the server, as a TextHelper. Retains its rich formatting and hover/click data, without guaranteeing those actions run. Use getTabListHeader() for the corresponding header.
Returns: the footer, or null if absent

getTabListHeader ​

getTabListHeader(): TextHelperSince1.3.1#
Returns the current tab-list header, normally supplied by the server, as a TextHelper. Retains its rich formatting and hover/click data, without guaranteeing those actions run.
const header = World.getTabListHeader();
if (header !== null) {
  Chat.log(`tab-list header: ${header}`);
}
Returns: the header, or null if absent

getTime ​

getTime(): longSince1.1.5#
Returns the client world's game-time counter, distinct from the day-time clock returned by getTimeOfDay(). Returns -1 when no world is loaded.
Returns: the current world time. -1 if world is not loaded.

getTimeOfDay ​

getTimeOfDay(): longSince1.1.5#
Returns the current dimension's time-of-day ticks, including time skipped by sleeping. On 26.1+, dimensions with a default clock use it; dimensions without one use the overworld clock. Unlike getTime(), this value follows the day-time clock rather than elapsed game ticks.
Returns: time-of-day ticks, or -1 if no world is loaded

getWorldIdentifier ​

getWorldIdentifier(): StringSince1.8.4#
Builds a name-based identifier for the current world; it is not guaranteed unique or stable. Singleplayer uses LOCAL_ followed by the save folder name; realms and LAN games use REALM_ or LAN_ followed by the server entry's name. Other servers use their address with every :25565 substring removed and remaining colons replaced by underscores.
Returns: the derived identifier, or "UNKNOWN_NAME" if no world or server was found

getWorldScanner ​

getWorldScanner(): WorldScannerBuilderSince1.6.5#
Returns a builder for a world scanner. The example builds a scanner matching blocks facing south that do not require a tool, have hardness at most 10, and whose string representation contains chest or barrel; building does not scan.
World.getWorldScanner()
    .withBlockFilter("getHardness").is("\x3C=", 10)
    .andStringBlockFilter().contains("chest", "barrel")
    .withStringStateFilter().contains("facing=south")
    .andStateFilter("isToolRequired").is(false)
    .build()
Returns: a builder to create a WorldScanner.
getWorldScanner(MethodWrapper<BlockHelper, Object, Boolean, ?> blockFilter, MethodWrapper<BlockStateHelper, Object, Boolean, ?> stateFilter): WorldScannerSince1.6.5#
Returns a scanner over the current world from two filter functions. This is the free form of the scanner getWorldScanner() builds, and it is the one to reach for when a filter is a real computation rather than a chain of equals and contains checks. The filters are stages: a block is kept when the block filter accepts it, and its state must then pass the state filter. Either may be null to skip that stage. Results are cached per block state for the life of the scanner and reused rather than evaluated for every block. Concurrent first encounters of a state may evaluate the filters more than once before an answer is cached. Build a new scanner when a filter reads script state that can change. The scanner uses parallel streams only when both filters support parallel execution; those filters must not access the world unsafely.
// every loaded block that is solid and is not dirt. naming the parameter type
// is what tells the wrapper what it is being handed
const scanner = World.getWorldScanner(
  JavaWrapper.methodToJava(function (block: BlockHelper) {
    return block.getId() !== "minecraft:dirt";
  }),
  JavaWrapper.methodToJava(function (state: BlockStateHelper) {
    return state.isSolid();
  })
);
if (scanner !== null) {
  const found = scanner.scanAroundPlayer(2);
  Chat.log(`${found.size()} blocks matched`);
}

Parameters:

  • blockFilter: tests block states, keeping the ones it returns true for, or null to keep all of them
  • stateFilter: tests states the block filter kept, keeping the ones it returns true for, or null to keep all of those
Returns: a scanner for the current world, or null if no world is loaded

isChunkLoaded ​

isChunkLoaded(int chunkX, int chunkZ): booleanSince1.2.2#
Checks whether the client chunk source currently has the given chunk.

Parameters:

  • chunkX: the x coordinate of the chunk, not the absolute position
  • chunkZ: the z coordinate of the chunk, not the absolute position
Returns: true if the client chunk source has the chunk; false if no world is loaded

isDay ​

isDay(): booleanSince1.8.4#
Tests the world's outside brightness, based on world time and weather rather than block light or whether the player is underwater. With no world loaded it returns false. In fixed-time dimensions both this and isNight() return false.
Returns: true when the world's outside-brightness test passes; false otherwise

isNight ​

isNight(): booleanSince1.8.4#
Uses the world's outside-darkness test, which considers time and weather rather than block light or whether the player is underwater. In fixed-time dimensions both isDay() and this method return false; with no world loaded this also returns false.
Returns: true when the world's outside-darkness test passes; false otherwise, including with no world loaded

isRaining ​

isRaining(): booleanSince1.8.4#
Returns whether the client world's global rain state is active; this is not a local player-position or sky-visibility test.
Returns: true if global rain is active, false otherwise, including with no world loaded

isThundering ​

isThundering(): booleanSince1.8.4#
Returns whether the client world's global thunder state is active, not whether there is thunder at the player's position. The global thunder level is derived from the rain level, so true implies isRaining() is also true.
Returns: true if global thunder is active, false otherwise, including with no world loaded

isWorldLoaded ​

isWorldLoaded(): booleanSince1.3.0#
Returns whether the client currently has a world loaded.
Returns: true if a world is currently loaded, false otherwise

iterateBox ​

iterateBox(BlockPosHelper pos1, BlockPosHelper pos2, MethodWrapper<BlockDataHelper, ?, ?, ?> callback): voidSince1.8.4#
walk a cuboid of block positions, ignoring air. This is the box shaped counterpart to iterateSphere(BlockPosHelper, int, MethodWrapper), and it includes both corners, so a box from one position to the next covers every position between them as well. The two corners are given in either order and the walk covers the space between them, so it does not matter which is which. The callback is called synchronously on the calling thread for each non-air position.
// what is in the six blocks directly above the player
const player = Player.getPlayer();
if (player !== null) {
  const base = player.getBlockPos();
  World.iterateBox(base.up(), base.up(6), JavaWrapper.methodToJava(function (block) {
    Chat.log(block.getName());
  }));
}

Parameters:

  • pos1: the first position
  • pos2: the second position
  • callback: the callback to call for each block
iterateBox(BlockPosHelper pos1, BlockPosHelper pos2, boolean ignoreAir, MethodWrapper<BlockDataHelper, ?, ?, ?> callback): voidSince1.8.4#
Visits positions between the corners, including air only when ignoreAir is false. The callback runs synchronously on the calling thread; with no world loaded there are no calls. Each corner's y is computed as clamp(minY, cornerY, height) in the current implementation, not as a clamp of cornerY to the build-height range; visited positions are not guaranteed to lie within that range.

Parameters:

  • pos1: the first position
  • pos2: the second position
  • ignoreAir: whether to ignore air blocks
  • callback: the callback to call for each block

iterateSphere ​

iterateSphere(BlockPosHelper pos, int radius, MethodWrapper<BlockDataHelper, ?, ?, ?> callback): voidSince1.8.4#
By default, air blocks are ignored and the callback is only called for real blocks. This walks a sphere of block positions around a centre and calls back for each one that is not air. The shape is a sphere measured in whole blocks, so the callback is made for every position inside the radius rather than for a sphere surface, and the vertical extent is clamped to the world's own build limits so the walk does not run off the top or the bottom. This is the form for "everything solid near here" where the answer is short and a list would be wasteful. The callback is called once per block position, so it is the per-block work that costs. Callbacks run synchronously on the calling thread.
// count the solid blocks in a five block bubble around the player
const player = Player.getPlayer();
if (player !== null) {
  let count = 0;
  World.iterateSphere(player.getBlockPos(), 5, JavaWrapper.methodToJava(function (block) {
    if (block.getBlockStateHelper().isSolid()) count++;
  }));
  Chat.log(`${count} solid blocks within five blocks`);
}

Parameters:

  • pos: the center position
  • radius: the radius to scan
  • callback: the callback to call for each block
iterateSphere(BlockPosHelper pos, int radius, boolean ignoreAir, MethodWrapper<BlockDataHelper, ?, ?, ?> callback): voidSince1.8.4#
Visits positions accepted by a squared-distance test around pos. Bounds and the distance test use integer arithmetic, which can overflow for large radii or coordinates. The current y bounds use clamp(minY, centerY - radius, height) and clamp(minY, centerY + radius, height); they do not guarantee positions within the world's build-height limits. With ignoreAir true, air positions are skipped. The callback runs synchronously on the calling thread; with no world loaded there are no calls. A negative radius throws IllegalArgumentException.

Parameters:

  • pos: the center position
  • radius: the radius to scan, which must not be negative
  • ignoreAir: whether to ignore air blocks
  • callback: the callback to call for each block

playSound ​

playSound(String id): voidSince1.1.7#
Plays a local UI sound at volume 1 and pitch 0.25. The ID is parsed as a resource location; playback is submitted to the client sound manager. For positional playback, use playSound(String, double, double, double, double, double).

Parameters:

  • id: the sound event id, with or without the minecraft namespace
playSound(String id, double volume): voidSince1.1.7#
Plays a local UI sound at the supplied volume and pitch 0.25. The ID is parsed as a resource location; playback is submitted to the client sound manager. Use playSound(String, double, double, double, double, double) for positional playback.

Parameters:

  • id: the sound event id, with or without the minecraft namespace
  • volume: the volume value passed to Minecraft's sound manager
playSound(String id, double volume, double pitch): voidSince1.1.7#
Plays a local UI sound with volume and pitch converted to float. The two-argument overload defaults pitch to 0.25; pass a pitch explicitly to choose another value. Use playSound(String, double, double, double, double, double) for positional playback.

Parameters:

  • id: the sound event id, with or without the minecraft namespace
  • volume: the volume value passed to Minecraft's sound manager
  • pitch: the pitch value passed to Minecraft's sound manager
playSound(String id, double volume, double pitch, double x, double y, double z): voidSince1.1.7#
Plays a local sound at the supplied coordinates using the master category. Volume and pitch are converted to float; with no world loaded, this method does nothing. The sound is not sent to the server.

Parameters:

  • id: the sound event id, with or without the minecraft namespace
  • volume: the volume value passed to Minecraft's local-sound API
  • pitch: the pitch value passed to Minecraft's local-sound API
  • x: the x world coordinate in blocks
  • y: the y world coordinate in blocks
  • z: the z world coordinate in blocks

playSoundFile ​

playSoundFile(String file, double volume): ClipSince1.1.7#
Opens and starts a Java Sound clip from a file relative to the macro folder. volume is mapped to the clip's master-gain range; the returned clip can be stopped by the caller and is closed on its stop event. File and Java Sound operations may fail with the declared exceptions; actual audibility depends on the host audio system.

Parameters:

  • file: the file to play, relative to the macro folder
  • volume: position in the clip's master-gain range: 0 selects its minimum and 1 its maximum
Returns: the started clip, which the caller may stop

rayTraceBlock ​

rayTraceBlock(double x1, double y1, double z1, double x2, double y2, double z2, boolean fluid): BlockDataHelperSince1.6.5#
Clips from the start point to the end point against block collider shapes. fluid selects whether fluids are considered; a miss returns null. Returns null if either the world or local player is unavailable (the player supplies the clip context).

Parameters:

  • x1: the x coordinate of the start of the line
  • y1: the y coordinate of the start of the line
  • z1: the z coordinate of the start of the line
  • x2: the x coordinate of the end of the line
  • y2: the y coordinate of the end of the line
  • z2: the z coordinate of the end of the line
  • fluid: whether a liquid in the way counts as the hit
Returns: block data at the first collider or selected fluid hit, or null on a miss or without a world/player

rayTraceEntity ​

rayTraceEntity(double x1, double y1, double z1, double x2, double y2, double z2): EntityHelper<?>Since1.8.3#
Returns the living entity whose hitbox intersects the segment and is nearest the player; this need not be the first entity from the segment's start. Non-living entities are ignored. Returns null if no world is loaded or no eligible entity intersects the segment. Requires a local player for the distance comparison when a world is loaded.
// is there a mob between the player and a point ten blocks ahead?
const player = Player.getPlayer();
if (player !== null) {
  const eyes = player.getEyePos();
  const end = eyes.add(10, 0, 0);
  const mob = World.rayTraceEntity(
    eyes.getX(), eyes.getY(), eyes.getZ(),
    end.getX(), end.getY(), end.getZ()
  );
  Chat.log(mob === null ? "nothing in the way" : `${mob.getName()} is in the way`);
}

Parameters:

  • x1: the x coordinate of the start of the line
  • y1: the y coordinate of the start of the line
  • z1: the z coordinate of the start of the line
  • x2: the x coordinate of the end of the line
  • y2: the y coordinate of the end of the line
  • z2: the z coordinate of the end of the line
Returns: a living entity whose hitbox the line passes through, or null if none does

spawnParticle ​

spawnParticle(String id, double x, double y, double z, int count): voidSince1.8.4#
Spawns particles locally using deltas of 0.1 on each axis, speed 1, and the particle-limiter override enabled. Positive counts use Gaussian position offsets, not a bounded tenth-block box. Nothing happens without a player. See spawnParticle(String, double, double, double, double, double, double, double, int, boolean) for supported IDs, count semantics, and visibility limitations.
// a puff of particles at a point in the world
World.spawnParticle("minecraft:flame", 0, 65, 0, 20);

Parameters:

  • id: a simple particle registry ID; the namespace defaults to minecraft
  • x: the x world coordinate in blocks
  • y: the y world coordinate in blocks
  • z: the z world coordinate in blocks
  • count: positive values attempt that many particles; zero attempts one; negative values attempt none
spawnParticle(String id, double x, double y, double z, double deltaX, double deltaY, double deltaZ, double speed, int count, boolean force): voidSince1.8.4#
Schedules particle spawning on the local client; no particles are sent to the server or other players. Nothing happens without a player. For positive counts, each attempt uses Gaussian position offsets scaled by the deltas and independent Gaussian velocity components scaled by speed. Zero deltas keep the initial positions at the supplied coordinates; they do not eliminate velocity. A zero count instead attempts one particle at the exact position with velocity components deltaX * speed, deltaY * speed, and deltaZ * speed. The ID is a registry identifier, not particle-option data. Only simple particle types are supported; parameterized types such as minecraft:dust cause a ClassCastException. A missing registry value falls back to CLOUD. The force argument overrides the particle limiter, while the packet's alwaysShow flag is always enabled. Neither guarantees visibility at arbitrary distances or that every attempted particle will render.
// a tight burst of flame with the particle-limiter override enabled
World.spawnParticle("flame", 0, 65, 0, 0, 0, 0, 1, 10, true);

// and a wider Gaussian spread, not a bounded four-block box
World.spawnParticle("flame", 0, 65, 0, 2, 2, 2, 0.1, 100, false);

Parameters:

  • id: a simple particle registry ID; the namespace defaults to minecraft
  • x: the x world coordinate in blocks
  • y: the y world coordinate in blocks
  • z: the z world coordinate in blocks
  • deltaX: the x position-offset scale for positive counts, or x velocity factor for zero
  • deltaY: the y position-offset scale for positive counts, or y velocity factor for zero
  • deltaZ: the z position-offset scale for positive counts, or z velocity factor for zero
  • speed: the velocity scale; it does not scale position offsets
  • count: positive values attempt that many particles; zero attempts one; negative values attempt none
  • force: whether to set the particle-limiter override flag