BlockStateHelper
com.jsmacrosce.jsmacros.client.api.helper.world.BlockStateHelper
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
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 checkentity: 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
Returns the legacy movement-blocking flag, excluding cobwebs and bamboo saplings.
Returns:
true if the state blocks the movement of entities.emitsRedstonePower
Returns whether this state's block is a redstone signal source.
Returns:
true if the state emits redstone power.exceedsCube
Returns the game's large-collision-shape flag for this state.
Returns:
true if the state has a large collision shape.getBlock
Returns the block that owns this state.
Returns: the block the state belongs to.
getFluidState
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
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
getLuminance
Returns this state's light emission value.
Returns: the luminance.
getPistonBehaviour
getUniversal
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
Returns whether this state has a block entity.
Returns:
true if the state has a block entity.hasComparatorOutput
Returns whether this state supports an analog output signal.
Returns:
true if the state has a comparator output.hasRandomTicks
Returns whether this state is marked for random ticking.
Returns:
true if the state can be random ticked.hasTag
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 tagisAir
Returns whether this state is marked as air.
Returns:
true if the state is air.isBurnable
Returns whether this state is marked as ignitable by lava.
Returns:
true if the state is burnable.isLiquid
Returns the state's liquid flag; this does not test whether it contains fluid.
Returns:
true if the state is a liquid.isOpaque
Returns whether this state can occlude neighboring blocks.
Returns:
true if the state is opaque.isReplaceable
Returns whether this state can be replaced in the default placement context.
Returns:
true if the state can be replaced.isSolid
Returns the state's legacy solid flag; this is distinct from its opacity.
Returns:
true if the state is solid.isToolRequired
Returns whether correct-tool status is required for this state's drops.
Returns:
true if drops require a correct tool.shouldSuffocate
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.