LockButtonWidgetHelper
com.jsmacrosce.jsmacros.client.api.helper.screen.LockButtonWidgetHelper
A lock button toggles between locked and unlocked when pressed. Its Minecraft widget is fixed at 20 by 20 pixels; its builder's size settings do not change that.
IScreen.lockButtonBuilder() starts unlocked; its boolean overload sets the initial state.
js
const screen = Hud.createScreen("a screen", true);
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
const lock = self.lockButtonBuilder()
.pos(10, 20)
.action(JavaWrapper.methodToJava(function (btn) {
Chat.log(`locked: ${btn.isLocked()}`);
}))
.build();
// the state can be set outright, without going through a press
lock.setLocked(true);
Chat.log(`locked: ${lock.isLocked()}`);
}));
Hud.openScreen(screen);Available in scripts as Widgets.LockButton.
Nested types
Constructors
new LockButtonWidgetHelper
new LockButtonWidgetHelper(LockIconButton btn)#Wraps the supplied lock button with the default z-index of zero.
Parameters:
btn: the lock button to wrap
new LockButtonWidgetHelper(LockIconButton btn, int zIndex)#Wraps the supplied lock button with the given drawing-order z-index.
Parameters:
btn: the lock button to wrapzIndex: the helper's z-index for screen drawing order
Methods
isLocked
Returns the button's current locked state.
Returns:
true if the button is locked, false otherwise.setLocked
Sets the locked state directly without pressing the button or invoking its action. The visual state is used on the next render.
Parameters:
locked: whether to lock the button or not
Returns: self for chaining.