inventory-framework icon indicating copy to clipboard operation
inventory-framework copied to clipboard

Timeable out item render

Open DevNatan opened this issue 2 years ago • 0 comments

Allow user to render an item only for a duration. Currently it is possible to use a workaround with context data to do this but it is very complex, it must be implemented in the IF itself.

With duration as parameter of setItem combined with onUpdate

By default the rendered item will be the fallback item PAPER, when updated it will set to the item DIAMOND for 3 seconds and return to PAPER.

slot(10, new ItemStack(Material.PAPER))
    .onUpdate(update -> update.setItem(new ItemStack(Material.DIAMOND, Duration.ofSeconds(3)))
    .onClick(ViewSlotContext::updateSlot);

It will also be possible to do conditional rendering together with onRender

slot(10)
    .onRender(render -> render.setItem(new ItemStack(Material.PAPER)))
    .onUpdate(update -> update.setItem(new ItemStack(Material.DIAMOND, 10L /* ticks */))
    .onClick(ViewSlotContext::updateSlot);

The item rendering chain will continue to work. As soon as the render duration of the timeout item update expires, the render function will be called and if null returns to fallback. As it is now.

slot(10, /* fallback */)
    .onRender(render -> render.setItem(true ? null : new ItemStack(Material.PAPER)))
    .onUpdate(update -> update.setItem(new ItemStack(Material.DIAMOND, 10L /* ticks */))
    .onClick(ViewSlotContext::updateSlot);

DevNatan avatar Apr 23 '22 15:04 DevNatan