diff --git a/src/main.rs b/src/main.rs
index 5518761..af97119 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -17,16 +17,13 @@
* .
*/
-use std::{
- fs::OpenOptions,
- sync::{Arc, LazyLock},
- time::Duration,
-};
+use std::{fs::OpenOptions, sync::Arc};
use color_eyre::eyre::Result;
+use net::cache::WorldCache;
use server::Server;
use tracing_subscriber::{layer::SubscriberExt, prelude::*, EnvFilter};
-use world::{blocks::ALL_BLOCKS, cache::WorldCache, read_world};
+use world::{blocks::ALL_BLOCKS, read_world};
#[macro_use]
extern crate tracing;
diff --git a/src/net/cache.rs b/src/net/cache.rs
new file mode 100644
index 0000000..477131c
--- /dev/null
+++ b/src/net/cache.rs
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2024 Andrew Brower.
+ * This file is part of Crawlspace.
+ *
+ * Crawlspace is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Crawlspace is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with Crawlspace. If not, see
+ * .
+ */
+
+use std::cmp::Ordering;
+
+use crate::{
+ protocol::{
+ datatypes::VarInt,
+ packets::{
+ login::registry::{AllRegistries, DimensionType, Registry},
+ play::ChunkDataUpdateLightC,
+ },
+ Encoder,
+ },
+ world::World,
+};
+
+#[derive(Debug)]
+pub struct WorldCache {
+ pub encoded: Vec>,
+}
+
+impl From for WorldCache {
+ fn from(world: World) -> Self {
+ let mut chunks = world.0.iter().collect::>();
+
+ chunks.sort_by(|((ax, az), _), ((bx, bz), _)| {
+ if (ax + az) > (bx + bz) {
+ Ordering::Greater
+ } else {
+ Ordering::Less
+ }
+ });
+
+ let chunks = chunks
+ .iter()
+ .map(|(_, c)| ChunkDataUpdateLightC::from(*c))
+ .collect::>>();
+
+ let mut encoder = Encoder::new();
+ let mut encoded = Vec::with_capacity(chunks.len());
+
+ chunks.iter().for_each(|chunk| {
+ encoder
+ .append_packet(chunk)
+ .expect("Failed to append packet to encoder");
+ encoded.push(encoder.take().to_vec());
+ });
+
+ Self { encoded }
+ }
+}
+
+#[derive(Debug)]
+pub struct RegistryCache {
+ pub encoded: Vec,
+ pub the_end_id: VarInt,
+}
+
+impl From<&AllRegistries> for RegistryCache {
+ fn from(registry: &AllRegistries) -> Self {
+ let mut encoder = Encoder::new();
+
+ let dimensions = Registry::from(registry.dimension_type.clone());
+ encoder
+ .append_packet(&Registry::from(registry.trim_material.clone()))
+ .expect("Failed to encode trim material");
+ encoder
+ .append_packet(&Registry::from(registry.trim_pattern.clone()))
+ .expect("Failed to encode trim pattern");
+ encoder
+ .append_packet(&Registry::from(registry.banner_pattern.clone()))
+ .expect("Failed to encode banner pattern");
+ encoder
+ .append_packet(&Registry::from(registry.biome.clone()))
+ .expect("Failed to encode biome");
+ encoder
+ .append_packet(&Registry::from(registry.chat_type.clone()))
+ .expect("Failed to encode chat type");
+ encoder
+ .append_packet(&Registry::from(registry.damage_type.clone()))
+ .expect("Failed to encode damage type");
+ encoder
+ .append_packet(&dimensions)
+ .expect("Failed to encode dimensions");
+ encoder
+ .append_packet(&Registry::from(registry.wolf_variant.clone()))
+ .expect("Failed to encode wolf variants");
+ encoder
+ .append_packet(&Registry::from(registry.painting_variant.clone()))
+ .expect("Failed to encode painting variants");
+
+ Self {
+ encoded: encoder.take().to_vec(),
+ the_end_id: VarInt(dimensions.index_of("minecraft:the_end")),
+ }
+ }
+}
diff --git a/src/net/mod.rs b/src/net/mod.rs
index d149028..5ffdc21 100644
--- a/src/net/mod.rs
+++ b/src/net/mod.rs
@@ -21,9 +21,11 @@ use color_eyre::eyre::Result;
use player::SharedPlayer;
use tokio::net::TcpListener;
-mod io;
+pub mod cache;
pub mod player;
+mod io;
+
use crate::CrawlState;
#[cfg(feature = "lan")]
diff --git a/src/net/player.rs b/src/net/player.rs
index 0a5de98..14fda98 100644
--- a/src/net/player.rs
+++ b/src/net/player.rs
@@ -38,12 +38,11 @@ use crate::{
packets::{
login::*,
play::{
- ChunkDataUpdateLightC, ConfirmTeleportS, GameEvent, GameEventC, Gamemode,
- KeepAliveC, LoginPlayC, PlayerInfoUpdateC, PlayerStatus, SetCenterChunkC,
- SynchronisePositionC,
+ ConfirmTeleportS, GameEvent, GameEventC, Gamemode, KeepAliveC, LoginPlayC,
+ PlayerInfoUpdateC, PlayerStatus, SetCenterChunkC, SynchronisePositionC,
},
},
- PacketState, Property,
+ PacketState,
},
CrawlState,
};
@@ -64,14 +63,11 @@ pub struct Player {
uuid: RwLock