Utilisation et contraintes

Ne recherchez une machine que dans un chunk déjà chargé. Sinon, renvoyez une absence. La découverte ne doit ni charger une usine distante ni créer de tickets à l’ouverture de Fabrication.

LoadedBlockAccess

LoadedBlockAccess
package dev.nebulastorage.api.platform

import net.minecraft.core.BlockPos
import net.minecraft.server.level.ServerLevel
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.chunk.LevelChunk

/** Server-thread reads that neither load a chunk nor renew Minecraft's implicit UNKNOWN ticket. */
object LoadedBlockAccess {
    fun chunk(level: ServerLevel, position: BlockPos): LevelChunk? {
        check(level.server.isSameThread) { "Loaded block access requires the server thread" }
        return level.chunkSource.getChunkNow(position.x shr 4, position.z shr 4)
    }

    fun entity(level: ServerLevel, position: BlockPos): BlockEntity? = chunk(level, position)?.getBlockEntity(position)
    fun state(level: ServerLevel, position: BlockPos): BlockState? = chunk(level, position)?.getBlockState(position)
}
Source

src/main/kotlin/dev/nebulastorage/api/platform/LoadedBlockAccess.kt; editorial/fr.json

43b4d12d69e6033c24fa8c39dac383ef2429b446