Skip to content

BlockDataHelper ​

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

A block state, its position, and its optional block entity, returned by world block lookups.
getNBT() returns null when no block entity was captured.

js
const block = World.getBlock(Player.getPlayer().getBlockPos().down());  
if (block !== null) {
 Chat.log(`${block.getId()} at ${block.getBlockPos()}`);  
 Chat.log(`it is ${block.getName()} and solid is ${block.getBlockStateHelper().isSolid()}`);  

 // the extra data, for the blocks that keep some
 const nbt = block.getNBT();  
 if (nbt === null) {
   Chat.log("no block entity here");  
 } else {
   Chat.log(nbt.asString());  
 }
}

Constructors ​

new BlockDataHelper ​

new BlockDataHelper(BlockState b, BlockEntity e, BlockPos bp)#
Stores the supplied block state, its block type, optional block entity, and position. The state must be non-null; the position is retained as supplied.

Parameters:

  • b: block state to wrap; must be non-null
  • e: block entity, or null when absent
  • bp: block position to store

Methods ​

getBlock ​

getBlock(): BlockHelperSince1.6.5#
Returns a helper for the block kind, without its state properties.
Returns: the block

getBlockPos ​

getBlockPos(): BlockPosHelperSince1.2.7#
Returns the position stored when this block helper was created.
Returns: the block pos.

getBlockState ​

getBlockState(): Map<String, String>Since1.1.7#
Returns every state property keyed by its name, with the current game-defined value name. This matches StateHelper.toMap() on getBlockStateHelper().
Returns: the property names and their current values.

getBlockStateHelper ​

getBlockStateHelper(): BlockStateHelperSince1.6.5#
Returns a helper for this block's state and its properties.
Returns: a helper over the state this block is in.

getId ​

getId(): String#
The block's registry id, independent of its state properties.
Returns: the block's registry id.

getName ​

getName(): TextHelper#
The block's translated name, independent of its state.
Returns: the translated name of the block. (was string before 1.6.5)

getNBT ​

Serializes the captured block entity to a compound on each call, excluding its position and id.
Returns: the block entity's data, or null if this block has no block entity.

Note: used to be a Map of String to String

getRawBlock ​

getRawBlock(): Block#
Returns the underlying Minecraft block type, without its state properties.
Returns: the raw block object this helper wraps.

getRawBlockEntity ​

getRawBlockEntity(): BlockEntity#
Returns the captured block entity, or null if none was captured. getNBT() serializes this same entity when present.
Returns: the raw block entity, or null if this block has none.

getRawBlockState ​

getRawBlockState(): BlockState#
Returns the underlying Minecraft block state wrapped by this helper.
Returns: the raw block state this helper wraps.

getX ​

getX(): intSince1.1.7#
The block's x coordinate.
Returns: the x value of the block.

getY ​

getY(): intSince1.1.7#
The block's y coordinate.
Returns: the y value of the block.

getZ ​

getZ(): intSince1.1.7#
The block's z coordinate.
Returns: the z value of the block.

toString ​

toString(): String#
Returns a diagnostic representation containing the stored position coordinates and block registry id.
Returns: diagnostic representation of this block data