pub enum ChunkStorage {
Disk(RegionManager),
RamOnly(RamOnlyStorage),
}Expand description
Chunk storage backend.
This enum provides persistence for chunks, either to disk (region files) or in-memory (for testing/minigames). TODO: make it possible to give plugins the option to load a custom backend
Variants§
Disk(RegionManager)
Disk-based storage using region files.
RamOnly(RamOnlyStorage)
In-memory storage for testing and minigames.
Implementations§
Source§impl ChunkStorage
impl ChunkStorage
fn invalid_chunk_data(message: impl Into<String>) -> Error
fn validate_packed_palette( palette: &[u16], bits_per_entry: u8, data: &[u64], entry_count: usize, global_palette_len: usize, name: &str, ) -> Result<()>
fn validate_persistent_chunk( persistent: &PersistentChunk<'_>, status: ChunkStatus, min_y: i32, height: i32, ) -> Result<()>
Sourcepub(super) fn section_to_persistent(
section: &SectionHolder,
builder: &mut ChunkBuilder<'_>,
) -> PersistentSection
pub(super) fn section_to_persistent( section: &SectionHolder, builder: &mut ChunkBuilder<'_>, ) -> PersistentSection
Converts a runtime section to persistent format.
Sourcepub(super) fn biomes_to_persistent(
biomes: &PalettedContainer<u16, 4>,
builder: &mut ChunkBuilder<'_>,
) -> PersistentBiomeData
pub(super) fn biomes_to_persistent( biomes: &PalettedContainer<u16, 4>, builder: &mut ChunkBuilder<'_>, ) -> PersistentBiomeData
Converts runtime biome data to persistent format.
Sourcepub(crate) fn try_persistent_to_chunk(
persistent: &PersistentChunk<'_>,
pos: ChunkPos,
status: ChunkStatus,
min_y: i32,
height: i32,
level: Weak<World>,
) -> Result<LoadedChunk>
pub(crate) fn try_persistent_to_chunk( persistent: &PersistentChunk<'_>, pos: ChunkPos, status: ChunkStatus, min_y: i32, height: i32, level: Weak<World>, ) -> Result<LoadedChunk>
Converts a persistent chunk to runtime format. The returned chunk is not dirty (freshly loaded from disk).
§Arguments
persistent- The persistent chunk datapos- The chunk positionstatus- The chunk statusmin_y- The minimum Y coordinate of the worldheight- The total height of the worldlevel- Weak reference to the world for Full chunk runtime access
Sourcepub(super) fn heightmaps_to_persistent(
heightmaps: &ChunkHeightmaps,
status: ChunkStatus,
) -> Vec<PersistentHeightmap>
pub(super) fn heightmaps_to_persistent( heightmaps: &ChunkHeightmaps, status: ChunkStatus, ) -> Vec<PersistentHeightmap>
Converts chunk heightmaps to persistent format for saving.
Sourcepub(super) fn persistent_to_heightmaps(
persistent: &[PersistentHeightmap],
status: ChunkStatus,
min_y: i32,
height: i32,
) -> ChunkHeightmaps
pub(super) fn persistent_to_heightmaps( persistent: &[PersistentHeightmap], status: ChunkStatus, min_y: i32, height: i32, ) -> ChunkHeightmaps
Reconstructs chunk heightmaps from persistent data.
Sourcepub(super) fn pois_to_persistent(
chunk: FullChunkRef<'_>,
chunk_pos: ChunkPos,
) -> Vec<PersistentPoi>
pub(super) fn pois_to_persistent( chunk: FullChunkRef<'_>, chunk_pos: ChunkPos, ) -> Vec<PersistentPoi>
Collects POI occupancy data from the world’s POI storage for this chunk.
Sourcepub(super) fn persistent_to_section(
persistent: &PersistentSection,
chunk: &PersistentChunk<'_>,
) -> Result<ChunkSection>
pub(super) fn persistent_to_section( persistent: &PersistentSection, chunk: &PersistentChunk<'_>, ) -> Result<ChunkSection>
Converts a persistent section to runtime format.
Sourcepub(super) fn persistent_to_biomes(
persistent: &PersistentBiomeData,
chunk: &PersistentChunk<'_>,
) -> Result<PalettedContainer<u16, 4>>
pub(super) fn persistent_to_biomes( persistent: &PersistentBiomeData, chunk: &PersistentChunk<'_>, ) -> Result<PalettedContainer<u16, 4>>
Converts persistent biome data to runtime format.
Sourcepub(super) fn resolve_block_state(
chunk: &PersistentChunk<'_>,
index: u16,
) -> Result<BlockStateId>
pub(super) fn resolve_block_state( chunk: &PersistentChunk<'_>, index: u16, ) -> Result<BlockStateId>
Resolves a chunk palette index to a runtime BlockStateId.
Sourcepub(super) fn resolve_biome(
chunk: &PersistentChunk<'_>,
index: u16,
) -> Result<u16>
pub(super) fn resolve_biome( chunk: &PersistentChunk<'_>, index: u16, ) -> Result<u16>
Resolves a chunk palette index to a runtime biome ID.
Source§impl ChunkStorage
impl ChunkStorage
pub(super) fn entities_to_persistent( entities: &[SharedEntity], ) -> Vec<PersistentEntity>
pub(crate) fn entity_tree_to_persistent( entity: &SharedEntity, ) -> Option<PersistentEntity>
pub(crate) fn entity_to_dimension_transition_persistent( entity: &SharedEntity, ) -> Option<PersistentEntity>
pub(super) fn custom_name_to_persistent( custom_name: Option<&TextComponent>, ) -> Vec<u8> ⓘ
pub(super) fn custom_name_from_persistent( bytes: &[u8], uuid: Uuid, ) -> Option<TextComponent>
pub(super) fn compound_to_persistent(compound: &NbtCompound) -> Vec<u8> ⓘ
pub(super) fn compound_from_persistent(bytes: &[u8], uuid: Uuid) -> NbtCompound
pub(super) fn save_data_from_persistent( persistent: &PersistentEntity, uuid: Uuid, ) -> EntityBaseSaveData
pub(super) fn clamp_loaded_entity_position(pos: DVec3) -> DVec3
pub(super) fn entity_to_persistent( entity: &SharedEntity, visited: &mut FxHashSet<i32>, mode: EntityPersistenceMode, ) -> Option<PersistentEntity>
pub(super) fn entity_should_save(entity: &dyn Entity) -> bool
pub(super) fn entity_should_persist( entity: &dyn Entity, mode: EntityPersistenceMode, ) -> bool
Sourcepub(super) fn persistent_block_entity_pos(
persistent: &PersistentBlockEntity,
chunk_pos: ChunkPos,
) -> BlockPos
pub(super) fn persistent_block_entity_pos( persistent: &PersistentBlockEntity, chunk_pos: ChunkPos, ) -> BlockPos
Converts a runtime section to persistent format.
Sourcepub(super) fn persistent_to_block_entity(
persistent: &PersistentBlockEntity,
chunk_pos: ChunkPos,
chunk: FullChunkRef<'_>,
) -> Option<SharedBlockEntity>
pub(super) fn persistent_to_block_entity( persistent: &PersistentBlockEntity, chunk_pos: ChunkPos, chunk: FullChunkRef<'_>, ) -> Option<SharedBlockEntity>
Converts a persistent block entity to runtime format.
pub(super) fn persistent_to_block_entity_at( persistent: &PersistentBlockEntity, pos: BlockPos, level: Weak<World>, state: BlockStateId, ) -> Option<SharedBlockEntity>
Sourcepub(crate) fn persistent_to_entity_tree_at_level(
persistent: &PersistentEntity,
chunk_pos: ChunkPos,
level: &Weak<World>,
) -> Vec<SharedEntity> ⓘ
pub(crate) fn persistent_to_entity_tree_at_level( persistent: &PersistentEntity, chunk_pos: ChunkPos, level: &Weak<World>, ) -> Vec<SharedEntity> ⓘ
Converts a persistent entity tree to runtime format.
pub(super) fn load_persistent_passenger_tree( persistent: &PersistentEntity, chunk_pos: ChunkPos, level: &Weak<World>, vehicle: &SharedEntity, entities: &mut Vec<SharedEntity>, )
Sourcepub(super) fn persistent_to_entity_at_level(
persistent: &PersistentEntity,
chunk_pos: ChunkPos,
level: &Weak<World>,
) -> Option<SharedEntity>
pub(super) fn persistent_to_entity_at_level( persistent: &PersistentEntity, chunk_pos: ChunkPos, level: &Weak<World>, ) -> Option<SharedEntity>
Converts one persistent entity to runtime format without loading passengers.
Source§impl ChunkStorage
impl ChunkStorage
Sourcepub(super) fn light_to_persistent(light: &ChunkLightData) -> PersistentLightData
pub(super) fn light_to_persistent(light: &ChunkLightData) -> PersistentLightData
Converts chunk-owned light data to persistent format.
pub(super) fn light_layer_to_persistent( layer: &ChunkLightLayerStorage, ) -> Vec<PersistentLightSection>
pub(super) fn persistent_to_light( persistent: &PersistentLightData, min_y: i32, height: i32, status: ChunkStatus, ) -> ChunkLightData
pub(super) fn apply_persistent_light_layer( layer: &mut ChunkLightLayerStorage, persistent: &[PersistentLightSection], layer_name: &str, )
pub(super) fn persistent_to_light_section( persistent: &PersistentLightSection, layer_name: &str, ) -> Option<LightSection>
pub(super) fn persistent_light_bytes_to_data( data: &[u8], section_index: u32, layer_name: &str, ) -> Option<LightSectionData>
Source§impl ChunkStorage
impl ChunkStorage
pub(super) fn jigsaw_piece_data_to_persistent( data: &JigsawPieceData, ) -> PersistentJigsawPieceData
pub(super) fn persistent_to_jigsaw_piece_data( data: &PersistentJigsawPieceData, ) -> JigsawPieceData
pub(super) fn procedural_piece_data_to_persistent( data: &ProceduralPieceData, ) -> PersistentProceduralPieceData
pub(super) fn persistent_to_procedural_piece_data( data: &PersistentProceduralPieceData, ) -> ProceduralPieceData
pub(super) fn ocean_monument_data_to_persistent( data: &OceanMonumentPieceData, ) -> PersistentOceanMonumentPieceData
pub(super) fn persistent_to_ocean_monument_data( data: &PersistentOceanMonumentPieceData, ) -> OceanMonumentPieceData
const fn ocean_monument_child_to_persistent( child: &OceanMonumentChildPiece, ) -> PersistentOceanMonumentChildPiece
const fn persistent_to_ocean_monument_child( child: &PersistentOceanMonumentChildPiece, ) -> OceanMonumentChildPiece
const fn ocean_monument_child_kind_to_persistent( kind: &OceanMonumentChildPieceKind, ) -> PersistentOceanMonumentChildPieceKind
const fn persistent_to_ocean_monument_child_kind( kind: &PersistentOceanMonumentChildPieceKind, ) -> OceanMonumentChildPieceKind
const fn ocean_monument_room_to_persistent( room: OceanMonumentRoomData, ) -> PersistentOceanMonumentRoomData
const fn persistent_to_ocean_monument_room( room: &PersistentOceanMonumentRoomData, ) -> OceanMonumentRoomData
const fn fortress_piece_data_to_persistent( data: FortressPieceData, ) -> PersistentNetherFortressPieceData
const fn persistent_to_fortress_piece_data( data: &PersistentNetherFortressPieceData, ) -> FortressPieceData
const fn stronghold_door_to_persistent( door: StrongholdSmallDoorType, ) -> PersistentStrongholdSmallDoorType
const fn persistent_to_stronghold_door( door: &PersistentStrongholdSmallDoorType, ) -> StrongholdSmallDoorType
const fn stronghold_piece_data_to_persistent( data: StrongholdPieceData, ) -> PersistentStrongholdPieceData
const fn persistent_to_stronghold_piece_data( data: &PersistentStrongholdPieceData, ) -> StrongholdPieceData
pub(super) fn mineshaft_kind_to_persistent( kind: &MineshaftPieceKind, ) -> PersistentMineshaftPieceKind
pub(super) fn persistent_to_mineshaft_kind( kind: &PersistentMineshaftPieceKind, ) -> MineshaftPieceKind
pub(super) fn structure_piece_payload_to_persistent( payload: &StructurePiecePayload, ) -> PersistentStructurePiecePayload
pub(super) fn persistent_to_structure_piece_payload( payload: &PersistentStructurePiecePayload, ) -> StructurePiecePayload
pub(super) fn pool_element_to_persistent( element: &PoolElement, ) -> PersistentPoolElement
pub(super) fn persistent_to_pool_element( element: &PersistentPoolElement, ) -> PoolElement
pub(super) fn processors_to_persistent( processors: &ProcessorList, ) -> PersistentProcessorList
pub(super) fn persistent_to_processors( processors: &PersistentProcessorList, ) -> ProcessorList
pub(super) fn template_processors_to_persistent( processors: &TemplateProcessorList, ) -> PersistentTemplateProcessorList
pub(super) fn persistent_to_template_processors( processors: &PersistentTemplateProcessorList, ) -> TemplateProcessorList
Sourcepub(super) fn structure_starts_to_persistent(
starts: &StructureStartMap,
) -> Vec<PersistentStructureStart>
pub(super) fn structure_starts_to_persistent( starts: &StructureStartMap, ) -> Vec<PersistentStructureStart>
Converts structure starts to persistent format for saving.
Sourcepub(super) fn structure_references_to_persistent(
refs: &StructureReferenceMap,
) -> Vec<PersistentStructureReference>
pub(super) fn structure_references_to_persistent( refs: &StructureReferenceMap, ) -> Vec<PersistentStructureReference>
Converts structure references to persistent format for saving.
Sourcepub(super) fn persistent_to_structure_starts(
persistent: &[PersistentStructureStart],
) -> StructureStartMap
pub(super) fn persistent_to_structure_starts( persistent: &[PersistentStructureStart], ) -> StructureStartMap
Reconstructs structure starts from persistent data.
Sourcepub(super) fn persistent_to_structure_references(
persistent: &[PersistentStructureReference],
) -> StructureReferenceMap
pub(super) fn persistent_to_structure_references( persistent: &[PersistentStructureReference], ) -> StructureReferenceMap
Reconstructs structure references from persistent data.
Source§impl ChunkStorage
impl ChunkStorage
Sourcepub(super) fn block_ticks_to_persistent(
ticks: Vec<SavedTick<BlockRef>>,
chunk_pos: ChunkPos,
) -> Vec<PersistentTick>
pub(super) fn block_ticks_to_persistent( ticks: Vec<SavedTick<BlockRef>>, chunk_pos: ChunkPos, ) -> Vec<PersistentTick>
Converts block ticks to persistent format for saving.
Sourcepub(super) fn fluid_ticks_to_persistent(
ticks: Vec<SavedTick<FluidRef>>,
chunk_pos: ChunkPos,
) -> Vec<PersistentTick>
pub(super) fn fluid_ticks_to_persistent( ticks: Vec<SavedTick<FluidRef>>, chunk_pos: ChunkPos, ) -> Vec<PersistentTick>
Converts fluid ticks to persistent format for saving.
Sourcepub(super) fn persistent_to_block_saved_ticks(
persistent: &[PersistentTick],
chunk_pos: ChunkPos,
) -> Vec<SavedTick<BlockRef>>
pub(super) fn persistent_to_block_saved_ticks( persistent: &[PersistentTick], chunk_pos: ChunkPos, ) -> Vec<SavedTick<BlockRef>>
Reconstructs saved block ticks from persistent data.
Sourcepub(super) fn persistent_to_fluid_saved_ticks(
persistent: &[PersistentTick],
chunk_pos: ChunkPos,
) -> Vec<SavedTick<FluidRef>>
pub(super) fn persistent_to_fluid_saved_ticks( persistent: &[PersistentTick], chunk_pos: ChunkPos, ) -> Vec<SavedTick<FluidRef>>
Reconstructs saved fluid ticks from persistent data.
Source§impl ChunkStorage
impl ChunkStorage
Sourcepub async fn load_chunk(
&self,
pos: ChunkPos,
min_y: i32,
height: i32,
level: Weak<World>,
thread_pool: &ThreadPool,
) -> Result<Option<LoadedChunk>>
pub async fn load_chunk( &self, pos: ChunkPos, min_y: i32, height: i32, level: Weak<World>, thread_pool: &ThreadPool, ) -> Result<Option<LoadedChunk>>
Loads a chunk from storage.
Returns Ok(None) if the chunk doesn’t exist in storage.
For RamOnly with create_empty_on_miss=true, this always
returns an empty chunk (never None).
Sourcepub async fn save_chunk_data(
&self,
prepared: PreparedChunkSave,
thread_pool: &ThreadPool,
) -> Result<bool>
pub async fn save_chunk_data( &self, prepared: PreparedChunkSave, thread_pool: &ThreadPool, ) -> Result<bool>
Saves prepared chunk data to storage.
Returns Ok(true) if the chunk was saved, Ok(false) if it was a no-op.
Sourcepub async fn chunk_exists(&self, pos: ChunkPos) -> Result<bool>
pub async fn chunk_exists(&self, pos: ChunkPos) -> Result<bool>
Checks if a chunk exists in storage.
Sourcepub async fn acquire_chunk(&self, pos: ChunkPos) -> Result<bool>
pub async fn acquire_chunk(&self, pos: ChunkPos) -> Result<bool>
Acquires a chunk for loading, preparing any necessary resources.
For disk storage, this opens/creates the region file and returns whether the chunk exists. For RAM storage, this just checks existence.
Sourcepub async fn release_chunk(&self, pos: ChunkPos) -> Result<()>
pub async fn release_chunk(&self, pos: ChunkPos) -> Result<()>
Releases a loaded chunk, allowing the storage to clean up resources.
Sourcepub async fn close_all(&self) -> Result<()>
pub async fn close_all(&self) -> Result<()>
Closes all storage handles and flushes pending data.
Sourcepub(crate) fn prepare_chunk_save(
chunk: &Chunk,
status: ChunkStatus,
runtime_entities: &[SharedEntity],
force: bool,
) -> Option<PreparedChunkSave>
pub(crate) fn prepare_chunk_save( chunk: &Chunk, status: ChunkStatus, runtime_entities: &[SharedEntity], force: bool, ) -> Option<PreparedChunkSave>
Saves a chunk to the appropriate region.
The chunk is serialized, compressed, and written to disk immediately. If the region was already open (has loaded chunks), the header update is deferred. If this call opened the region, it will be closed after saving.
If the chunk is not dirty and force is false, this is a no-op.
Returns Ok(true) if the chunk was saved.
Prepares chunk data and its authoritative persisted status for saving.
Call this during the holder’s snapshot-preparation phase, then pass the result to
save_chunk_data after ending that phase.
§Panics
Panics if status does not match whether Full runtime state is initialized.
fn entity_position_is_finite(entity: &dyn Entity) -> bool
fn warn_skipping_non_finite_entity(entity: &dyn Entity)
fn assert_unique_save_uuid( seen_uuids: &mut FxHashSet<Uuid>, uuid: Uuid, entity_id: i32, chunk_pos: ChunkPos, )
Sourcefn to_persistent(
sections: &Sections,
block_entities: &[SharedBlockEntity],
pending_block_entities: &[BlockPos],
entities: &[SharedEntity],
block_ticks: Vec<PersistentTick>,
fluid_ticks: Vec<PersistentTick>,
heightmaps: Vec<PersistentHeightmap>,
light: PersistentLightData,
carving_mask: Option<Vec<u64>>,
postprocessing: Vec<Vec<u16>>,
structure_starts: Vec<PersistentStructureStart>,
structure_references: Vec<PersistentStructureReference>,
pois: Vec<PersistentPoi>,
chunk_pos: ChunkPos,
) -> PersistentChunk<'static>
fn to_persistent( sections: &Sections, block_entities: &[SharedBlockEntity], pending_block_entities: &[BlockPos], entities: &[SharedEntity], block_ticks: Vec<PersistentTick>, fluid_ticks: Vec<PersistentTick>, heightmaps: Vec<PersistentHeightmap>, light: PersistentLightData, carving_mask: Option<Vec<u64>>, postprocessing: Vec<Vec<u16>>, structure_starts: Vec<PersistentStructureStart>, structure_references: Vec<PersistentStructureReference>, pois: Vec<PersistentPoi>, chunk_pos: ChunkPos, ) -> PersistentChunk<'static>
Converts chunk data to persistent format.
Auto Trait Implementations§
impl !Freeze for ChunkStorage
impl !RefUnwindSafe for ChunkStorage
impl Send for ChunkStorage
impl Sync for ChunkStorage
impl Unpin for ChunkStorage
impl UnsafeUnpin for ChunkStorage
impl UnwindSafe for ChunkStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreArc<SyncMutex<>>