Skip to content

Commit

Permalink
Merge branch 'main' into simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
cooltexture1 committed Mar 5, 2024
2 parents 9d26244 + c27cd44 commit 7336916
Show file tree
Hide file tree
Showing 28 changed files with 670 additions and 775 deletions.
203 changes: 110 additions & 93 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ reqwest = { version = "0.11", features = [ "blocking" ]}
glutin = "0.31"
glutin-winit = "0.4"

arc-swap = "1.7.0"

[dependencies.leafish_resources]
path = "./resources"
version = "0"
Expand Down
40 changes: 20 additions & 20 deletions blocks/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blocks/src/bin/dump_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() {
let id = str::parse::<usize>(&args[2]).unwrap();

let id_map = VanillaIDMap::new(protocol_version);
let block = id_map.by_vanilla_id(id, Arc::new(RwLock::new(HashMap::new())));
let block = id_map.by_vanilla_id(id, &Arc::new(HashMap::new()));

println!("{:?}", block);
}
26 changes: 12 additions & 14 deletions blocks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ pub use self::material::Material;

pub use self::blocks::Block::*;
pub use self::blocks::*;
use parking_lot::RwLock;
use std::sync::Arc;

pub trait WorldAccess {
fn get_block(&self, pos: Position) -> Block;
Expand Down Expand Up @@ -51,7 +49,7 @@ impl VanillaIDMap {
pub fn by_vanilla_id(
&self,
id: usize,
modded_block_ids: Arc<RwLock<HashMap<usize, String>>>, // TODO: remove and add to constructor, but have to mutate in Server
modded_block_ids: &HashMap<usize, String>, // TODO: remove and add to constructor, but have to mutate in Server
) -> Block {
match &self.mapping {
IDMapKind::Flat(blocks) => {
Expand All @@ -63,7 +61,7 @@ impl VanillaIDMap {
block
} else {
let data = id & 0xf;
if let Some(name) = modded_block_ids.read().get(&(id >> 4)) {
if let Some(name) = modded_block_ids.get(&(id >> 4)) {
if let Some(blocks_by_data) = self.modded.get(name) {
blocks_by_data[data].unwrap_or(Block::Missing {})
} else {
Expand Down Expand Up @@ -99,13 +97,13 @@ mod tests {
fn hier_1_12_2() {
let id_map = VanillaIDMap::new(340);
assert_eq!(
id_map.by_vanilla_id(255 << 4, Arc::new(RwLock::new(HashMap::new()))),
id_map.by_vanilla_id(255 << 4, &Arc::new(HashMap::new())),
StructureBlock {
mode: StructureBlockMode::Save
}
);
assert_eq!(
id_map.by_vanilla_id((255 << 4) | 3, Arc::new(RwLock::new(HashMap::new()))),
id_map.by_vanilla_id((255 << 4) | 3, &Arc::new(HashMap::new())),
StructureBlock {
mode: StructureBlockMode::Data
}
Expand All @@ -116,13 +114,13 @@ mod tests {
fn flat_1_13_2() {
let id_map = VanillaIDMap::new(404);
assert_eq!(
id_map.by_vanilla_id(8595, Arc::new(RwLock::new(HashMap::new()))),
id_map.by_vanilla_id(8595, &Arc::new(HashMap::new())),
StructureBlock {
mode: StructureBlockMode::Save
}
);
assert_eq!(
id_map.by_vanilla_id(8598, Arc::new(RwLock::new(HashMap::new()))),
id_map.by_vanilla_id(8598, &Arc::new(HashMap::new())),
StructureBlock {
mode: StructureBlockMode::Data
}
Expand All @@ -133,11 +131,11 @@ mod tests {
fn flat_1_14_4() {
let id_map = VanillaIDMap::new(477);
assert_eq!(
id_map.by_vanilla_id(9113, Arc::new(RwLock::new(HashMap::new()))),
id_map.by_vanilla_id(9113, &Arc::new(HashMap::new())),
Conduit { waterlogged: true }
);
assert_eq!(
id_map.by_vanilla_id(9114, Arc::new(RwLock::new(HashMap::new()))),
id_map.by_vanilla_id(9114, &Arc::new(HashMap::new())),
Conduit { waterlogged: false }
);
}
Expand All @@ -146,11 +144,11 @@ mod tests {
fn flat_1_15_1() {
let id_map = VanillaIDMap::new(575);
assert_eq!(
id_map.by_vanilla_id(9113, Arc::new(RwLock::new(HashMap::new()))),
id_map.by_vanilla_id(9113, &Arc::new(HashMap::new())),
Conduit { waterlogged: true }
);
assert_eq!(
id_map.by_vanilla_id(9114, Arc::new(RwLock::new(HashMap::new()))),
id_map.by_vanilla_id(9114, &Arc::new(HashMap::new())),
Conduit { waterlogged: false }
);
}
Expand All @@ -159,7 +157,7 @@ mod tests {
fn flat_1_16() {
let id_map = VanillaIDMap::new(735);
assert_eq!(
id_map.by_vanilla_id(1048, Arc::new(RwLock::new(HashMap::new()))),
id_map.by_vanilla_id(1048, &Arc::new(HashMap::new())),
NoteBlock {
instrument: NoteBlockInstrument::Pling,
note: 24,
Expand All @@ -172,7 +170,7 @@ mod tests {
fn flat_1_16_2() {
let id_map = VanillaIDMap::new(751);
assert_eq!(
id_map.by_vanilla_id(1048, Arc::new(RwLock::new(HashMap::new()))),
id_map.by_vanilla_id(1048, &Arc::new(HashMap::new())),
NoteBlock {
instrument: NoteBlockInstrument::Pling,
note: 24,
Expand Down
Loading

0 comments on commit 7336916

Please sign in to comment.