UniversalBlockStateHelper
com.jsmacrosce.jsmacros.client.api.helper.world.UniversalBlockStateHelper
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
Returns: whether this sculk sensor can summon.
getAge
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
getAxis
getBambooLeaves
getBedPart
getBites
Returns: the
BITES property's value.getBlockFace
getBlockHalf
getCandles
Returns: the
CANDLES property's value.getCharges
Returns: the respawn anchor's charge count.
getChestType
getComparatorMode
getDelay
Returns the state's
DELAY property.Returns: the
DELAY property's value.getDistance
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
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 valuegetDoubleBlockHalf
getDusted
Returns: the copper bulb's oxidation level.
getEastWallShape
getEastWireConnection
getEggs
Returns: the
EGGS property's value.getFacing
Returns: the value of the
FACING property as a direction.getFlowerAmount
Returns: the flower bed's flower count.
getHatched
Returns: the
HATCH property's value.getHoneyLevel
Returns: the value of the
LEVEL_HONEY property (0–5).getHopperFacing
Returns: the value of the
FACING_HOPPER property as a direction.getHorizontalAxis
getHorizontalFacing
Returns: the value of the
HORIZONTAL_FACING property as a direction.getInstrument
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 valuegetLayers
Returns: the
LAYERS property's value.getLevel
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
getMaxDistance
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
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
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
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
Returns: the
MOISTURE property's value.getNorthWallShape
getNorthWireConnection
getNote
Returns: the
NOTE property's value.getOrientation
getPickles
Returns: the
PICKLES property's value.getPistonType
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 valuegetPower
Returns: the
POWER property's value.getRailShape
getRotation
Returns: the block's rotation in one of 16 steps.
getSculkSensorPhase
getSlabType
getSouthWallShape
getSouthWireConnection
getStage
Returns: the
STAGE property's value.getStairShape
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 valuegetStraightRailShape
getStructureBlockMode
getThickness
getTilt
getTrialSpawnerState
getVaultState
getVerticalDirection
getWestWallShape
getWestWireConnection
hasBerries
Returns: the
BERRIES property's value.hasBook
Returns the state's
HAS_BOOK property.Returns: whether the state's
HAS_BOOK property is truehasBottle0
Returns the state's
HAS_BOTTLE_0 property.Returns: whether the state's
HAS_BOTTLE_0 property is truehasBottle1
Returns the state's
HAS_BOTTLE_1 property.Returns: whether the state's
HAS_BOTTLE_1 property is truehasBottle2
Returns the state's
HAS_BOTTLE_2 property.Returns: whether the state's
HAS_BOTTLE_2 property is truehasEye
Returns: the
EYE property's value; present on end portal frames.hasRecord
Returns the state's
HAS_RECORD property.Returns: whether the state's
HAS_RECORD property is trueisAttached
Returns: the
ATTACHED property's value; present on tripwire hooks.isBloom
Returns: whether this block state has bloom enabled.
isBottom
Returns: whether the state's
BOTTOM property is true.isBubbleColumnDown
Returns: the
DRAG property value; true indicates downward bubble-column motion.isBubbleColumnUp
Returns: the negation of the
DRAG property; true indicates upward bubble-column motion.isConditional
Returns: the
CONDITIONAL property's value; present on command blocks.isCracked
Returns: whether the decorated pot is cracked.
isCrafting
Returns: whether the crafter is crafting.
isDisarmed
Returns: the
DISARMED property's value; present on tripwire.isDown
Returns: whether the state's
DOWN property is true.isEast
Returns: whether the state's
EAST property is true.isEnabled
Returns: the
ENABLED property's value; present on hoppers.isExtended
Returns: the
EXTENDED property's value; present on pistons.isFalling
Returns: the
FALLING property's value; present on fluids.isHanging
Returns the state's
HANGING property.Returns: whether the state's
HANGING property is trueisInverted
Returns the state's
INVERTED property.Returns: whether the state's
INVERTED property is trueisInWall
Returns the state's
IN_WALL property.Returns: whether the state's
IN_WALL property is trueisLit
Returns the state's
LIT property.Returns: the
LIT property's value.isLocked
Returns the state's
LOCKED property.Returns: the
LOCKED property's value.isNorth
Returns: whether the state's
NORTH property is true.isOccupied
Returns the state's
OCCUPIED property.Returns: the
OCCUPIED property's value.isOminous
Returns: whether the vault is ominous.
isOpen
Returns the state's
OPEN property.Returns: whether the state's
OPEN property is trueisPersistent
Returns the state's
PERSISTENT property.Returns: the
PERSISTENT property's value.isPowered
Returns the state's
POWERED property.Returns: the
POWERED property's value.isShort
Returns: the
SHORT property's value; present on piston heads.isShrieking
Returns: whether this sculk sensor is shrieking.
isSignalFire
Returns the state's
SIGNAL_FIRE property.Returns: the
SIGNAL_FIRE property's value.isSlot0Occupied
Returns: whether chiseled bookshelf slot 0 is occupied.
isSlot1Occupied
Returns: the
SLOT_1_OCCUPIED property's value.isSlot2Occupied
Returns: the
SLOT_2_OCCUPIED property's value.isSlot3Occupied
Returns: the
SLOT_3_OCCUPIED property's value.isSlot4Occupied
Returns: whether chiseled bookshelf slot 4 is occupied.
isSlot5Occupied
Returns: whether chiseled bookshelf slot 5 is occupied.
isSnowy
Returns the state's
SNOWY property.Returns: the
SNOWY property's value.isSouth
Returns: whether the state's
SOUTH property is true.isTriggered
Returns the state's
TRIGGERED property.Returns: the
TRIGGERED property's value.isUnstable
Returns the state's
UNSTABLE property.Returns: the
UNSTABLE property's value.isUp
Returns: whether the state's
UP property is true.isWaterlogged
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 valueisWest
Returns: whether the state's
WEST property is true.main
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