Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit c92e26c

Browse files
committed
perf: improve speed of space validating
1 parent d815efd commit c92e26c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/kotlin/scpsharp/content/facility/generator/FacilityGenerator.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class FacilityGenerator(
7373
fun isChunkLoaded(pos: BlockPos) =
7474
isChunkLoaded(ChunkSectionPos.getSectionCoord(pos.x), ChunkSectionPos.getSectionCoord(pos.z))
7575

76+
fun isChunkLoadedAtBlock(x: Int, z: Int) =
77+
isChunkLoaded(ChunkSectionPos.getSectionCoord(x), ChunkSectionPos.getSectionCoord(z))
78+
7679
fun getSurfaceHeight(pos: BlockPos) = getSurfaceHeight(pos.x, pos.z)
7780

7881
fun getSurfaceHeight(x: Int, z: Int) = chunkGenerator.getHeight(
@@ -92,11 +95,16 @@ class FacilityGenerator(
9295
extraValidator = extraValidator
9396
)
9497

95-
fun validateBlock(pos: BlockPos) = isChunkLoaded(pos) && validateBlock(get(pos))
98+
fun validateBlock(pos: BlockPos) = validateBlock(get(pos))
9699

97100
fun validateBlock(state: BlockState): Boolean = !state.isIn(ComponentTags.FACILITY_KEEP)
98101

99102
fun validateSpace(box: BlockBox): Boolean {
103+
for (x in box.minX..box.maxX step 16) {
104+
for (z in box.minZ..box.maxZ step 16) {
105+
if (!isChunkLoadedAtBlock(x, z)) return false
106+
}
107+
}
100108
for (x in box.minX..box.maxX) {
101109
for (y in box.minY..box.maxY) {
102110
for (z in box.minZ..box.maxZ) {

0 commit comments

Comments
 (0)