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-nulle: block entity, ornullwhen absentbp: block position to store
Methods
getBlock
Returns a helper for the block kind, without its state properties.
Returns: the block
getBlockPos
Returns the position stored when this block helper was created.
Returns: the block pos.
getBlockState
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
Returns a helper for this block's state and its properties.
Returns: a helper over the state this block is in.
getId
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.getRawBlock
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
The block's
x coordinate.Returns: the
x value of the block.getY
The block's
y coordinate.Returns: the
y value of the block.getZ
The block's
z coordinate.Returns: the
z value of the block.