Skip to content

UniversalBlockStateHelper ​

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

Since1.8.4

Provides typed accessors for common block-state properties. Unlike StateHelper.toMap(), which returns property values as names, these accessors return values such as directions and numbers in their typed form. Accessing a property absent from the state throws. The level, distance, and age accessors try supported properties in order and throw if none is present. Obtain this helper from BlockStateHelper.getUniversal().

js
// Compare a typed direction with the map's property-name value.  
const reg = Client.getRegistryManager();  
const state = reg.getBlockState("minecraft:oak_stairs", "[facing=east,half=bottom]");  
const universal = state.getUniversal();  

Chat.log(universal.getHorizontalFacing().getName());   // a direction
Chat.log(universal.getBlockHalf());                    // a word
Chat.log(universal.isWaterlogged());                    // a boolean

for (const [name, value] of state.toMap()) {
  Chat.log(`${name} is ${value}`);                      // every property, as names
}

// Accessing an absent property throws.  
try {
  universal.getHoneyLevel();  
} catch (e) {
  Chat.log("a stair has no honey level");  
}

// Numeric families try their supported properties in order.  
const wheat = reg.getBlockState("minecraft:wheat").getUniversal();  
Chat.log(`age ${wheat.getAge()} of ${wheat.getMaxAge()}`);

Constructors ​

new UniversalBlockStateHelper ​

new UniversalBlockStateHelper(BlockState base)#
Wraps the supplied block-state reference.

Parameters:

  • base: non-null block state to wrap

Methods ​

canSummon ​

canSummon(): booleanSince1.8.4#
Returns: whether this sculk sensor can summon.

getAge ​

getAge(): intSince1.8.4#
Returns the value of the first present property in the helper's configured order: AGE_1, AGE_2, AGE_3, AGE_4, AGE_5, AGE_7, AGE_15, then AGE_25. No scaling is applied between properties.
Returns: the value of the first present age property.

getAttachment ​

getAttachment(): StringSince1.8.4#
Returns: the BELL_ATTACHMENT property's value, as the name the game gives it.

getAxis ​

getAxis(): StringSince1.8.4#
Returns: the name of the AXIS property's value.

getBambooLeaves ​

getBambooLeaves(): StringSince1.8.4#
Returns: the serialized name of the BAMBOO_LEAVES property.

getBedPart ​

getBedPart(): StringSince1.8.4#
Returns: the serialized name of the BED_PART property's value.

getBites ​

getBites(): intSince1.8.4#
Returns: the BITES property's value.

getBlockFace ​

getBlockFace(): StringSince1.9.0#
Returns: the attachment face's serialized name.

getBlockHalf ​

getBlockHalf(): StringSince1.8.4#
Returns: the serialized value of the HALF property.

getCandles ​

getCandles(): intSince1.8.4#
Returns: the CANDLES property's value.

getCharges ​

getCharges(): intSince1.8.4#
Returns: the respawn anchor's charge count.

getChestType ​

getChestType(): StringSince1.8.4#
Returns: the serialized name of the CHEST_TYPE property.

getComparatorMode ​

getComparatorMode(): StringSince1.8.4#
Returns: the serialized name of the MODE_COMPARATOR property.

getDelay ​

getDelay(): intSince1.8.4#
Returns the state's DELAY property.
Returns: the DELAY property's value.

getDistance ​

getDistance(): intSince1.8.4#
Returns the first present property in order: STABILITY_DISTANCE, then DISTANCE. Throws if neither property is present.
Returns: the distance of this state, from the first of the game's distance properties it has.

getDoorHinge ​

getDoorHinge(): StringSince1.8.4#
Returns the door hinge's serialized name: left or right.
// which side a door is hinged on
const door = Client.getRegistryManager()
  .getBlockState("minecraft:oak_door", "[hinge=left,open=true]").getUniversal();
Chat.log(`hinge ${door.getDoorHinge()}, open ${door.isOpen()}`);
Returns: the serialized name of the DOOR_HINGE property's value

