Skip to content

BlockStateHelper ​

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

Since1.6.5

Represents one particular state of a block, including its property values. It extends StateHelper with block-specific queries; getUniversal() exposes properties as typed values. States can be obtained from BlockDataHelper.getBlockStateHelper(),
BlockHelper.getDefaultState(), or from the registry with RegistryHelper.getBlockState(String).

js
const state = Client.getRegistryManager().getBlockState("minecraft:oak_stairs", "[facing=east]");  
Chat.log(`${state.getId()}: ${state.toMap().facing} ${state.toMap().half}`);  

// the properties as typed values rather than as names
const universal = state.getUniversal();  
Chat.log(`facing is ${universal.getHorizontalFacing().getName()}`);  
Chat.log(`waterlogged is ${universal.isWaterlogged()}`);  

// and the world's own opinion of the block
Chat.log(`solid ${state.isSolid()}, opaque ${state.isOpaque()}, light ${state.getLuminance()}`);

Constructors ​

new BlockStateHelper ​

new BlockStateHelper(BlockState base)#
Wraps the supplied raw block state without copying or changing it.

Parameters:

  • base: raw block state to wrap

Methods ​

allowsSpawning ​

allowsSpawning(BlockPosHelper pos, String entity): booleanSince1.6.5#
Returns the game's spawn-validity result for this state, position, and entity type. The result can depend on the supplied position and world, not just on the state.

Parameters:

  • pos: the position of the block to check
  • entity: the entity type to check
Returns: true if the entity can spawn on this block state at the given position in the current world.

blocksMovement ​

blocksMovement(): booleanSince1.6.5#
Returns the legacy movement-blocking flag, excluding cobwebs and bamboo saplings.
Returns: true if the state blocks the movement of entities.

emitsRedstonePower ​

emitsRedstonePower(): booleanSince1.6.5#
Returns whether this state's block is a redstone signal source.
Returns: true if the state emits redstone power.

exceedsCube ​

exceedsCube(): booleanSince1.6.5#
Returns the game's large-collision-shape flag for this state.
Returns: true if the state has a large collision shape.

getBlock ​

getBlock(): BlockHelperSince1.6.5#
Returns the block that owns this state.
Returns: the block the state belongs to.

getFluidState ​

getFluidState(): FluidStateHelperSince1.8.4#
Returns the fluid state held by this block state. A state with no fluid returns an empty state, not null; use FluidStateHelper.isEmpty() to test it.
Returns: the fluid state of this block state.

getHardness ​

getHardness(): floatSince1.6.5#
Returns this state's destroy-speed value without a world, position, player, or tool. It is block hardness, not an estimate of breaking time; unbreakable blocks report -1.
Returns: the hardness.

getId ​

getId(): StringSince1.8.4#
Returns the registry id of the block, independent of this state's properties.
Returns: the block's id.

getLuminance ​

getLuminance(): intSince1.6.5#
Returns this state's light emission value.
Returns: the luminance.

getPistonBehaviour ​

getPistonBehaviour(): StringSince1.6.5#
Returns the piston push-reaction name for this state: NORMAL, BLOCK, PUSH_ONLY, DESTROY, or IGNORE.
Returns: the piston behaviour of the state.

getUniversal ​

getUniversal(): UniversalBlockStateHelperSince1.8.4#
Returns a helper with typed accessors for the block-state properties it exposes. Unlike StateHelper.toMap(), these accessors return property values in their typed form; an accessor for a property absent from this state throws rather than returning false.
Returns: a typed-property view of this state.

hasBlockEntity ​

hasBlockEntity(): booleanSince1.6.5#
Returns whether this state has a block entity.
Returns: true if the state has a block entity.

hasComparatorOutput ​

hasComparatorOutput(): booleanSince1.6.5#
Returns whether this state supports an analog output signal.
Returns: true if the state has a comparator output.

hasRandomTicks ​

hasRandomTicks(): booleanSince1.6.5#
Returns whether this state is marked for random ticking.
Returns: true if the state can be random ticked.

hasTag ​

hasTag(String tag): booleanSince2.0.0#
Returns whether this state's block belongs to the supplied block tag. Tag membership is per block, not per state, and is data-driven, so it 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 state's block is in the tag

isAir ​

isAir(): booleanSince1.6.5#
Returns whether this state is marked as air.
Returns: true if the state is air.

isBurnable ​

isBurnable(): booleanSince1.6.5#
Returns whether this state is marked as ignitable by lava.
Returns: true if the state is burnable.

isLiquid ​

isLiquid(): booleanSince1.6.5#
Returns the state's liquid flag; this does not test whether it contains fluid.
Returns: true if the state is a liquid.

isOpaque ​

isOpaque(): booleanSince1.6.5#
Returns whether this state can occlude neighboring blocks.
Returns: true if the state is opaque.

isReplaceable ​

isReplaceable(): booleanSince1.6.5#
Returns whether this state can be replaced in the default placement context.
Returns: true if the state can be replaced.

isSolid ​

isSolid(): booleanSince1.6.5#
Returns the state's legacy solid flag; this is distinct from its opacity.
Returns: true if the state is solid.

isToolRequired ​

isToolRequired(): booleanSince1.6.5#
Returns whether correct-tool status is required for this state's drops.
Returns: true if drops require a correct tool.

shouldSuffocate ​

shouldSuffocate(BlockPosHelper pos): booleanSince1.6.5#
Returns the game's suffocation result for this state at the given position in the currently loaded world.

Parameters:

  • pos: the position of the block to check
Returns: true if an entity can suffocate in this block state at the given position in the current world.

toString ​

toString(): String#
Returns a diagnostic representation containing the wrapped block's identifier and property map.
Returns: a diagnostic representation of the wrapped block state.