CompoundTag.map and CompoundTag.ifCompound
This commit is contained in:
parent
d80c1915f6
commit
427fd43ea0
@ -111,6 +111,26 @@ operator fun IItemHandler.get(index: Int): ItemStack = getStackInSlot(index)
|
||||
|
||||
operator fun JsonObject.set(s: String, value: JsonElement) = add(s, value)
|
||||
|
||||
inline fun <R, reified T : Tag> CompoundTag.map(s: String, consumer: (T) -> R): R? {
|
||||
val tag = get(s)
|
||||
|
||||
if (tag is T) {
|
||||
return consumer(tag)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
inline fun <T> CompoundTag.ifCompound(s: String, consumer: (CompoundTag) -> T): T? {
|
||||
val tag = get(s)
|
||||
|
||||
if (tag is CompoundTag) {
|
||||
return consumer(tag)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
inline fun CompoundTag.ifHas(s: String, consumer: (Tag) -> Unit) {
|
||||
val tag = get(s)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user