CompoundTag.map and CompoundTag.ifCompound

This commit is contained in:
DBotThePony 2022-09-01 19:32:24 +07:00
parent d80c1915f6
commit 427fd43ea0
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -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)