Some fixes for item filters
This commit is contained in:
parent
78fad5d3cc
commit
8454db6785
@ -22,9 +22,7 @@ data class ItemFilterSet(val filter: ImmutableSet<ItemFilter>, val isWhitelist:
|
||||
}
|
||||
|
||||
fun replace(index: Int, value: ItemFilter): ItemFilterSet {
|
||||
if (index !in filter.indices)
|
||||
throw IndexOutOfBoundsException("No such filter at index $index")
|
||||
else if (value in filter)
|
||||
if (index !in filter.indices || value in filter)
|
||||
return this
|
||||
|
||||
val values = ObjectArrayList(filter)
|
||||
@ -50,7 +48,7 @@ data class ItemFilterSet(val filter: ImmutableSet<ItemFilter>, val isWhitelist:
|
||||
|
||||
fun removeAt(index: Int): ItemFilterSet {
|
||||
if (index !in filter.indices)
|
||||
throw IndexOutOfBoundsException("No such filter at index $index")
|
||||
return this
|
||||
|
||||
if (filter.size == 1)
|
||||
return copy(filter = ImmutableSet.of())
|
||||
@ -65,7 +63,7 @@ data class ItemFilterSet(val filter: ImmutableSet<ItemFilter>, val isWhitelist:
|
||||
}
|
||||
|
||||
operator fun get(index: Int): ItemFilter {
|
||||
return filter.asList()[index]
|
||||
return filter.asList().getOrElse(index) { ItemFilter.EMPTY }
|
||||
}
|
||||
|
||||
fun clear(): ItemFilterSet {
|
||||
|
@ -16,8 +16,14 @@ class ItemFilterInput(menu: MatteryMenu, maxSlots: Int, var filter: Delegate<Ite
|
||||
|
||||
val inputs = immutableList(maxSlots) { i ->
|
||||
menu.PlayerInput(StreamCodecs.ITEM_FILTER, handler = {
|
||||
if (allowRecursive || it.depth <= 1)
|
||||
filter?.get()?.addOrReplace(i, it)
|
||||
if (allowRecursive || it.depth <= 1) {
|
||||
val filter = filter ?: return@PlayerInput
|
||||
|
||||
if (it.hasRules)
|
||||
filter.accept(filter.get().addOrReplace(i, it))
|
||||
else
|
||||
filter.accept(filter.get().removeAt(i))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user