Fix inventory change trigger search tree NPE

This commit is contained in:
DBotThePony 2023-10-23 18:41:38 +07:00
parent 74f8e316b7
commit a04643e905
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -71,7 +71,7 @@ object MatteryInventoryChangeTrigger : CriterionTrigger<InventoryChangeTrigger.T
private class Node<T>(
val strategy: Strategy<in T?>,
private val getter: InventoryChangeTrigger.TriggerInstance.() -> Collection<T>,
val test: Tester<T>,
val test: Tester<T?>, // if hint is present, tester is always going to be called with `null` value once
val hint: Hint<T>? = null
) {
fun getValues(instance: InventoryChangeTrigger.TriggerInstance): Set<T> {
@ -84,9 +84,9 @@ object MatteryInventoryChangeTrigger : CriterionTrigger<InventoryChangeTrigger.T
private val nodes = ArrayList<Node<*>>()
init {
nodes.add(Node(BoundsStrategy, { listOf(slotsOccupied) }, { v, inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> v.matches(slotsOccupied) }))
nodes.add(Node(BoundsStrategy, { listOf(slotsFull) }, { v, inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> v.matches(slotsFull) }))
nodes.add(Node(BoundsStrategy, { listOf(slotsEmpty) }, { v, inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> v.matches(slotsEmpty) }))
nodes.add(Node(BoundsStrategy, { listOf(slotsOccupied) }, { v, inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> v!!.matches(slotsOccupied) }))
nodes.add(Node(BoundsStrategy, { listOf(slotsFull) }, { v, inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> v!!.matches(slotsFull) }))
nodes.add(Node(BoundsStrategy, { listOf(slotsEmpty) }, { v, inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> v!!.matches(slotsEmpty) }))
nodes.add(Node(
DefaultStrategy,
@ -96,16 +96,16 @@ object MatteryInventoryChangeTrigger : CriterionTrigger<InventoryChangeTrigger.T
nodes.add(Node(
DefaultStrategy,
{ predicates.map { it.tag as Optional<TagKey<Item>> } },
{ v, inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> v.isEmpty || item.`is`(v.get()) },
{ predicates.map { it.tag.orElse(null) } },
{ v, inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> v == null || item.`is`(v) },
{ inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> item.tags.collect(Collectors.toCollection(::ArrayList)) }))
nodes.add(Node(BoundsStrategy, { predicates.map { it.count } }, { v, inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> v.matches(item.count) }))
nodes.add(Node(BoundsStrategy, { predicates.map { it.count } }, { v, inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> v!!.matches(item.count) }))
nodes.add(Node(
BoundsStrategy,
{ predicates.map { it.durability } },
{ v, inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> v.isAny || item.isDamageableItem && v.matches(item.maxDamage - item.damageValue) }))
{ v, inventory: Container, item: ItemStack, slotsFull: Int, slotsEmpty: Int, slotsOccupied: Int -> v!!.isAny || item.isDamageableItem && v.matches(item.maxDamage - item.damageValue) }))
}
private class ListenerTree(private val advancements: PlayerAdvancements) {