diff --git a/build.gradle.kts b/build.gradle.kts index c2d5ba3..d292396 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "io.github.solid-resourcepack" -version = "1.1.0" +version = "1.1.1" repositories { mavenCentral() diff --git a/src/main/kotlin/io/github/solid/resourcepack/api/link/ModelLinkCollector.kt b/src/main/kotlin/io/github/solid/resourcepack/api/link/ModelLinkCollector.kt index 4eeba95..fd02b13 100644 --- a/src/main/kotlin/io/github/solid/resourcepack/api/link/ModelLinkCollector.kt +++ b/src/main/kotlin/io/github/solid/resourcepack/api/link/ModelLinkCollector.kt @@ -113,7 +113,9 @@ class ModelLinkCollector(private val packPath: Path) : ModelLinkHolder { val parsed = readModel(definition) parsed?.collect()?.let { result.addAll(it.filter { m -> - basePaths.any { path -> packPath.resolve(path).resolve(toModelPath(m.key)).exists() } + basePaths.any { basePath -> + packPath.resolve(basePath).resolve(toModelPath(m.key)).exists() && m.key.namespace() == path.last().toString() + } }) } } catch (e: Exception) { @@ -135,15 +137,23 @@ class ModelLinkCollector(private val packPath: Path) : ModelLinkHolder { } - private fun MutableList.combine(other: List, check: (first: T, second: T) -> Boolean): List { + private fun MutableList.combine(other: List, check: (first: ModelLink, second: ModelLink) -> Boolean): List { other.forEach { element -> val found = this.find { check(element, it) }?.let { this.indexOf(it) } if (found == null) { this.add(element) return@forEach } + val toReplace = this.elementAt(found) + val result = ModelLink( + key = toReplace.key, + parent = element.parent ?: toReplace.parent, + itemModel = element.itemModel ?: toReplace.itemModel, + modelType = toReplace.modelType, + predicates = element.predicates ?: toReplace.predicates, + ) this.removeAt(found) - this.add(found, element) + this.add(found, result) } return this } diff --git a/src/main/kotlin/io/github/solid/resourcepack/api/link/ModelLinkHolder.kt b/src/main/kotlin/io/github/solid/resourcepack/api/link/ModelLinkHolder.kt index 4159552..b491cf1 100644 --- a/src/main/kotlin/io/github/solid/resourcepack/api/link/ModelLinkHolder.kt +++ b/src/main/kotlin/io/github/solid/resourcepack/api/link/ModelLinkHolder.kt @@ -9,6 +9,7 @@ interface ModelLinkHolder { data class ModelLink( val key: Key, val parent: Key? = null, + val itemModel: Key? = null, val predicates: Map? = null, val modelType: ModelType = ModelType.ITEM, ) diff --git a/src/main/kotlin/io/github/solid/resourcepack/api/link/modern/ModernResourcePackItemLink.kt b/src/main/kotlin/io/github/solid/resourcepack/api/link/modern/ModernResourcePackItemLink.kt index ec56268..c18b6f3 100644 --- a/src/main/kotlin/io/github/solid/resourcepack/api/link/modern/ModernResourcePackItemLink.kt +++ b/src/main/kotlin/io/github/solid/resourcepack/api/link/modern/ModernResourcePackItemLink.kt @@ -13,9 +13,16 @@ data class ModernResourcePackLink( val model: ModernResourcePackModel? = null ) : ModelLinkHolder { override fun collect(): List { - if (model?.model == null) { return listOf() } + if (model?.model == null) { + return listOf() + } if (model.type != Key.key("minecraft", "model")) return listOf() - return listOf(ModelLink(model.model)) + return listOf( + ModelLink( + model.model, + itemModel = Key.key(model.model.namespace(), model.model.value().replaceFirst("item/", "")) + ) + ) } } diff --git a/src/test/kotlin/io/github/solid/resourcepack/api/link/ModelLinkCollectorTest.kt b/src/test/kotlin/io/github/solid/resourcepack/api/link/ModelLinkCollectorTest.kt index e6f005b..ba279de 100644 --- a/src/test/kotlin/io/github/solid/resourcepack/api/link/ModelLinkCollectorTest.kt +++ b/src/test/kotlin/io/github/solid/resourcepack/api/link/ModelLinkCollectorTest.kt @@ -12,6 +12,19 @@ class ModelLinkCollectorTest { val path = Path.of("src", "test", "kotlin", "pack") println(path.toAbsolutePath().toString()) val collector = ModelLinkCollector(path) - assert(collector.collect().isNotEmpty()) + val result = collector.collect() + printResult(result) + assert(result.isNotEmpty()) + } + + private fun printResult(result: List) { + result.forEach { + println("Key: " + it.key) + println("Type: " + it.modelType) + println("Item Model: " + it.itemModel) + println("Parent: " + it.parent) + println("Predicates: " + it.predicates) + println("---") + } } } \ No newline at end of file