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.
// 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
server1MAverageTPS
server5MAverageTPS
serverInstantTPS
Methods
findBlocksMatching
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 positioncenterZ: the z coordinate of the centre chunk, not the block positionid: the block id to look for, with or without the minecraft namespacechunkrange: how many chunks out from the centre to search, so one is a three by three
null if no world is loadednull 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 namespacechunkrange: how many chunks out from the player's chunk to search
null if there is no world or playerids, 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 namespacechunkrange: how many chunks out from the player's chunk to search
null if there is no world or playerids, 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 positioncenterZ: the z coordinate of the centre chunk, not the block positionids: the block ids to look for, with or without the minecraft namespacechunkrange: how many chunks out from the centre to search
null if no world is loadedfindBlocksMatching(MethodWrapper<BlockHelper, Object, Boolean, ?> blockFilter, MethodWrapper<BlockStateHelper, Object, Boolean, ?> stateFilter, int chunkrange): List<Pos3D>Since1.6.4#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 statesstateFilter: optional predicate selecting states accepted by the block filter, ornullchunkrange: how many chunks out from the player's chunk to search
null if there is no player or worldfindBlocksMatching(int chunkX, int chunkZ, MethodWrapper<BlockHelper, Object, Boolean, ?> blockFilter, MethodWrapper<BlockStateHelper, Object, Boolean, ?> stateFilter, int chunkrange): List<Pos3D>Since1.6.4#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 positionchunkZ: the z coordinate of the centre chunk, not the block positionblockFilter: required predicate selecting blocks; results may be reused for matching statesstateFilter: optional predicate selecting states accepted by the block filter, ornullchunkrange: how many chunks out from the centre to search
null if no world is loadedgetBiome
getBiomeAt
(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 coordinatez: the z block coordinate
null if unavailablenull if no world is loaded or the biome has no registered key.Parameters:
x: the x block coordinatey: the y block coordinatez: the z block coordinate
null if unavailablegetBlock
getBlock(int x, int y, int z): BlockDataHelper#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 coordinatey: the y block coordinatez: the z block coordinate
null for void air or no loaded worldpos, 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
null if the client has no data for itParameters:
pos: the block position to look up
null if the client has no data for itgetBlockLight
Parameters:
x: the x block coordinatey: the y block coordinatez: the z block coordinate
0 to 15, or -1 if no world is loadedgetBossBars
getChunk
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 positionz: the z coordinate of the chunk, not the absolute position
null if no world is loadedgetCurrentServerAddress
const address = World.getCurrentServerAddress();
if (address !== null) {
Chat.log(`connected to ${address}`);
}null if no connection existsgetDifficulty
-1 if no world is loadedgetDimension
getEntities
getEntities(): List<EntityHelper<?>>#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`);
}null if no world is loadedminecraft: namespace; returns null without a world.Parameters:
types: the entity types to consider, with or without the minecraft namespace
null if no world is loadeddistance; negative values match none. Returns null if no player or world is available.Parameters:
distance: the maximum distance to search for entities
null if no player or world is availabledistance. IDs may omit the namespace. Returns null if no player or world is available.Parameters:
distance: the maximum distance to search for entitiestypes: the entity types to consider, with or without the minecraft namespace
null if no player or world is availablefilter 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
null if no world is loadedgetLoadedPlayers
getLoadedPlayers(): List<PlayerEntityHelper<Player>>#null if no world is loadedgetMoonPhase
0 through 7; 0 is full and 4 is new. The phase advances once per 24,000 clock ticks.-1 if no world is loadedgetPlayerEntry
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
null if not found.getPlayers
getPlayers(): List<PlayerListEntryHelper>#null when there is no connection.null if no connection is availablegetRaw
null if no world is loadedgetRespawnPos
null if no world is loaded.null if no world is loadedgetScoreboards
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()}`);
}
}null if no world is loadedgetServer15MAverageTPS
getServer1MAverageTPS
getServer5MAverageTPS
getServerInstantTPS
getServerTPS
Chat.log(`server tps: ${World.getServerTPS()}`);getSkyLight
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 coordinatey: the y block coordinatez: the z block coordinate
0 to 15, or -1 if no world is loadedgetTabListFooter
getTabListHeader
const header = World.getTabListHeader();
if (header !== null) {
Chat.log(`tab-list header: ${header}`);
}null if absentgetTime
-1 when no world is loaded.-1 if world is not loaded.getTimeOfDay
-1 if no world is loadedgetWorldIdentifier
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."UNKNOWN_NAME" if no world or server was foundgetWorldScanner
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()getWorldScanner(MethodWrapper<BlockHelper, Object, Boolean, ?> blockFilter, MethodWrapper<BlockStateHelper, Object, Boolean, ?> stateFilter): WorldScannerSince1.6.5#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 returnstruefor, ornullto keep all of themstateFilter: tests states the block filter kept, keeping the ones it returnstruefor, ornullto keep all of those
null if no world is loadedisChunkLoaded
Parameters:
chunkX: the x coordinate of the chunk, not the absolute positionchunkZ: the z coordinate of the chunk, not the absolute position
true if the client chunk source has the chunk; false if no world is loadedisDay
false. In fixed-time dimensions both this and isNight() return false.true when the world's outside-brightness test passes; false otherwiseisNight
false; with no world loaded this also returns false.true when the world's outside-darkness test passes; false otherwise, including with no world loadedisRaining
true if global rain is active, false otherwise, including with no world loadedisThundering
true implies isRaining() is also true.true if global thunder is active, false otherwise, including with no world loadedisWorldLoaded
true if a world is currently loaded, false otherwiseiterateBox
iterateBox(BlockPosHelper pos1, BlockPosHelper pos2, MethodWrapper<BlockDataHelper, ?, ?, ?> callback): voidSince1.8.4#// 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 positionpos2: the second positioncallback: the callback to call for each block
iterateBox(BlockPosHelper pos1, BlockPosHelper pos2, boolean ignoreAir, MethodWrapper<BlockDataHelper, ?, ?, ?> callback): voidSince1.8.4#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 positionpos2: the second positionignoreAir: whether to ignore air blockscallback: the callback to call for each block
iterateSphere
iterateSphere(BlockPosHelper pos, int radius, MethodWrapper<BlockDataHelper, ?, ?, ?> callback): voidSince1.8.4#// 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 positionradius: the radius to scancallback: the callback to call for each block
iterateSphere(BlockPosHelper pos, int radius, boolean ignoreAir, MethodWrapper<BlockDataHelper, ?, ?, ?> callback): voidSince1.8.4#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 positionradius: the radius to scan, which must not be negativeignoreAir: whether to ignore air blockscallback: the callback to call for each block
playSound
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
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 namespacevolume: the volume value passed to Minecraft's sound manager
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 namespacevolume: the volume value passed to Minecraft's sound managerpitch: the pitch value passed to Minecraft's sound manager
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 namespacevolume: the volume value passed to Minecraft's local-sound APIpitch: the pitch value passed to Minecraft's local-sound APIx: the x world coordinate in blocksy: the y world coordinate in blocksz: the z world coordinate in blocks
playSoundFile
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 foldervolume: position in the clip's master-gain range:0selects its minimum and1its maximum
rayTraceBlock
rayTraceBlock(double x1, double y1, double z1, double x2, double y2, double z2, boolean fluid): BlockDataHelperSince1.6.5#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 liney1: the y coordinate of the start of the linez1: the z coordinate of the start of the linex2: the x coordinate of the end of the liney2: the y coordinate of the end of the linez2: the z coordinate of the end of the linefluid: whether a liquid in the way counts as the hit
null on a miss or without a world/playerrayTraceEntity
rayTraceEntity(double x1, double y1, double z1, double x2, double y2, double z2): EntityHelper<?>Since1.8.3#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 liney1: the y coordinate of the start of the linez1: the z coordinate of the start of the linex2: the x coordinate of the end of the liney2: the y coordinate of the end of the linez2: the z coordinate of the end of the line
null if none doesspawnParticle
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 tominecraftx: the x world coordinate in blocksy: the y world coordinate in blocksz: the z world coordinate in blockscount: 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#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 tominecraftx: the x world coordinate in blocksy: the y world coordinate in blocksz: the z world coordinate in blocksdeltaX: the x position-offset scale for positive counts, or x velocity factor for zerodeltaY: the y position-offset scale for positive counts, or y velocity factor for zerodeltaZ: the z position-offset scale for positive counts, or z velocity factor for zerospeed: the velocity scale; it does not scale position offsetscount: positive values attempt that many particles; zero attempts one; negative values attempt noneforce: whether to set the particle-limiter override flag