resource: split BlockType in Copy and !Copy parts

Preparation for actually adding !Copy fields to BlockType.

Only the Copy parts are added to the processed data, avoiding .clone()
for the most part.
This commit is contained in:
Matthias Schiffer 2023-12-30 01:42:17 +01:00
parent 1874d3082d
commit 8814dcff89
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
6 changed files with 4073 additions and 2043 deletions

View file

@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use super::chunk::{Chunk, SectionIterItem};
use crate::{
resource::{Biome, BlockFlag, BlockType},
resource::{Biome, BlockColor, BlockFlag},
types::*,
};
@ -31,8 +31,8 @@ impl BlockHeight {
}
}
/// Array optionally storing a [BlockType] for each coordinate of a chunk
pub type BlockArray = LayerBlockArray<Option<BlockType>>;
/// Array optionally storing a [BlockColor] for each coordinate of a chunk
pub type BlockArray = LayerBlockArray<Option<BlockColor>>;
/// Array optionally storing a biome index for each coordinate of a chunk
///
@ -49,7 +49,7 @@ pub type DepthArray = LayerBlockArray<Option<BlockHeight>>;
/// References to LayerData entries for a single coordinate pair
struct LayerEntry<'a> {
/// The block type of the referenced entry
block: &'a mut Option<BlockType>,
block: &'a mut Option<BlockColor>,
/// The biome type of the referenced entry
biome: &'a mut Option<NonZeroU16>,
/// The block light of the referenced entry
@ -86,7 +86,7 @@ impl<'a> LayerEntry<'a> {
let Some(block_type) = section
.section
.block_at(coords)?
.filter(|block_type| block_type.is(BlockFlag::Opaque))
.filter(|block_type| block_type.block_color.is(BlockFlag::Opaque))
else {
if self.is_empty() {
*self.block_light = section.block_light.block_light_at(coords);
@ -96,7 +96,7 @@ impl<'a> LayerEntry<'a> {
};
if self.is_empty() {
*self.block = Some(block_type);
*self.block = Some(block_type.block_color);
if let Some(biome) = section.biomes.biome_at(section.y, coords)? {
let (biome_index, _) = biome_list.insert_full(*biome);
*self.biome = NonZeroU16::new(
@ -107,7 +107,7 @@ impl<'a> LayerEntry<'a> {
}
}
if block_type.is(BlockFlag::Water) {
if block_type.block_color.is(BlockFlag::Water) {
return Ok(false);
}

View file

@ -44,7 +44,7 @@ fn palette_bits(len: usize, min: u8, max: u8) -> Option<u8> {
/// Trait for common functions of [SectionV1_13] and [SectionV0]
pub trait Section: Debug {
/// Returns the [BlockType] at a coordinate tuple inside the section
fn block_at(&self, coords: SectionBlockCoords) -> Result<Option<BlockType>>;
fn block_at(&self, coords: SectionBlockCoords) -> Result<Option<&BlockType>>;
}
/// Minecraft v1.13+ section block data
@ -53,7 +53,7 @@ pub struct SectionV1_13<'a> {
/// Packed block type data
block_states: Option<&'a [i64]>,
/// List of block types indexed by entries encoded in *block_states*
palette: Vec<Option<BlockType>>,
palette: Vec<Option<&'a BlockType>>,
/// Number of bits per block in *block_states*
bits: u8,
/// Set to true if packed block entries in *block_states* are aligned to i64
@ -146,7 +146,7 @@ impl<'a> SectionV1_13<'a> {
}
impl<'a> Section for SectionV1_13<'a> {
fn block_at(&self, coords: SectionBlockCoords) -> Result<Option<BlockType>> {
fn block_at(&self, coords: SectionBlockCoords) -> Result<Option<&BlockType>> {
let index = self.palette_index_at(coords);
Ok(*self
.palette
@ -189,7 +189,7 @@ impl<'a> SectionV0<'a> {
}
impl<'a> Section for SectionV0<'a> {
fn block_at(&self, coords: SectionBlockCoords) -> Result<Option<BlockType>> {
fn block_at(&self, coords: SectionBlockCoords) -> Result<Option<&BlockType>> {
let offset = coords.offset();
let block = self.blocks[offset] as u8;