mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
world/section: prefer slice references to Vec and fastnbt types
Makes the code a bit nicer and saves repeated deref calls into fastnbt.
This commit is contained in:
parent
a4b726992a
commit
56573640fd
2 changed files with 11 additions and 15 deletions
|
@ -92,12 +92,12 @@ impl<'a> Chunk<'a> {
|
||||||
(
|
(
|
||||||
SectionV1_13::new(
|
SectionV1_13::new(
|
||||||
data_version,
|
data_version,
|
||||||
section.block_states.data.as_ref(),
|
section.block_states.data.as_deref(),
|
||||||
§ion.block_states.palette,
|
§ion.block_states.palette,
|
||||||
block_types,
|
block_types,
|
||||||
)
|
)
|
||||||
.with_context(|| format!("Failed to load section at Y={}", section.y))?,
|
.with_context(|| format!("Failed to load section at Y={}", section.y))?,
|
||||||
BiomesV18::new(section.biomes.data.as_ref(), §ion.biomes.palette)
|
BiomesV18::new(section.biomes.data.as_deref(), §ion.biomes.palette)
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
format!("Failed to load section biomes at Y={}", section.y)
|
format!("Failed to load section biomes at Y={}", section.y)
|
||||||
})?,
|
})?,
|
||||||
|
|
|
@ -37,14 +37,14 @@ pub trait Section {
|
||||||
/// v1.13+ block data.
|
/// v1.13+ block data.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct BiomesV18<'a> {
|
pub struct BiomesV18<'a> {
|
||||||
_biomes: Option<&'a fastnbt::LongArray>,
|
_biomes: Option<&'a [i64]>,
|
||||||
_palette: &'a Vec<String>,
|
_palette: &'a [String],
|
||||||
_bits: u8,
|
_bits: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> BiomesV18<'a> {
|
impl<'a> BiomesV18<'a> {
|
||||||
/// Constructs a new [BiomesV18] from deserialized data structures
|
/// Constructs a new [BiomesV18] from deserialized data structures
|
||||||
pub fn new(biomes: Option<&'a fastnbt::LongArray>, palette: &'a Vec<String>) -> Result<Self> {
|
pub fn new(biomes: Option<&'a [i64]>, palette: &'a [String]) -> Result<Self> {
|
||||||
let bits = palette_bits(palette.len(), 1, 6).context("Unsupported block palette size")?;
|
let bits = palette_bits(palette.len(), 1, 6).context("Unsupported block palette size")?;
|
||||||
|
|
||||||
if let Some(biomes) = biomes {
|
if let Some(biomes) = biomes {
|
||||||
|
@ -66,7 +66,7 @@ impl<'a> BiomesV18<'a> {
|
||||||
/// Minecraft v1.13+ section block data
|
/// Minecraft v1.13+ section block data
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SectionV1_13<'a> {
|
pub struct SectionV1_13<'a> {
|
||||||
block_states: Option<&'a fastnbt::LongArray>,
|
block_states: Option<&'a [i64]>,
|
||||||
palette: Vec<Option<BlockType>>,
|
palette: Vec<Option<BlockType>>,
|
||||||
bits: u8,
|
bits: u8,
|
||||||
aligned_blocks: bool,
|
aligned_blocks: bool,
|
||||||
|
@ -76,8 +76,8 @@ impl<'a> SectionV1_13<'a> {
|
||||||
/// Constructs a new [SectionV1_13] from deserialized data structures
|
/// Constructs a new [SectionV1_13] from deserialized data structures
|
||||||
pub fn new(
|
pub fn new(
|
||||||
data_version: u32,
|
data_version: u32,
|
||||||
block_states: Option<&'a fastnbt::LongArray>,
|
block_states: Option<&'a [i64]>,
|
||||||
palette: &'a Vec<de::BlockStatePaletteEntry>,
|
palette: &'a [de::BlockStatePaletteEntry],
|
||||||
block_types: &'a BlockTypes,
|
block_types: &'a BlockTypes,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let aligned_blocks = data_version >= 2529;
|
let aligned_blocks = data_version >= 2529;
|
||||||
|
@ -158,18 +158,14 @@ impl<'a> Section for SectionV1_13<'a> {
|
||||||
/// Pre-1.13 section block data
|
/// Pre-1.13 section block data
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SectionV0<'a> {
|
pub struct SectionV0<'a> {
|
||||||
blocks: &'a fastnbt::ByteArray,
|
blocks: &'a [i8],
|
||||||
data: &'a fastnbt::ByteArray,
|
data: &'a [i8],
|
||||||
block_types: &'a BlockTypes,
|
block_types: &'a BlockTypes,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SectionV0<'a> {
|
impl<'a> SectionV0<'a> {
|
||||||
/// Constructs a new [SectionV0] from deserialized data structures
|
/// Constructs a new [SectionV0] from deserialized data structures
|
||||||
pub fn new(
|
pub fn new(blocks: &'a [i8], data: &'a [i8], block_types: &'a BlockTypes) -> Result<Self> {
|
||||||
blocks: &'a fastnbt::ByteArray,
|
|
||||||
data: &'a fastnbt::ByteArray,
|
|
||||||
block_types: &'a BlockTypes,
|
|
||||||
) -> Result<Self> {
|
|
||||||
use BLOCKS_PER_CHUNK as N;
|
use BLOCKS_PER_CHUNK as N;
|
||||||
|
|
||||||
if blocks.len() != N * N * N {
|
if blocks.len() != N * N * N {
|
||||||
|
|
Loading…
Add table
Reference in a new issue