getDoubleBlockHalf ​

getDoubleBlockHalf(): StringSince1.8.4#
Returns: the serialized value of the DOUBLE_BLOCK_HALF property.

getDusted ​

getDusted(): intSince1.9.0#
Returns: the copper bulb's oxidation level.

getEastWallShape ​

getEastWallShape(): StringSince1.8.4#
Returns: the EAST_WALL property's value, as the name the game gives it.

getEastWireConnection ​

getEastWireConnection(): StringSince1.8.4#
Returns: the EAST_REDSTONE property's value, as the name the game gives it.

getEggs ​

getEggs(): intSince1.8.4#
Returns: the EGGS property's value.

getFacing ​

getFacing(): DirectionHelperSince1.8.4#
Returns: the value of the FACING property as a direction.

getFlowerAmount ​

getFlowerAmount(): intSince1.9.0#
Returns: the flower bed's flower count.

getHatched ​

getHatched(): intSince1.8.4#
Returns: the HATCH property's value.

getHoneyLevel ​

getHoneyLevel(): intSince1.8.4#
Returns: the value of the LEVEL_HONEY property (0–5).

getHopperFacing ​

getHopperFacing(): DirectionHelperSince1.8.4#
Returns: the value of the FACING_HOPPER property as a direction.

getHorizontalAxis ​

getHorizontalAxis(): StringSince1.8.4#
Returns: the serialized value of the HORIZONTAL_AXIS property.

getHorizontalFacing ​

getHorizontalFacing(): DirectionHelperSince1.8.4#
Returns: the value of the HORIZONTAL_FACING property as a direction.

getInstrument ​

getInstrument(): StringSince1.8.4#
Returns the note-block instrument's serialized name, such as harp or bell.
// what a note block is set to
const reg = Client.getRegistryManager();
for (const name of ["harp", "basedrum", "snare", "hat", "guitar", "bell", "chime"]) {
  const note = reg.getBlockState("minecraft:note_block", `[instrument=${name}]`).getUniversal();
  Chat.log(`${note.getInstrument()} is note ${note.getNote()}`);
}
Returns: the serialized name of the NOTEBLOCK_INSTRUMENT property's value

getLayers ​

getLayers(): intSince1.8.4#
Returns: the LAYERS property's value.

getLevel ​

getLevel(): intSince1.8.4#
Returns the value of the first present level property, checking flowing-fluid, cauldron, composter, then generic level.
// the level of a fluid, and the same number through the property map
const reg = Client.getRegistryManager();
const water = reg.getFluidState("minecraft:water").getBlockState().getUniversal();
Chat.log(`level ${water.getLevel()}, between ${water.getMinLevel()} and ${water.getMaxLevel()}`);

// and a block with no level property at all
try {
  reg.getBlockState("minecraft:stone").getUniversal().getLevel();
} catch (e) {
  Chat.log("stone has no level");
}
Returns: the value of the first present level property.

getMaxAge ​

getMaxAge(): intSince1.8.4#
Returns the maximum possible value of the first present age property, using the same property order as getAge().
Returns: the maximum possible value of the first present age property.

getMaxDistance ​

getMaxDistance(): intSince1.8.4#
Returns the maximum possible value of the first present distance property, in the order described by getDistance().
Returns: the largest value the distance property this state has can hold.

getMaxLevel ​

getMaxLevel(): intSince1.8.4#
Returns the greatest allowed value of the first present level property, checking the same properties in the same order as getLevel().
// the range a level can take here
const lava = Client.getRegistryManager().getFluidState("minecraft:lava")
  .getBlockState().getUniversal();
Chat.log(`${lava.getMinLevel()} to ${lava.getMaxLevel()}`);
Returns: the greatest allowed value of the first present level property.

getMinDistance ​

