Skip to content

Commit cd147b7

Browse files
committed
Avoid structure load recursion
1 parent d051441 commit cd147b7

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import net.minecraft.nbt.NbtIo
3030
import net.minecraft.nbt.NbtSizeTracker
3131
import net.minecraft.registry.Registries
3232
import net.minecraft.structure.StructureTemplate
33+
import java.io.FileNotFoundException
3334
import java.nio.file.FileSystems
3435
import java.nio.file.Files
3536
import java.nio.file.Path
@@ -74,25 +75,26 @@ object StructureRegistry : ConcurrentHashMap<String, StructureTemplate>(), Loada
7475
* @param convert Whether to replace the file after converting it.
7576
*
7677
* @throws IllegalStateException if there was an error while parsing the data
78+
* @throws FileNotFoundException when the given path doesn't exist
7779
*/
7880
fun loadStructureByRelativePath(
7981
relativePath: Path,
8082
convert: Boolean = true,
8183
): StructureTemplate {
82-
updateFileWatcher()
84+
updateFileWatcher(convert)
8385

84-
val struct = loadFileAndCreate(relativePath, convert)
85-
putIfAbsent(relativePath.pathString.lowercase(), struct)
86+
val structure = loadFileAndCreate(relativePath, convert)
87+
putIfAbsent(relativePath.pathString, structure)
8688

87-
return struct
89+
return structure
8890
}
8991

9092
/**
9193
* Poll directory file events to load many structures at once.
9294
* They might not show up in the command suggestion, but they are
9395
* present in the map.
9496
*/
95-
private fun updateFileWatcher() {
97+
private fun updateFileWatcher(convert: Boolean) {
9698
pathWatcher.poll()?.let { key ->
9799
key.pollEvents()
98100
?.filterIsInstance<WatchEvent<Path>>()
@@ -102,8 +104,8 @@ object StructureRegistry : ConcurrentHashMap<String, StructureTemplate>(), Loada
102104
when (event.kind()) {
103105
ENTRY_DELETE -> remove(newPath.pathString)
104106
ENTRY_CREATE -> {
105-
putIfAbsent(newPath.pathString,
106-
loadStructureByRelativePath(newPath, convert = true))
107+
put(newPath.pathString,
108+
loadFileAndCreate(newPath, convert))
107109
}
108110
}
109111

0 commit comments

Comments
 (0)