2. Content Provider
Now, you maybe want to know how to put items in your new inventory. To do that, you'll need to create a new InventoryProvider.
InventoryProvider is an interface, so you just need to implements it, example:
Here, the method init
will be called when an inventory is opened for the player, and the method update
will be called every tick for the players with the inventory opened.
To put the items in the inventory, you just have to use the methods of the given InventoryContents
, like fillRow(row, item)
. Theses methods requires a ClickableItem
, which is just an ItemStack
combined with a Consumer<InventoryClickEvent>
.
To create a ClickableItem
, you just have to use ClickableItem.of(ItemStack, Consumer<InventoryClickEvent>)
, or Clickable.empty(ItemStack)
to create an item with an empty consumer, example:
All the SmartInvs methods which asks for a row
and a column
have an overload method which asks for a SlotPos
you can build using SlotPos.of(row, column)
, these SlotPos are totally immutables.
This is a list of all the InventoryContents
methods you can use to play with the inventory items:
If you need to set properties to your InventoryContents, you can use the setProperty(String name, Object value)
method, to get the properties, use property(String name)
or property(String name, T def)
to provide a default value.
Each opened inventory has a different InventoryContents, so when you create an iterator or set a property, it will only be saved for the opened inventory o the actual player.
Example
And this is the result of this provider, when applied to a basic chest inventory with 3 rows:
In this example, I didn't used the update
method, but you can use it exactly like the init
method.
Last updated