getMinDistance(): intSince1.8.4#
Returns the minimum possible value of the first present distance property, in the order described by getDistance().
Returns: the smallest value the distance property this state has can hold.

getMinLevel ​

getMinLevel(): intSince1.8.4#
Returns the smallest allowed value of the first present level property, using the same property order as getLevel().
Returns: the smallest value the level property this state has can hold.

getMoisture ​

getMoisture(): intSince1.8.4#
Returns: the MOISTURE property's value.

getNorthWallShape ​

getNorthWallShape(): StringSince1.8.4#
Returns: the NORTH_WALL property's value, as the name the game gives it.

getNorthWireConnection ​

getNorthWireConnection(): StringSince1.8.4#
Returns: the NORTH_REDSTONE property's value, as the name the game gives it.

getNote ​

getNote(): intSince1.8.4#
Returns: the NOTE property's value.

getOrientation ​

getOrientation(): StringSince1.8.4#
Returns: the serialized value of the ORIENTATION property.

getPickles ​

getPickles(): intSince1.8.4#
Returns: the PICKLES property's value.

getPistonType ​

getPistonType(): StringSince1.8.4#
Returns the piston-head type's serialized name: normal or sticky.
// sticky and not
for (const type of ["normal", "sticky"]) {
  const piston = Client.getRegistryManager()
    .getBlockState("minecraft:piston_head", `[type=${type},facing=up]`).getUniversal();
  Chat.log(`${piston.getPistonType()}, facing ${piston.getFacing().getName()}`);
}
Returns: the serialized name of the PISTON_TYPE property's value

getPower ​

getPower(): intSince1.8.4#
Returns: the POWER property's value.

getRailShape ​

getRailShape(): StringSince1.8.4#
Returns: the serialized value of the RAIL_SHAPE property.

getRotation ​

getRotation(): intSince1.8.4#
Returns: the block's rotation in one of 16 steps.

getSculkSensorPhase ​

getSculkSensorPhase(): StringSince1.8.4#
Returns: the sculk sensor phase's serialized name.

getSlabType ​

getSlabType(): StringSince1.8.4#
Returns: the serialized name of the SLAB_TYPE property's value.

getSouthWallShape ​

getSouthWallShape(): StringSince1.8.4#
Returns: the SOUTH_WALL property's value, as the name the game gives it.

getSouthWireConnection ​

getSouthWireConnection(): StringSince1.8.4#
Returns: the SOUTH_REDSTONE property's value, as the name the game gives it.

getStage ​

getStage(): intSince1.8.4#
Returns: the STAGE property's value.

getStairShape ​

getStairShape(): StringSince1.8.4#
Returns the stair shape's serialized name: straight, inner_left, inner_right, outer_left, or outer_right.
// the five shapes a stair can be
for (const shape of ["straight", "inner_left", "inner_right", "outer_left", "outer_right"]) {
  const stair = Client.getRegistryManager()
    .getBlockState("minecraft:oak_stairs", `[shape=${shape}]`).getUniversal();
  Chat.log(`${stair.getStairShape()}, half ${stair.getBlockHalf()}`);
}
Returns: the serialized name of the STAIRS_SHAPE property's value

getStraightRailShape ​

getStraightRailShape(): StringSince1.8.4#
Returns: the serialized value of the RAIL_SHAPE_STRAIGHT property.

getStructureBlockMode ​

getStructureBlockMode(): StringSince1.8.4#
Returns: the serialized name of the STRUCTUREBLOCK_MODE property.

getThickness ​

getThickness(): StringSince1.8.4#
Returns: the serialized name of the DRIPSTONE_THICKNESS/SPELEOTHEM_THICKNESS property.

getTilt ​

getTilt(): StringSince1.8.4#
Returns: the serialized name of the TILT property.

getTrialSpawnerState ​

getTrialSpawnerState(): StringSince2.0.0#
Returns: the trial spawner state's serialized name.

getVaultState ​

getVaultState(): StringSince2.0.0#
Returns: the vault state's serialized name.

