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

Commit d815efd

Browse files
committed
fix: facility generator causes far chunk access
1 parent cbf5790 commit d815efd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import net.minecraft.util.math.*
1818
import net.minecraft.util.math.random.Random
1919
import net.minecraft.world.Heightmap
2020
import net.minecraft.world.StructureWorldAccess
21+
import net.minecraft.world.chunk.ChunkStatus
2122
import net.minecraft.world.gen.chunk.ChunkGenerator
2223
import net.minecraft.world.gen.feature.util.FeatureContext
2324

@@ -40,11 +41,11 @@ class FacilityGenerator(
4041
), context.generator
4142
)
4243

43-
operator fun get(pos: BlockPos): BlockState = if (isChunkLoaded(pos)) access.getBlockState(pos)
44+
operator fun get(pos: BlockPos): BlockState = if (isChunkLoaded(pos)) access.toServerWorld().getBlockState(pos)
4445
else throw UnsupportedOperationException("Target chunk not loaded")
4546

4647
operator fun set(pos: BlockPos, state: BlockState) =
47-
if (isChunkLoaded(pos)) access.setBlockState(pos, state, 3 /* NOTIFY_ALL */)
48+
if (isChunkLoaded(pos)) access.toServerWorld().setBlockState(pos, state, 3 /* NOTIFY_ALL */)
4849
else throw UnsupportedOperationException("Target chunk not loaded")
4950

5051
operator fun set(pos: BlockPos, block: Block) = set(pos, block.defaultState)
@@ -65,7 +66,9 @@ class FacilityGenerator(
6566
val world: ServerWorld get() = access.toServerWorld()
6667
val server get() = access.server
6768

68-
fun isChunkLoaded(posX: Int, posZ: Int) = access.chunkManager.isChunkLoaded(posX, posZ)
69+
fun isChunkLoaded(posX: Int, posZ: Int) =
70+
access.chunkManager.getChunk(posX, posZ, ChunkStatus.EMPTY, false) != null
71+
6972
fun isChunkLoaded(pos: ChunkPos) = isChunkLoaded(pos.x, pos.z)
7073
fun isChunkLoaded(pos: BlockPos) =
7174
isChunkLoaded(ChunkSectionPos.getSectionCoord(pos.x), ChunkSectionPos.getSectionCoord(pos.z))

0 commit comments

Comments
 (0)