Code Samples - DevNatan/inventory-framework GitHub Wiki
Counter
private final MutableIntState counterState = mutableState(0);
@Override
public void onInit(ViewConfigBuilder config) {
config.title("Counter")
.cancelOnClick()
.layout(" - # + ");
}
@Override
public void onFirstRender(RenderContext render) {
// Current count item
render.layoutSlot('#')
// The `watch` here updates the item when `counterState` updates
.watch(counterState)
.renderWith(() -> new ItemStack(
/* type = */ Material.GOLD_INGOT,
/* amount = */ counterState.get(render)
));
// Decrement button
render.layoutSlot('-', new ItemStack(Material.ARROW))
.onClick(counterState::decrement);
// Increment button
render.layoutSlot('+', new ItemStack(Material.ARROW))
.onClick(counterState::increment);
}