You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/invui2/inventory.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,18 +44,18 @@ InvUI's inventories have a powerful event system. There are multiple events that
44
44
45
45
#### ItemPreUpdateEvent
46
46
47
-
This event is called before changes were fully processed. Cancelling this event or changing the amount of items that were added or removed will affect the source of the change (i.e. the player's cursor most of the time) appropriately, if possible. This allows restricting which or how many items can be put into an inventory or even a specific slot of an inventory.
47
+
This event is called before changes were fully processed. Cancelling this event will affect the source of the change (i.e. the player's cursor most of the time) appropriately, if possible. This allows restricting which items can be put into an inventory or even a specific slot of an inventory.
48
48
49
-
In the following example, the `ItemPreUpdateEvent` is cancelled or handled in such a way that only red and orange wool can be put into the inventory. Additionally, orange wool can no longer be stacked:
49
+
In the following example, the `ItemPreUpdateEvent` is cancelled in such a way that only red wool can be placed on slot 10, and only orange wool can be placed on the other slots:
50
50
51
51
=== "Kotlin"
52
52
```kotlin
53
53
inv.addPreUpdateHandler { event ->
54
54
if (event.isAdd || event.isSwap) {
55
-
when (event.newItem?.type) {
56
-
Material.RED_WOOL -> Unit // red wool can be added normally
57
-
Material.ORANGE_WOOL -> event.newItem?.amount = 1 // orange wool stack size is limited to 1
58
-
else -> event.isCancelled = true // cancel event for all other item types
0 commit comments