BlockHelper
com.jsmacrosce.jsmacros.client.api.helper.world.BlockHelper
Describes a block type independently of any world position; BlockStateHelper represents one of that block's variants.
js
const block = Client.getRegistryManager().getBlock("stone");
Chat.log(`${block.getId()} is called ${block.getName()}`);
// inspect its default state and all defined variants
Chat.log(`default state has ${block.getDefaultState().getId()}`);
Chat.log(`and ${block.getStates().size()} states in total`);
// the item that places it
const stack = block.getDefaultItemStack();
Chat.log(`${stack.getItemId()} holds up to ${stack.getMaxCount()}`);Constructors
new BlockHelper
Methods
canMobSpawnInside
Tests whether the block's default state is non-solid and non-liquid.
Returns:
true if its default state is non-solid and non-liquid.getBlastResistance
Returns this block's explosion resistance.
Returns: the explosion resistance value.
getDefaultItemStack
Returns the default stack for the item's form of this block. Blocks without a dedicated item use the item returned by Minecraft's block-to-item mapping.
// the item that places a block, as a stack of one
const block = Client.getRegistryManager().getBlock("oak_stairs");
const stack = block.getDefaultItemStack();
Chat.log(`${stack.getItemId()} x ${stack.getCount()}`);
// a stack of sixty-four of it, ready to place
const many = stack.copy().getCreative().setCount(64);
Chat.log(`${many.getCount()} of ${many.getItemId()}`);Returns: the default item stack of the block.
getDefaultState
Returns the block's registered default state.
// the plain form of a block that comes in variants
const stairs = Client.getRegistryManager().getBlock("oak_stairs");
const plain = stairs.getDefaultState();
for (const [name, value] of plain.toMap()) {
Chat.log(`${name} is ${value}`);
}
// and the same block, a named variant instead
const turned = Client.getRegistryManager().getBlockState("oak_stairs", "[facing=east]");
Chat.log(`${plain.toMap().facing} versus ${turned.toMap().facing}`);Returns: the default state of the block.
getHardness
Returns the block's default destroy-time value, independent of block state. An unbreakable block uses
-1; BlockStateHelper.getHardness() reports state-specific hardness.Returns: the default destroy-time value.
getId
getJumpVelocityMultiplier
Returns this block's jump factor.
Returns: the jump factor multiplier.
getName
Returns the block's display name as text.
Returns: the name of the block.
getSlipperiness
Returns this block's friction value.
Returns: the friction value.
getStates
Returns every possible state defined for this block.
Returns: all possible block states of the block.
getTags
getVelocityMultiplier
Returns this block's entity movement speed factor.
Returns: the speed factor multiplier.
hasDynamicBounds
Returns whether this block's shape is marked dynamic.
Returns:
true if its shape is dynamic.hasTag
Returns whether this block belongs to the supplied block tag. Tag membership is data-driven and can differ between loaded datapacks. Unknown tags and tags from other registries return
false.Parameters:
tag: the block tag id, optionally prefixed with#or missing its namespace
Returns:
true if this block is in the tag