Added support to add custom item containers via plugins
Code:
val CUSTOM_ITEM_CONTAINER = ContainerKey("custom_container", capacity = 28, stackType = ContainerStackType.NORMAL)
/**
* Register the container key so the player de-serializer knows the capacity
* and stack type when loading the container.
*/
register_container_key(CUSTOM_ITEM_CONTAINER)
on_command("add") {
add_item_to_container(player, Item(Items.ABYSSAL_WHIP))
}
fun add_item_to_container(p: Player, item: Item) {
val container = p.containers.computeIfAbsent(CUSTOM_ITEM_CONTAINER) { ItemContainer(p.world.definitions, CUSTOM_ITEM_CONTAINER) }
container.add(item)
}
The register_container_key is something I didn't want to require when a plugin wants to serialize/deserialize a custom item container, however I thought of several issues that could come with serializing the capacity/stack type on the item containers themselves in player data (apart from not belonging there in the first place).
This is then saved as (using JSON in this example):
Code:
"itemContainers": [
{
"name": "custom_container",
"items": {
"0": {
"id": 4151,
"amount": 1
}
}
},
{
"name": "inventory",
"items": {
"0": {
"id": 4151,
"amount": 1
},
"1": {
"id": 11941,
"amount": 1
}
}
}
],