getVerticalDirection ​

getVerticalDirection(): StringSince1.8.4#
Returns: the serialized name of the VERTICAL_DIRECTION property.

getWestWallShape ​

getWestWallShape(): StringSince1.8.4#
Returns: the WEST_WALL property's value, as the name the game gives it.

getWestWireConnection ​

getWestWireConnection(): StringSince1.8.4#
Returns: the WEST_REDSTONE property's value, as the name the game gives it.

hasBerries ​

hasBerries(): booleanSince1.8.4#
Returns: the BERRIES property's value.

hasBook ​

hasBook(): booleanSince1.8.4#
Returns the state's HAS_BOOK property.
Returns: whether the state's HAS_BOOK property is true

hasBottle0 ​

hasBottle0(): booleanSince1.8.4#
Returns the state's HAS_BOTTLE_0 property.
Returns: whether the state's HAS_BOTTLE_0 property is true

hasBottle1 ​

hasBottle1(): booleanSince1.8.4#
Returns the state's HAS_BOTTLE_1 property.
Returns: whether the state's HAS_BOTTLE_1 property is true

hasBottle2 ​

hasBottle2(): booleanSince1.8.4#
Returns the state's HAS_BOTTLE_2 property.
Returns: whether the state's HAS_BOTTLE_2 property is true

hasEye ​

hasEye(): booleanSince1.8.4#
Returns: the EYE property's value; present on end portal frames.

hasRecord ​

hasRecord(): booleanSince1.8.4#
Returns the state's HAS_RECORD property.
Returns: whether the state's HAS_RECORD property is true

isAttached ​

isAttached(): booleanSince1.8.4#
Returns: the ATTACHED property's value; present on tripwire hooks.

isBloom ​

isBloom(): booleanSince1.8.4#
Returns: whether this block state has bloom enabled.

isBottom ​

isBottom(): booleanSince1.8.4#
Returns: whether the state's BOTTOM property is true.

isBubbleColumnDown ​

isBubbleColumnDown(): booleanSince1.8.4#
Returns: the DRAG property value; true indicates downward bubble-column motion.

isBubbleColumnUp ​

isBubbleColumnUp(): booleanSince1.8.4#
Returns: the negation of the DRAG property; true indicates upward bubble-column motion.

isConditional ​

isConditional(): booleanSince1.8.4#
Returns: the CONDITIONAL property's value; present on command blocks.

isCracked ​

isCracked(): booleanSince1.9.0#
Returns: whether the decorated pot is cracked.

isCrafting ​

isCrafting(): booleanSince2.0.0#
Returns: whether the crafter is crafting.

isDisarmed ​

isDisarmed(): booleanSince1.8.4#
Returns: the DISARMED property's value; present on tripwire.

isDown ​

isDown(): booleanSince1.8.4#
Returns: whether the state's DOWN property is true.

isEast ​

isEast(): booleanSince1.8.4#
Returns: whether the state's EAST property is true.

isEnabled ​

isEnabled(): booleanSince1.8.4#
Returns: the ENABLED property's value; present on hoppers.

isExtended ​

isExtended(): booleanSince1.8.4#
Returns: the EXTENDED property's value; present on pistons.

isFalling ​

isFalling(): booleanSince1.8.4#
Returns: the FALLING property's value; present on fluids.

isHanging ​

isHanging(): booleanSince1.8.4#
Returns the state's HANGING property.
Returns: whether the state's HANGING property is true

isInverted ​

isInverted(): booleanSince1.8.4#
Returns the state's INVERTED property.
Returns: whether the state's INVERTED property is true

isInWall ​

isInWall(): booleanSince1.8.4#
Returns the state's IN_WALL property.
Returns: whether the state's IN_WALL property is true

isLit ​

isLit(): booleanSince1.8.4#
Returns the state's LIT property.
Returns: the LIT property's value.

isLocked ​

