FluidStateHelper
com.jsmacrosce.jsmacros.client.api.helper.world.FluidStateHelper
A fluid state describes a fluid type and its state properties. BlockStateHelper.getFluidState() returns an empty state rather than null for blocks without fluid; registry lookups by fluid id return the fluid type's default state. Properties are exposed through StateHelper.toMap() and StateHelper.with(String, String).
js
// is there a fluid in the block the player is standing on
const under = World.getBlock(Player.getPlayer().getBlockPos().down());
if (under !== null) {
const fluid = under.getBlockStateHelper().getFluidState();
if (fluid.isEmpty()) {
Chat.log("dry ground");
} else {
Chat.log(`${fluid.getId()} at level ${fluid.getLevel()}, still: ${fluid.isStill()}`);
}
}
// the same fluid, straight out of the registry
const lava = Client.getRegistryManager().getFluidState("minecraft:lava");
Chat.log(`${lava.getId()} has blast resistance ${lava.getBlastResistance()}`);Constructors
new FluidStateHelper
new FluidStateHelper(FluidState base)#Wraps the supplied fluid state.
Parameters:
base: raw fluid state to wrap.
Methods
getBlastResistance
Returns the explosion resistance of this fluid type; it does not vary by fluid state.
Returns: the blast resistance of this fluid.
getBlockState
Returns the block state produced from this fluid state by the game's legacy block conversion.
Returns: the block state of this fluid.
getHeight
Returns this state type's own height as a fraction of a block, without considering the surrounding world. This may differ from the world- and position-dependent fluid height.
Returns: this state's own height as a fraction of a block.
getId
getLevel
Returns the fluid amount on the game's scale. Source states return
8; flowing states return their level property, in the range one through eight. Unlike flowing states, source states have no level property in StateHelper.toMap(). This amount is distinct from getHeight(), which is defined by the fluid type.Returns: the fluid amount on the game's scale.
getVelocity
Returns the flow vector computed for this fluid state and position using the currently loaded client level. A loaded level is required.
// which way the current runs, at the block under the player
const pos = Player.getPlayer().getBlockPos().down();
const block = World.getBlock(pos);
if (block !== null) {
const fluid = block.getBlockStateHelper().getFluidState();
if (!fluid.isEmpty()) {
const flow = fluid.getVelocity(block.getBlockPos());
Chat.log(`flowing ${flow.getX()}, ${flow.getY()}, ${flow.getZ()}`);
if (flow.getY() > 0) {
Chat.log("falling");
}
}
}Parameters:
pos: position used to compute the flow
Returns: the computed flow vector.
hasRandomTicks
Returns whether this fluid type is marked as randomly ticking.
Returns:
true if this fluid type is randomly ticking; false otherwise.isEmpty
Returns whether this is the empty fluid state.
Returns:
true if this fluid is empty; false otherwise.isStill
Returns whether this state is a source state.
Returns:
true if this fluid is still, false otherwise.