Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "io.github.solid-resourcepack"
version = "1.1.0"
version = "1.1.1"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ class ModelLinkCollector(private val packPath: Path) : ModelLinkHolder {
val parsed = readModel<ModernResourcePackLink>(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) {
Expand All @@ -135,15 +137,23 @@ class ModelLinkCollector(private val packPath: Path) : ModelLinkHolder {
}


private fun <T> MutableList<T>.combine(other: List<T>, check: (first: T, second: T) -> Boolean): List<T> {
private fun MutableList<ModelLink>.combine(other: List<ModelLink>, check: (first: ModelLink, second: ModelLink) -> Boolean): List<ModelLink> {
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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface ModelLinkHolder {
data class ModelLink(
val key: Key,
val parent: Key? = null,
val itemModel: Key? = null,
val predicates: Map<String, Any>? = null,
val modelType: ModelType = ModelType.ITEM,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ data class ModernResourcePackLink(
val model: ModernResourcePackModel? = null
) : ModelLinkHolder {
override fun collect(): List<ModelLink> {
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/", ""))
)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModelLink>) {
result.forEach {
println("Key: " + it.key)
println("Type: " + it.modelType)
println("Item Model: " + it.itemModel)
println("Parent: " + it.parent)
println("Predicates: " + it.predicates)
println("---")
}
}
}