isLocked(): booleanSince1.8.4#
Returns the state's LOCKED property.
Returns: the LOCKED property's value.

isNorth ​

isNorth(): booleanSince1.8.4#
Returns: whether the state's NORTH property is true.

isOccupied ​

isOccupied(): booleanSince1.8.4#
Returns the state's OCCUPIED property.
Returns: the OCCUPIED property's value.

isOminous ​

isOminous(): booleanSince2.0.0#
Returns: whether the vault is ominous.

isOpen ​

isOpen(): booleanSince1.8.4#
Returns the state's OPEN property.
Returns: whether the state's OPEN property is true

isPersistent ​

isPersistent(): booleanSince1.8.4#
Returns the state's PERSISTENT property.
Returns: the PERSISTENT property's value.

isPowered ​

isPowered(): booleanSince1.8.4#
Returns the state's POWERED property.
Returns: the POWERED property's value.

isShort ​

isShort(): booleanSince1.8.4#
Returns: the SHORT property's value; present on piston heads.

isShrieking ​

isShrieking(): booleanSince1.8.4#
Returns: whether this sculk sensor is shrieking.

isSignalFire ​

isSignalFire(): booleanSince1.8.4#
Returns the state's SIGNAL_FIRE property.
Returns: the SIGNAL_FIRE property's value.

isSlot0Occupied ​

isSlot0Occupied(): booleanSince1.8.4#
Returns: whether chiseled bookshelf slot 0 is occupied.

isSlot1Occupied ​

isSlot1Occupied(): booleanSince1.8.4#
Returns: the SLOT_1_OCCUPIED property's value.

isSlot2Occupied ​

isSlot2Occupied(): booleanSince1.8.4#
Returns: the SLOT_2_OCCUPIED property's value.

isSlot3Occupied ​

isSlot3Occupied(): booleanSince1.8.4#
Returns: the SLOT_3_OCCUPIED property's value.

isSlot4Occupied ​

isSlot4Occupied(): booleanSince1.8.4#
Returns: whether chiseled bookshelf slot 4 is occupied.

isSlot5Occupied ​

isSlot5Occupied(): booleanSince1.8.4#
Returns: whether chiseled bookshelf slot 5 is occupied.

isSnowy ​

isSnowy(): booleanSince1.8.4#
Returns the state's SNOWY property.
Returns: the SNOWY property's value.

isSouth ​

isSouth(): booleanSince1.8.4#
Returns: whether the state's SOUTH property is true.

isTriggered ​

isTriggered(): booleanSince1.8.4#
Returns the state's TRIGGERED property.
Returns: the TRIGGERED property's value.

isUnstable ​

isUnstable(): booleanSince1.8.4#
Returns the state's UNSTABLE property.
Returns: the UNSTABLE property's value.

isUp ​

isUp(): booleanSince1.8.4#
Returns: whether the state's UP property is true.

isWaterlogged ​

isWaterlogged(): booleanSince1.8.4#
Returns whether this state's WATERLOGGED property is true.
// is there water in this block rather than around it
const reg = Client.getRegistryManager();
const dry = reg.getBlockState("minecraft:oak_fence", "[waterlogged=false]").getUniversal();
const wet = reg.getBlockState("minecraft:oak_fence", "[waterlogged=true]").getUniversal();
Chat.log(`dry ${dry.isWaterlogged()}, wet ${wet.isWaterlogged()}`);

// and what the wet one actually holds
const state = reg.getBlockState("minecraft:oak_fence", "[waterlogged=true]");
Chat.log(state.getFluidState().getId());
Returns: the WATERLOGGED property's value

isWest ​

isWest(): booleanSince1.8.4#
Returns: whether the state's WEST property is true.

main ​

static main(String[] args): void#
Prints candidate accessor snippets for declared block-state properties without a matching accessor, followed by method names left unmatched by the diagnostic. The printed snippets are suggestions, not guaranteed compilable source.

Parameters:

  • args: unused command-line arguments