@@ -18,6 +18,7 @@ import net.minecraft.util.math.*
18
18
import net.minecraft.util.math.random.Random
19
19
import net.minecraft.world.Heightmap
20
20
import net.minecraft.world.StructureWorldAccess
21
+ import net.minecraft.world.chunk.ChunkStatus
21
22
import net.minecraft.world.gen.chunk.ChunkGenerator
22
23
import net.minecraft.world.gen.feature.util.FeatureContext
23
24
@@ -40,11 +41,11 @@ class FacilityGenerator(
40
41
), context.generator
41
42
)
42
43
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)
44
45
else throw UnsupportedOperationException("Target chunk not loaded")
45
46
46
47
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 */)
48
49
else throw UnsupportedOperationException("Target chunk not loaded")
49
50
50
51
operator fun set(pos: BlockPos, block: Block) = set(pos, block.defaultState)
@@ -65,7 +66,9 @@ class FacilityGenerator(
65
66
val world: ServerWorld get() = access.toServerWorld()
66
67
val server get() = access.server
67
68
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
+
69
72
fun isChunkLoaded(pos: ChunkPos) = isChunkLoaded(pos.x, pos.z)
70
73
fun isChunkLoaded(pos: BlockPos) =
71
74
isChunkLoaded(ChunkSectionPos.getSectionCoord(pos.x), ChunkSectionPos.getSectionCoord(pos.z))
0 commit comments