diff --git a/extractor/src/main/kotlin/de/snowii/extractor/Extractor.kt b/extractor/src/main/kotlin/de/snowii/extractor/Extractor.kt index a9ff4007d..9140a9550 100644 --- a/extractor/src/main/kotlin/de/snowii/extractor/Extractor.kt +++ b/extractor/src/main/kotlin/de/snowii/extractor/Extractor.kt @@ -27,7 +27,7 @@ class Extractor : ModInitializer { Recipes(), Particles(), SyncedRegistries(), - Packet(), + Packets(), Screens(), Items(), Blocks(), diff --git a/extractor/src/main/kotlin/de/snowii/extractor/extractors/Packet.kt b/extractor/src/main/kotlin/de/snowii/extractor/extractors/Packets.kt similarity index 97% rename from extractor/src/main/kotlin/de/snowii/extractor/extractors/Packet.kt rename to extractor/src/main/kotlin/de/snowii/extractor/extractors/Packets.kt index b358827de..de666ff31 100644 --- a/extractor/src/main/kotlin/de/snowii/extractor/extractors/Packet.kt +++ b/extractor/src/main/kotlin/de/snowii/extractor/extractors/Packets.kt @@ -12,7 +12,7 @@ import net.minecraft.network.state.* import net.minecraft.server.MinecraftServer -class Packet : Extractor.Extractor { +class Packets : Extractor.Extractor { override fun fileName(): String { return "packets.json" } diff --git a/extractor/src/main/kotlin/de/snowii/extractor/extractors/Recipes.kt b/extractor/src/main/kotlin/de/snowii/extractor/extractors/Recipes.kt index de6243cce..371f92505 100644 --- a/extractor/src/main/kotlin/de/snowii/extractor/extractors/Recipes.kt +++ b/extractor/src/main/kotlin/de/snowii/extractor/extractors/Recipes.kt @@ -22,6 +22,7 @@ class Recipes : Extractor.Extractor { recipeJson.addProperty("name", recipeRaw.id.value.toString()) val recipe: Recipe<*> = recipeRaw.value() + recipeJson.addProperty("category", recipe.group) recipeJson.addProperty("group", recipe.group) recipeJson.addProperty("type", recipe.type.toString()) val placementArray = JsonArray() diff --git a/pumpkin-inventory/src/lib.rs b/pumpkin-inventory/src/lib.rs index db9147aa9..f7e64aace 100644 --- a/pumpkin-inventory/src/lib.rs +++ b/pumpkin-inventory/src/lib.rs @@ -16,7 +16,7 @@ pub use open_container::OpenContainer; /// https://wiki.vg/Inventory #[derive(Debug, ToPrimitive, FromPrimitive, Clone, Copy, Eq, PartialEq)] -#[repr(u16)] +#[repr(u8)] pub enum WindowType { // not used Generic9x1 = screen!("minecraft:generic_9x1"), diff --git a/pumpkin-macros/src/lib.rs b/pumpkin-macros/src/lib.rs index cd7c79580..82dfad011 100644 --- a/pumpkin-macros/src/lib.rs +++ b/pumpkin-macros/src/lib.rs @@ -7,9 +7,7 @@ mod packet; #[proc_macro_attribute] pub fn client_packet(input: TokenStream, item: TokenStream) -> TokenStream { let ast: syn::DeriveInput = syn::parse(item.clone()).unwrap(); - let name = &ast.ident; - let (impl_generics, ty_generics, _) = ast.generics.split_for_impl(); let input: proc_macro2::TokenStream = packet::packet_clientbound(input); @@ -28,9 +26,7 @@ pub fn client_packet(input: TokenStream, item: TokenStream) -> TokenStream { #[proc_macro_attribute] pub fn server_packet(input: TokenStream, item: TokenStream) -> TokenStream { let ast: syn::DeriveInput = syn::parse(item.clone()).unwrap(); - let name = &ast.ident; - let (impl_generics, ty_generics, _) = ast.generics.split_for_impl(); let input: proc_macro2::TokenStream = packet::packet_serverbound(input); diff --git a/pumpkin-macros/src/screen.rs b/pumpkin-macros/src/screen.rs index 2c8da2886..2983acc46 100644 --- a/pumpkin-macros/src/screen.rs +++ b/pumpkin-macros/src/screen.rs @@ -7,10 +7,10 @@ use serde::Deserialize; #[derive(Deserialize)] pub struct Screen { name: String, - id: u16, + id: u8, } -static SCREENS: LazyLock> = LazyLock::new(|| { +static SCREENS: LazyLock> = LazyLock::new(|| { serde_json::from_str::>(include_str!("../../assets/screens.json")) .expect("Could not parse screens.json registry.") .into_iter() diff --git a/pumpkin-protocol/README.md b/pumpkin-protocol/README.md deleted file mode 100644 index e7b469872..000000000 --- a/pumpkin-protocol/README.md +++ /dev/null @@ -1,80 +0,0 @@ -### Pumpkin Protocol -Contains all Serverbound(Client->Server) and Clientbound(Server->Client) Packets. - -### Features -- [x] ZLib Compression -- [x] AES/CFB8 Encryiption - -Packets in the Pumpkin protocol are organized by functionality and state. - -`server`: Contains definitions for serverbound packets. - -`client`: Contains definitions for clientbound packets. - -### States: -**Handshake**: Always the first packet being send from the Client. This begins also determins the next state, usally to indicate if the player thans perform a Status Request, Join the Server or wants to be transfered. - -**Status**: Indicates the Client wants to see a Status response (MOTD). - -**Login**: The Login sequence. Indicates the Client wants to join to the Server - -**Config**: A sequence of Configuration packets beining mostly send from the Server to the Client. (Features, Resource Pack, Server Links...) - -**Play**: The final state which indicate the Player is now ready to Join in also used to handle all other Gameplay packets. - -### How to add a Packet ? -You can find all Minecraft Java packets at https://wiki.vg/Protocol. There you also can see in which [State](State) they are. -You also can see all the information the Packets has which we can either Write or Read depending if its Serverbound or Clientbound -#### Adding a Packet -Adding a Packet is easy. First you have to dereive serde Serialize for Clientbound Packets or Deserialize for Serverbound packets. -```rust -#[derive(Serialize)] -``` -Next you have set the packet id using the packet macro -```rust -#[packet(0x1D)] -``` -Now you can create the Field. Please start the Packet name with "C" if its Clientbound and with "S" if its Serverbound. -Example: -```rust -pub struct CPlayDisconnect { - reason: TextComponent, - more fields... -} -``` -Also don't forgot to impl a new function for Clientbound Packets so we can actaully send then by putting in the values :D -Example: -```rust -impl CPlayDisconnect { - pub fn new(reason: TextComponent) -> Self { - Self { reason } - } -} -``` -At the End everything should come together, -Thats a Clientbound Packet -```rust -#[derive(Serialize)] -#[packet(0x1D)] -pub struct CPlayDisconnect { - reason: TextComponent, -} - -impl CPlayDisconnect { - pub fn new(reason: TextComponent) -> Self { - Self { reason } - } -} -``` -Thats a Serverbound packet -```rust -#[derive(Deserialize)] -#[packet(0x1D)] -pub struct CPlayDisconnect { - reason: TextComponent, -} -``` - -### Porting -You can compare difference in Protocol on wiki.vg https://wiki.vg/index.php?title=Protocol&action=history -Also change the `CURRENT_MC_PROTOCOL` in `src/lib.rs` \ No newline at end of file diff --git a/pumpkin-registry/README.md b/pumpkin-registry/README.md deleted file mode 100644 index cd0b46392..000000000 --- a/pumpkin-registry/README.md +++ /dev/null @@ -1,5 +0,0 @@ -### Pumpkin Registry -Here you find all the registry data we have. -Registries are repositories of data that contain entries pertaining to certain aspects of the game, such as the world, the player, among others. -Registry data usually send by the Clientbound Registry data Packet. -A list of Registry entries can be found at https://wiki.vg/Registry_Data \ No newline at end of file diff --git a/pumpkin-world/README.md b/pumpkin-world/README.md deleted file mode 100644 index 40637233c..000000000 --- a/pumpkin-world/README.md +++ /dev/null @@ -1,17 +0,0 @@ -### Pumpkin World -Contains everything World related for example - -- Loading Chunks (Anvil Format) -- Generating Chunks -- Loading Blocks/Items - -### Porting -When updating your Minecraft server to a newer version, you typically need to replace the files in the assets directory to ensure compatibility with the new version's resources. -Thankfully, vanilla Minecraft provides a way to extract these updated assets directly from the server JAR file itself. - -1. Download the latest Minecraft server JAR file for the version you want to upgrade to. -2. Run `java -DbundlerMainClass=net.minecraft.data.Main -jar .jar --reports`. -3. This command will create a new folder named `reports` in the same directory as the server JAR. This folder contains the updated "assets" directory for the new version. -4. Copy the assets folder from the reports folder and replace the existing assets directory within your server directory. - -For details see https://wiki.vg/Data_Generators diff --git a/pumpkin-world/src/cylindrical_chunk_iterator.rs b/pumpkin-world/src/cylindrical_chunk_iterator.rs index 39a873018..d1146557f 100644 --- a/pumpkin-world/src/cylindrical_chunk_iterator.rs +++ b/pumpkin-world/src/cylindrical_chunk_iterator.rs @@ -3,11 +3,11 @@ use pumpkin_core::math::vector2::Vector2; #[derive(Debug, PartialEq)] pub struct Cylindrical { pub center: Vector2, - pub view_distance: i32, + pub view_distance: u8, } impl Cylindrical { - pub fn new(center: Vector2, view_distance: i32) -> Self { + pub fn new(center: Vector2, view_distance: u8) -> Self { Self { center, view_distance, @@ -45,19 +45,19 @@ impl Cylindrical { } fn left(&self) -> i32 { - self.center.x - self.view_distance - 1 + self.center.x - self.view_distance as i32 - 1 } fn bottom(&self) -> i32 { - self.center.z - self.view_distance - 1 + self.center.z - self.view_distance as i32 - 1 } fn right(&self) -> i32 { - self.center.x + self.view_distance + 1 + self.center.x + self.view_distance as i32 + 1 } fn top(&self) -> i32 { - self.center.z + self.view_distance + 1 + self.center.z + self.view_distance as i32 + 1 } fn is_within_distance(&self, x: i32, z: i32) -> bool { diff --git a/pumpkin/src/client/client_packet.rs b/pumpkin/src/client/client_packet.rs index 8fd1ac97a..cee93fa06 100644 --- a/pumpkin/src/client/client_packet.rs +++ b/pumpkin/src/client/client_packet.rs @@ -8,10 +8,10 @@ use pumpkin_protocol::{ status::CPingResponse, }, server::{ - config::{SAcknowledgeFinishConfig, SClientInformationConfig, SKnownPacks, SPluginMessage}, + config::{SClientInformationConfig, SKnownPacks, SPluginMessage}, handshake::SHandShake, - login::{SEncryptionResponse, SLoginAcknowledged, SLoginPluginResponse, SLoginStart}, - status::{SStatusPingRequest, SStatusRequest}, + login::{SEncryptionResponse, SLoginPluginResponse, SLoginStart}, + status::SStatusPingRequest, }, ConnectionState, KnownPack, CURRENT_MC_PROTOCOL, }; @@ -55,14 +55,14 @@ impl Client { } } - pub async fn handle_status_request(&self, server: &Server, _status_request: SStatusRequest) { - log::debug!("Handling status request for id"); + pub async fn handle_status_request(&self, server: &Server) { + log::debug!("Handling status request"); let status = server.get_status(); self.send_packet(&status.lock().await.get_status()).await; } pub async fn handle_ping_request(&self, ping_request: SStatusPingRequest) { - log::debug!("Handling ping request for id"); + log::debug!("Handling ping request"); self.send_packet(&CPingResponse::new(ping_request.payload)) .await; self.close(); @@ -147,7 +147,7 @@ impl Client { server: &Server, encryption_response: SEncryptionResponse, ) { - log::debug!("Handling encryption for id"); + log::debug!("Handling encryption"); let shared_secret = server.decrypt(&encryption_response.shared_secret).unwrap(); if let Err(error) = self.set_encryption(Some(&shared_secret)).await { @@ -254,7 +254,7 @@ impl Client { } pub async fn handle_plugin_response(&self, plugin_response: SLoginPluginResponse) { - log::debug!("Handling plugin for id"); + log::debug!("Handling plugin"); let velocity_config = &ADVANCED_CONFIG.proxy.velocity; if velocity_config.enabled { let mut address = self.address.lock().await; @@ -273,12 +273,8 @@ impl Client { } } - pub async fn handle_login_acknowledged( - &self, - server: &Server, - _login_acknowledged: SLoginAcknowledged, - ) { - log::debug!("Handling login acknowledged for id"); + pub async fn handle_login_acknowledged(&self, server: &Server) { + log::debug!("Handling login acknowledged"); self.connection_state.store(ConnectionState::Config); self.send_packet(&server.get_branding()).await; @@ -315,14 +311,14 @@ impl Client { &self, client_information: SClientInformationConfig, ) { - log::debug!("Handling client settings for id"); + log::debug!("Handling client settings"); if let (Some(main_hand), Some(chat_mode)) = ( Hand::from_i32(client_information.main_hand.into()), ChatMode::from_i32(client_information.chat_mode.into()), ) { *self.config.lock().await = Some(PlayerConfig { locale: client_information.locale, - view_distance: client_information.view_distance, + view_distance: client_information.view_distance as u8, chat_mode, chat_colors: client_information.chat_colors, skin_parts: client_information.skin_parts, @@ -336,7 +332,7 @@ impl Client { } pub async fn handle_plugin_message(&self, plugin_message: SPluginMessage) { - log::debug!("Handling plugin message for id"); + log::debug!("Handling plugin message"); if plugin_message.channel.starts_with("minecraft:brand") || plugin_message.channel.starts_with("MC|Brand") { @@ -349,7 +345,7 @@ impl Client { } pub async fn handle_known_packs(&self, server: &Server, _config_acknowledged: SKnownPacks) { - log::debug!("Handling known packs for id"); + log::debug!("Handling known packs"); for registry in &server.cached_registry { self.send_packet(&CRegistryData::new( ®istry.registry_id, @@ -363,8 +359,8 @@ impl Client { self.send_packet(&CFinishConfig::new()).await; } - pub fn handle_config_acknowledged(&self, _config_acknowledged: &SAcknowledgeFinishConfig) { - log::debug!("Handling config acknowledge for id"); + pub fn handle_config_acknowledged(&self) { + log::debug!("Handling config acknowledge"); self.connection_state.store(ConnectionState::Play); self.make_player .store(true, std::sync::atomic::Ordering::Relaxed); diff --git a/pumpkin/src/client/container.rs b/pumpkin/src/client/container.rs index 31a528ec1..7c145c2e0 100644 --- a/pumpkin/src/client/container.rs +++ b/pumpkin/src/client/container.rs @@ -134,6 +134,7 @@ impl Player { } let click = Click::new( + // TODO: This is very bad packet .mode .0 diff --git a/pumpkin/src/client/mod.rs b/pumpkin/src/client/mod.rs index 12f018f77..73379cd03 100644 --- a/pumpkin/src/client/mod.rs +++ b/pumpkin/src/client/mod.rs @@ -52,7 +52,7 @@ pub struct PlayerConfig { /// The player's preferred language. pub locale: String, // 16 /// The maximum distance at which chunks are rendered. - pub view_distance: i8, + pub view_distance: u8, /// The player's chat mode settings pub chat_mode: ChatMode, /// Whether chat colors are enabled. @@ -392,8 +392,7 @@ impl Client { let bytebuf = &mut packet.bytebuf; match packet.id.0 { SStatusRequest::PACKET_ID => { - self.handle_status_request(server, SStatusRequest::read(bytebuf)?) - .await; + self.handle_status_request(server).await; } SStatusPingRequest::PACKET_ID => { self.handle_ping_request(SStatusPingRequest::read(bytebuf)?) @@ -432,8 +431,7 @@ impl Client { .await; } SLoginAcknowledged::PACKET_ID => { - self.handle_login_acknowledged(server, SLoginAcknowledged::read(bytebuf)?) - .await; + self.handle_login_acknowledged(server).await; } _ => { log::error!( @@ -463,7 +461,7 @@ impl Client { .await; } SAcknowledgeFinishConfig::PACKET_ID => { - self.handle_config_acknowledged(&SAcknowledgeFinishConfig::read(bytebuf)?); + self.handle_config_acknowledged(); } SKnownPacks::PACKET_ID => { self.handle_known_packs(server, SKnownPacks::read(bytebuf)?) diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index 404ae7a52..6d335d459 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -384,7 +384,8 @@ impl Player { ) { *self.config.lock().await = PlayerConfig { locale: client_information.locale, - view_distance: client_information.view_distance, + // A Negative view distance would be impossible and make no sense right ?, Mojang: Lets make is signed :D + view_distance: client_information.view_distance as u8, chat_mode, chat_colors: client_information.chat_colors, skin_parts: client_information.skin_parts, @@ -398,7 +399,7 @@ impl Player { } } - pub async fn handle_interact(&self, _: &Server, interact: SInteract) { + pub async fn handle_interact(&self, interact: SInteract) { let sneaking = interact.sneaking; let entity = &self.living_entity.entity; if entity.sneaking.load(std::sync::atomic::Ordering::Relaxed) != sneaking { diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index a3d91428f..7e8f0854a 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -223,7 +223,7 @@ impl Player { world.remove_player(self).await; let watched = self.watched_section.load(); - let view_distance = i32::from(get_view_distance(self).await); + let view_distance = get_view_distance(self).await; let cylindrical = Cylindrical::new(Vector2::new(watched.x, watched.z), view_distance); // NOTE: This all must be synchronous to make sense! The chunks are handled asynhrously. @@ -676,8 +676,7 @@ impl Player { .await; } SInteract::PACKET_ID => { - self.handle_interact(server, SInteract::read(bytebuf)?) - .await; + self.handle_interact(SInteract::read(bytebuf)?).await; } SKeepAlive::PACKET_ID => { self.handle_keep_alive(SKeepAlive::read(bytebuf)?).await; diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 8b7ca6071..4a150a07c 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -5,8 +5,6 @@ // REMOVE SOME WHEN RELEASE #![expect(clippy::cargo_common_metadata)] #![expect(clippy::multiple_crate_versions)] -#![expect(clippy::significant_drop_in_scrutinee)] -#![expect(clippy::significant_drop_tightening)] #![expect(clippy::single_call_fn)] #![expect(clippy::cast_sign_loss)] #![expect(clippy::cast_possible_truncation)] diff --git a/pumpkin/src/world/player_chunker.rs b/pumpkin/src/world/player_chunker.rs index f81aacce4..2c4be9da4 100644 --- a/pumpkin/src/world/player_chunker.rs +++ b/pumpkin/src/world/player_chunker.rs @@ -11,13 +11,13 @@ use crate::entity::player::Player; use super::World; -pub async fn get_view_distance(player: &Player) -> i8 { +pub async fn get_view_distance(player: &Player) -> u8 { player .config .lock() .await .view_distance - .clamp(2, BASIC_CONFIG.view_distance as i8) + .clamp(2, BASIC_CONFIG.view_distance) } pub async fn player_join(world: &World, player: Arc) { @@ -36,7 +36,7 @@ pub async fn player_join(world: &World, player: Arc) { chunk_z: chunk_pos.z.into(), }) .await; - let view_distance = i32::from(get_view_distance(&player).await); + let view_distance = get_view_distance(&player).await; log::debug!( "Player {} ({}) joined with view distance: {}", player.gameprofile.name, @@ -70,7 +70,7 @@ pub async fn update_position(player: &Arc) { }) .await; - let view_distance = i32::from(get_view_distance(player).await); + let view_distance = get_view_distance(player).await; let old_cylindrical = Cylindrical::new( Vector2::new(current_watched.x, current_watched.z), view_distance,