mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-07-01 13:29:06 +02:00
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:
parent
1874d3082d
commit
8814dcff89
6 changed files with 4073 additions and 2043 deletions
|
@ -1,6 +1,6 @@
|
|||
//! Functions for computations of block colors
|
||||
|
||||
use super::{Biome, BlockType, Color, Colorf};
|
||||
use super::{Biome, BlockColor, Color, Colorf};
|
||||
|
||||
/// Converts an u8 RGB color to a float vector
|
||||
fn color_vec_unscaled(color: Color) -> Colorf {
|
||||
|
@ -91,18 +91,18 @@ const BIRCH_COLOR: Colorf = Colorf::new(0.502, 0.655, 0.333); // == color_vec(Co
|
|||
/// Color multiplier for spruce leaves
|
||||
const EVERGREEN_COLOR: Colorf = Colorf::new(0.380, 0.600, 0.380); // == color_vec(Color([97, 153, 97]))
|
||||
|
||||
/// Determined if calling [block_color] for a given [BlockType] needs biome information
|
||||
pub fn needs_biome(block: BlockType) -> bool {
|
||||
/// Determined if calling [block_color] for a given [BlockColor] needs biome information
|
||||
pub fn needs_biome(block: BlockColor) -> bool {
|
||||
use super::BlockFlag::*;
|
||||
|
||||
block.is(Grass) || block.is(Foliage) || block.is(Water)
|
||||
}
|
||||
|
||||
/// Determined the block color to display for a given [BlockType]
|
||||
/// Determined the block color to display for a given [BlockColor]
|
||||
///
|
||||
/// [needs_biome] must be used to determine whether passing a [Biome] is necessary.
|
||||
/// Will panic if a [Biome] is necessary, but none is passed.
|
||||
pub fn block_color(block: BlockType, biome: Option<&Biome>, depth: f32) -> Colorf {
|
||||
pub fn block_color(block: BlockColor, biome: Option<&Biome>, depth: f32) -> Colorf {
|
||||
use super::BlockFlag::*;
|
||||
|
||||
let get_biome = || biome.expect("needs biome to determine block color");
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -42,21 +42,28 @@ pub type Colorf = glam::Vec3;
|
|||
|
||||
/// A block type specification
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub struct BlockType {
|
||||
pub struct BlockColor {
|
||||
/// Bit set of [BlockFlag]s describing special properties of the block type
|
||||
pub flags: BitFlags<BlockFlag>,
|
||||
/// Base color of the block type
|
||||
pub color: Color,
|
||||
}
|
||||
|
||||
impl BlockType {
|
||||
/// Checks whether a block type has a given [BlockFlag] set
|
||||
impl BlockColor {
|
||||
/// Checks whether a block color has a given [BlockFlag] set
|
||||
#[inline]
|
||||
pub fn is(&self, flag: BlockFlag) -> bool {
|
||||
self.flags.contains(flag)
|
||||
}
|
||||
}
|
||||
|
||||
/// A block type specification
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BlockType {
|
||||
/// Determines the rendered color of the block type
|
||||
pub block_color: BlockColor,
|
||||
}
|
||||
|
||||
/// Used to look up standard Minecraft block types
|
||||
#[derive(Debug)]
|
||||
pub struct BlockTypes {
|
||||
|
@ -70,10 +77,15 @@ impl Default for BlockTypes {
|
|||
fn default() -> Self {
|
||||
let block_type_map: HashMap<_, _> = block_types::BLOCK_TYPES
|
||||
.iter()
|
||||
.map(|(k, v)| (String::from(*k), *v))
|
||||
.map(|(k, v)| (String::from(*k), v.clone()))
|
||||
.collect();
|
||||
let legacy_block_types = Box::new(legacy_block_types::LEGACY_BLOCK_TYPES.map(|inner| {
|
||||
inner.map(|id| *block_type_map.get(id).expect("Unknown legacy block type"))
|
||||
inner.map(|id| {
|
||||
block_type_map
|
||||
.get(id)
|
||||
.expect("Unknown legacy block type")
|
||||
.clone()
|
||||
})
|
||||
}));
|
||||
|
||||
BlockTypes {
|
||||
|
@ -86,15 +98,15 @@ impl Default for BlockTypes {
|
|||
impl BlockTypes {
|
||||
/// Resolves a Minecraft 1.13+ string block type ID
|
||||
#[inline]
|
||||
pub fn get(&self, id: &str) -> Option<BlockType> {
|
||||
pub fn get(&self, id: &str) -> Option<&BlockType> {
|
||||
let suffix = id.strip_prefix("minecraft:")?;
|
||||
self.block_type_map.get(suffix).copied()
|
||||
self.block_type_map.get(suffix)
|
||||
}
|
||||
|
||||
/// Resolves a Minecraft pre-1.13 numeric block type ID
|
||||
#[inline]
|
||||
pub fn get_legacy(&self, id: u8, data: u8) -> Option<BlockType> {
|
||||
Some(self.legacy_block_types[id as usize][data as usize])
|
||||
pub fn get_legacy(&self, id: u8, data: u8) -> Option<&BlockType> {
|
||||
Some(&self.legacy_block_types[id as usize][data as usize])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue