diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/Ext.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/Ext.kt index 4e8ea0863..e71a7cbed 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/Ext.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/Ext.kt @@ -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 CompoundTag.map(s: String, consumer: (T) -> R): R? { + val tag = get(s) + + if (tag is T) { + return consumer(tag) + } + + return null +} + +inline fun 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)