-
Notifications
You must be signed in to change notification settings - Fork 0
Common Errors
Here are some common errors that you may encounter using KInventory, and how to work around them.
When working with the DefaultedList
s that Minecraft generally uses to store the ItemStack
s in inventories, you may encounter an UnsupportedOperationException
. This happens because Kotlin (quite rightly) sees DefaultedList
as a list, and tries to be helpful and add its own functions to be run on a list. The problem is that these conflict with DefaultedList
's own functions, and throw this error.
The solution is to use DefaultedList<E>.set()
, which is identical to add()
except it returns the element that you set. However, it crucially doesn't shadow a Kotlin method, so you can use it without causing an error.
This error occurs when you try to serialize a class with private values in the constructor. While such a class will compile, actually trying to serialize it will make kotlinx.serialization attempt to access a private variable which throws this error. The solution is to modify the access of that variable to either public or internal (internal makes the variable public but only within your code. Other users who depend on your code will not see it).