Skip to content

Commit b6e73e3

Browse files
committed
Update StructureRegistry.kt
1 parent ab7916c commit b6e73e3

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

common/src/main/kotlin/com/lambda/interaction/construction/StructureRegistry.kt

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ object StructureRegistry : ConcurrentHashMap<String, StructureTemplate>(), Loada
5959
private val serializers = mapOf(
6060
"nbt" to StructureTemplate::readNbtOrException,
6161
"schem" to StructureTemplate::readSpongeOrException,
62-
63-
// Not supported due to the clusterfuck codebase of litematica and basically zero documentation
6462
"litematic" to StructureTemplate::readLitematicaOrException,
6563

6664
// Not supported, who could've guess that converting a format from 15 years ago would be hard? :clueless:
@@ -151,9 +149,7 @@ object StructureRegistry : ConcurrentHashMap<String, StructureTemplate>(), Loada
151149
StructureTemplate().apply {
152150
serializers[suffix]
153151
?.invoke(this, Registries.BLOCK.readOnlyWrapper, nbt)
154-
?.let { error ->
155-
throw IllegalStateException("Could not create structure: ${error.message}")
156-
}
152+
?.let { throw it } // ToDo: Maybe use propagation instead of errors as values
157153
}
158154

159155
/**
@@ -182,13 +178,14 @@ object StructureRegistry : ConcurrentHashMap<String, StructureTemplate>(), Loada
182178
contains("DataVersion") && contains("blocks") && contains("palette") && contains("size")
183179

184180
override fun load(): String {
185-
runCatching {
186-
structure.walk()
187-
.filter { it.extension in serializers.keys }
188-
.sortedBy { it.extension.length } // Don’t walk lexicographically -Constructor
189-
.distinctBy { it.nameWithoutExtension }
190-
.forEach { loadStructureByRelativePath(structure.relativize(it)) }
191-
}.onFailure { LOG.warn("Error while loading a structure:", it) }
181+
structure.walk()
182+
.filter { it.extension in serializers.keys }
183+
.sortedBy { it.extension.length } // Don’t walk lexicographically -Constructor
184+
.distinctBy { it.nameWithoutExtension } // Pick the first structure in the priority list nbt > litematica > schematica
185+
.forEach { struct ->
186+
runCatching { loadStructureByRelativePath(structure.relativize(struct)) }
187+
.onFailure { LOG.warn("Unable to load the structure $struct: ${it.message}") }
188+
}
192189

193190
return "Loaded $size structure templates"
194191
}

0 commit comments

Comments
 (0)