Skip to content

Commit 14dab0e

Browse files
committed
feat: better filter for modern links
1 parent 781868f commit 14dab0e

File tree

3 files changed

+43
-33
lines changed

3 files changed

+43
-33
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# solid-api ![Maven Central Version](https://img.shields.io/maven-central/v/io.github.solid-resourcepack/solid-api?style=flat) ![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/solid-resourcepack/solid-api)
1+
# solid-api ![Maven Central Version](https://img.shields.io/maven-central/v/io.github.solidpack/solid-api?style=flat) ![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/solidpack/solid-api)
22
A (currently) read only API for minecraft resource packs.
33

44
> Documentation is still work in progress
@@ -7,17 +7,17 @@ A (currently) read only API for minecraft resource packs.
77

88
### Gradle Kotlin
99
```kt
10-
implementation("io.github.solid-resourcepack:solid-api:VERSION")
10+
implementation("io.github.solidpack:solid-api:VERSION")
1111
```
1212
### Gradle Groovy
1313
```groovy
14-
implementation 'io.github.solid-resourcepack:solid-api:VERSION'
14+
implementation 'io.github.solidpack:solid-api:VERSION'
1515
```
1616

1717
### Maven
1818
```xml
1919
<dependency>
20-
<groupId>io.github.solid-resourcepack</groupId>
20+
<groupId>io.github.solidpack</groupId>
2121
<artifactId>solid-api</artifactId>
2222
<version>VERSION</version>
2323
</dependency>

build.gradle.kts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ plugins {
88
`maven-publish`
99
}
1010

11-
group = "io.github.solid-resourcepack"
12-
version = "1.1.1"
11+
group = "io.github.solidpack"
12+
version = "1.1.2"
1313

1414
repositories {
1515
mavenCentral()
@@ -56,9 +56,9 @@ centralPortal {
5656
password = project.findProperty("sonatypePassword") as? String
5757

5858
pom {
59-
name.set("Solid")
60-
description.set("An API wrapper around unnamed/creative to make custom minecraft items/blocks with java edition resource packs easy for developers")
61-
url.set("https://github.com/solid-resourcepack/solid")
59+
name.set("Solid API")
60+
description.set("A read only API to make working with custom minecraft items/blocks with java edition resource packs easy for developers")
61+
url.set("https://github.com/solidpack/solid-api")
6262

6363
developers {
6464
developer {
@@ -73,8 +73,8 @@ centralPortal {
7373
}
7474
}
7575
scm {
76-
url.set("https://github.com/solid-resourcepack/solid")
77-
connection.set("git:git@github.com:solid-resourcepack/solid.git")
76+
url.set("https://github.com/solidpack/solid-api")
77+
connection.set("git:git@github.com:solidpack/solid-api.git")
7878
}
7979
}
8080
}

src/main/kotlin/io/github/solid/resourcepack/api/link/ModelLinkCollector.kt

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,40 +103,50 @@ class ModelLinkCollector(private val packPath: Path) : ModelLinkHolder {
103103
return result
104104
}
105105

106-
private fun collectModern(basePaths: List<Path>, path: Path): List<ModelLink> {
106+
private fun collectModern(basePaths: List<Path> = listOf(Paths.get("assets"))): List<ModelLink> {
107107
val result = mutableListOf<ModelLink>()
108-
val items = path.resolve("items")
109-
if (!items.exists()) return result
110-
items.listDirectoryEntries("*.json").forEach itemForEach@{ definition ->
111-
if (!definition.exists()) return@itemForEach
112-
try {
113-
val parsed = readModel<ModernResourcePackLink>(definition)
114-
parsed?.collect()?.let {
115-
result.addAll(it.filter { m ->
116-
basePaths.any { basePath ->
117-
packPath.resolve(basePath).resolve(toModelPath(m.key)).exists() && m.key.namespace() == path.last().toString()
118-
}
119-
})
120-
}
121-
} catch (e: Exception) {
122-
e.printStackTrace()
123-
}
108+
basePaths.map { packPath.resolve(it) }.forEach { baseDir ->
109+
if (!baseDir.exists()) return@forEach
110+
result.addAll(collectModernRecursively(basePaths, baseDir))
124111
}
125112
return result
126113
}
127114

128-
private fun collectModern(basePaths: List<Path> = listOf(Paths.get("assets"))): List<ModelLink> {
115+
private fun collectModernRecursively(basePaths: List<Path>, currentDir: Path): List<ModelLink> {
129116
val result = mutableListOf<ModelLink>()
130-
basePaths.map { packPath.resolve(it) }.forEach {
131-
if (!it.exists()) return@forEach
132-
it.listDirectoryEntries().filter { it.isDirectory() }.forEach { namespace ->
133-
result.addAll(collectModern(basePaths, namespace))
117+
118+
val itemsDir = currentDir.resolve("items")
119+
if (itemsDir.exists()) {
120+
itemsDir.listDirectoryEntries("*.json").forEach itemForEach@{ definition ->
121+
if (!definition.exists()) return@itemForEach
122+
try {
123+
val parsed = readModel<ModernResourcePackLink>(definition)
124+
parsed?.collect()?.let {
125+
result.addAll(it.filter { m ->
126+
basePaths.any { basePath ->
127+
packPath.resolve(basePath).resolve(toModelPath(m.key)).exists() &&
128+
m.key.namespace() == currentDir.last().toString()
129+
}
130+
})
131+
}
132+
} catch (e: Exception) {
133+
e.printStackTrace()
134+
}
134135
}
135136
}
137+
138+
// Recurse into subdirectories
139+
currentDir.listDirectoryEntries()
140+
.filter { it.isDirectory() }
141+
.forEach { subDir ->
142+
result.addAll(collectModernRecursively(basePaths, subDir))
143+
}
144+
136145
return result
137146
}
138147

139148

149+
140150
private fun MutableList<ModelLink>.combine(other: List<ModelLink>, check: (first: ModelLink, second: ModelLink) -> Boolean): List<ModelLink> {
141151
other.forEach { element ->
142152
val found = this.find { check(element, it) }?.let { this.indexOf(it) }

0 commit comments

Comments
 (0)