Skip to content

Commit

Permalink
fix: correctly lock fastanvil to git, remove global block states
Browse files Browse the repository at this point in the history
  • Loading branch information
bigspeedfpv committed Nov 12, 2024
1 parent 6204816 commit 0804c63
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 78 deletions.
90 changes: 55 additions & 35 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bytes = "1.8.0"
cfb8 = { version = "0.8.1", optional = true }
clap = { version = "4.5.20", features = ["derive"] }
color-eyre = "0.6.3"
fastanvil = "0.31.0"
fastanvil = { git = "https://github.com/owengage/fastnbt.git" }
fastnbt = { git = "https://github.com/owengage/fastnbt.git" }
rand = "0.8.5"
rayon = "1.10.0"
Expand Down
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

packages = with pkgs; [
rust-analyzer
valgrind
];
};

Expand All @@ -72,6 +73,7 @@
inherit version;
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
cargoLock.outputHashes."fastanvil-0.31.0" = "E4WI6SZgkjqUOtbfXfKGfpFH7btEh5V0KpMXSIsuh08=";
cargoLock.outputHashes."fastnbt-2.5.0" = "E4WI6SZgkjqUOtbfXfKGfpFH7btEh5V0KpMXSIsuh08=";
inherit buildType;
dontStrip = buildType == "debug";
Expand Down
6 changes: 1 addition & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use color_eyre::eyre::Result;
use net::cache::WorldCache;
use server::Server;
use tracing_subscriber::{layer::SubscriberExt, prelude::*, EnvFilter};
use world::{blocks::ALL_BLOCKS, read_world};
use world::read_world;

#[macro_use]
extern crate tracing;
Expand Down Expand Up @@ -76,10 +76,6 @@ async fn main() -> Result<()> {
let world = read_world(&args.map_dir)?;
info!("Done.");

info!("Loading blocks");
let _ = *ALL_BLOCKS;
info!("Done.");

info!("Generating world chunk packets");
let world_cache = WorldCache::from(world);
info!("Done.");
Expand Down
6 changes: 4 additions & 2 deletions src/net/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::{
},
Encoder,
},
world::World,
world::{blocks::Blocks, World},
};

#[derive(Debug)]
Expand All @@ -50,9 +50,11 @@ impl From<World> for WorldCache {
}
});

let block_states = Blocks::new();

let chunks = chunks
.par_iter()
.map(|(_, c)| ChunkDataUpdateLightC::from(*c))
.map(|(_, c)| ChunkDataUpdateLightC::new(c, &block_states))
.collect::<Vec<ChunkDataUpdateLightC<'_>>>();

let encoded = chunks
Expand Down
12 changes: 6 additions & 6 deletions src/protocol/packets/play/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::{
protocol::{datatypes::VarInt, Encode, Packet},
world::{
self,
blocks::BlockState,
blocks::{BlockState, Blocks},
},
};

Expand Down Expand Up @@ -189,7 +189,7 @@ impl Encode for ChunkDataUpdateLightC<'_> {
}

impl ChunkSection {
pub fn anvil_to_sec(value: &world::Section) -> Self {
pub fn anvil_to_sec(value: &world::Section, block_states: &Blocks) -> Self {
let mut blocks: [i16; 16 * 16 * 16] = [0; 16 * 16 * 16];
let bit_length = (64 - (value.block_states.palette.len() as u64).leading_zeros()).max(4);
let blocks_per_long = 64 / bit_length;
Expand All @@ -214,7 +214,7 @@ impl ChunkSection {
.block_states
.palette
.iter()
.map(|b| BlockState::try_from(b).unwrap_or(BlockState::AIR))
.map(|b| BlockState::parse_state(b, block_states).unwrap_or(BlockState::AIR))
.collect::<Vec<_>>();

let blocks: Vec<u16> = blocks
Expand Down Expand Up @@ -297,12 +297,12 @@ impl ChunkSection {
}
}

impl From<&world::Chunk> for ChunkDataUpdateLightC<'_> {
fn from(value: &world::Chunk) -> Self {
impl ChunkDataUpdateLightC<'_> {
pub fn new(value: &world::Chunk, block_states: &Blocks) -> Self {
let data = value
.sections
.iter()
.map(ChunkSection::anvil_to_sec)
.map(|sec| ChunkSection::anvil_to_sec(sec, block_states))
.collect::<Vec<_>>();

Self {
Expand Down
Loading

0 comments on commit 0804c63

Please sign in to comment.