Skip to content

Commit

Permalink
Down to 7 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin051000 committed Feb 6, 2025
1 parent 1ff7e3f commit ee2c544
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
35 changes: 35 additions & 0 deletions src/block_definitions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::hash::Hash;
use serde::Deserialize;
use std::collections::HashMap;
use std::sync::LazyLock;
use crate::colors::RGBTuple;


/// Use this!
pub static BLOCKS: LazyLock<Blocks> = LazyLock::new(|| Blocks::load());

Expand All @@ -25,6 +27,39 @@ pub struct Block {
pub floor_color: Option<RGBTuple>,
}

impl Hash for Block {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.name.hash(state);
self.id.hash(state);
// self.properties.hash(state);
self.building_corner.hash(state);
self.wall_color.hash(state);
self.floor_color.hash(state);
}
}

impl Ord for Block {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
use std::cmp::Ordering;

if self.id < other.id {
Ordering::Less
}
else if self.id > other.id {
Ordering::Greater
}
else {
Ordering::Equal
}
}
}

impl PartialOrd for Block {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

#[derive(Deserialize, Debug)]
pub struct Blocks {
blocks: Vec<Block>,
Expand Down
7 changes: 4 additions & 3 deletions src/element_processing/buildings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ pub fn generate_buildings(
match building_type.as_str() {
"yes" | "house" | "detached" | "static_caravan" | "semidetached_house"
| "bungalow" | "manor" | "villa" => {
return *BLOCKS.building_floor_variations()[variation_index_floor];
return BLOCKS.building_floor_variations()[variation_index_floor].clone();
}
_ => return *BLOCKS.by_name("light_gray_concrete").unwrap(),
_ => return BLOCKS.by_name("light_gray_concrete").unwrap().clone(),
}
}
*BLOCKS.by_name("light_gray_concrete").unwrap()

BLOCKS.by_name("light_gray_concrete").unwrap().clone()
});
let window_block = &*BLOCKS.by_name("white_stained_glass").unwrap();

Expand Down
8 changes: 4 additions & 4 deletions src/world_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct SectionToModify {

impl SectionToModify {
fn get_block(&self, x: u8, y: u8, z: u8) -> Option<Block> {
let b = self.blocks[Self::index(x, y, z)];
let b = self.blocks[Self::index(x, y, z)].clone();
if b == *BLOCKS.by_name("air").unwrap() {
return None;
}
Expand Down Expand Up @@ -151,12 +151,12 @@ impl ChunkToModify {
section.get_block(x, (y & 15).try_into().unwrap(), z)
}

fn set_block(&mut self, x: u8, y: i32, z: u8, block: Block) {
fn set_block(&mut self, x: u8, y: i32, z: u8, block: &Block) {
let section_idx: i8 = (y >> 4).try_into().unwrap();

let section = self.sections.entry(section_idx).or_default();

section.set_block(x, (y & 15).try_into().unwrap(), z, block);
section.set_block(x, (y & 15).try_into().unwrap(), z, *block);
}

fn sections(&self) -> impl Iterator<Item = Section> + '_ {
Expand Down Expand Up @@ -222,7 +222,7 @@ impl WorldToModify {
(x & 15).try_into().unwrap(),
y,
(z & 15).try_into().unwrap(),
block,
&block,
);
}
}
Expand Down

0 comments on commit ee2c544

Please sign in to comment.