Some Renames

This commit is contained in:
Alexander Medvedev 2025-02-05 23:12:16 +01:00
parent 12866bce36
commit 3d789f7450
26 changed files with 85 additions and 79 deletions

View File

@ -34,7 +34,7 @@ The Documentation of Pumpkin can be found at <https://pumpkinmc.org/>
### Coding Guidelines ### Coding Guidelines
Things need to be done before this Pull Request can be merged. Your CI also checks most of them automatically and fill fail if something is not fulfilled Things need to be done before this Pull Request can be merged. Your CI also checks most of them automatically and fill fail if something is not fulfilled
Note: Pumpkin's clippy settings are relatively strict, this can be may frustrating but is necessary so the code says clean and conssistent Note: Pumpkin's clippy settings are relatively strict, this can be may frustrating but is necessary so the code says clean and consistent
**Basic** **Basic**
- **Title:** Use a concise and informative title that clearly communicates the purpose of the PR. Anyone reviewing the PR should quickly understand the changes being proposed. - **Title:** Use a concise and informative title that clearly communicates the purpose of the PR. Anyone reviewing the PR should quickly understand the changes being proposed.

View File

@ -50,8 +50,8 @@ rayon = "1.10"
parking_lot = { version = "0.12", features = ["send_guard"] } parking_lot = { version = "0.12", features = ["send_guard"] }
crossbeam = "0.8" crossbeam = "0.8"
uuid = { version = "1.12", features = ["serde", "v3", "v4"] } uuid = { version = "1.13", features = ["serde", "v3", "v4"] }
derive_more = { version = "1.0", features = ["full"] } derive_more = { version = "2.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"

View File

@ -7,14 +7,14 @@ pub struct CompressionConfig {
/// Whether compression is enabled /// Whether compression is enabled
pub enabled: bool, pub enabled: bool,
#[serde(flatten)] #[serde(flatten)]
pub compression_info: CompressionInfo, pub info: CompressionInfo,
} }
impl Default for CompressionConfig { impl Default for CompressionConfig {
fn default() -> Self { fn default() -> Self {
Self { Self {
enabled: true, enabled: true,
compression_info: Default::default(), info: Default::default(),
} }
} }
} }

View File

@ -33,22 +33,22 @@ impl Default for RCONConfig {
#[serde(default)] #[serde(default)]
pub struct RCONLogging { pub struct RCONLogging {
/// Whether successful RCON logins should be logged. /// Whether successful RCON logins should be logged.
pub log_logged_successfully: bool, pub logged_successfully: bool,
/// Whether failed RCON login attempts with incorrect passwords should be logged. /// Whether failed RCON login attempts with incorrect passwords should be logged.
pub log_wrong_password: bool, pub wrong_password: bool,
/// Whether all RCON commands, regardless of success or failure, should be logged. /// Whether all RCON commands, regardless of success or failure, should be logged.
pub log_commands: bool, pub commands: bool,
/// Whether RCON quit commands should be logged. /// Whether RCON quit commands should be logged.
pub log_quit: bool, pub quit: bool,
} }
impl Default for RCONLogging { impl Default for RCONLogging {
fn default() -> Self { fn default() -> Self {
Self { Self {
log_logged_successfully: true, logged_successfully: true,
log_wrong_password: true, wrong_password: true,
log_commands: true, commands: true,
log_quit: true, quit: true,
} }
} }
} }

View File

@ -5,11 +5,11 @@ use serde::{Deserialize, Serialize};
pub struct ResourcePackConfig { pub struct ResourcePackConfig {
pub enabled: bool, pub enabled: bool,
/// The path to the resource pack. /// The path to the resource pack.
pub resource_pack_url: String, pub url: String,
/// The SHA1 hash (40) of the resource pack. /// The SHA1 hash (40) of the resource pack.
pub resource_pack_sha1: String, pub sha1: String,
/// Custom prompt Text component, Leave blank for none /// Custom prompt Text component, Leave blank for none
pub prompt_message: String, pub message: String,
/// Will force the Player to accept the resource pack /// Will force the Player to accept the resource pack
pub force: bool, pub force: bool,
} }
@ -17,12 +17,12 @@ pub struct ResourcePackConfig {
impl ResourcePackConfig { impl ResourcePackConfig {
pub fn validate(&self) { pub fn validate(&self) {
assert_eq!( assert_eq!(
!self.resource_pack_url.is_empty(), !self.url.is_empty(),
!self.resource_pack_sha1.is_empty(), !self.sha1.is_empty(),
"Resource Pack path or Sha1 hash is missing" "Resource Pack path or Sha1 hash is missing"
); );
assert!( assert!(
self.resource_pack_sha1.len() <= 40, self.sha1.len() <= 40,
"Resource pack sha1 hash is too long (max. 40)" "Resource pack sha1 hash is too long (max. 40)"
) )
} }

View File

@ -48,7 +48,7 @@ pub trait ByteBuf: Buf {
fn try_get_var_long(&mut self) -> Result<VarLong, ReadingError>; fn try_get_var_long(&mut self) -> Result<VarLong, ReadingError>;
fn try_get_identifer(&mut self) -> Result<Identifier, ReadingError>; fn try_get_identifier(&mut self) -> Result<Identifier, ReadingError>;
fn try_get_string(&mut self) -> Result<String, ReadingError>; fn try_get_string(&mut self) -> Result<String, ReadingError>;
@ -170,12 +170,12 @@ impl<T: Buf> ByteBuf for T {
self.try_copy_to_bytes(bits.div_ceil(8)) self.try_copy_to_bytes(bits.div_ceil(8))
} }
fn try_get_identifer(&mut self) -> Result<Identifier, ReadingError> { fn try_get_identifier(&mut self) -> Result<Identifier, ReadingError> {
match Identifier::decode(self) { match Identifier::decode(self) {
Ok(identifer) => Ok(identifer), Ok(identifier) => Ok(identifier),
Err(error) => match error { Err(error) => match error {
DecodeError::Incomplete => Err(ReadingError::Incomplete("identifer".to_string())), DecodeError::Incomplete => Err(ReadingError::Incomplete("identifier".to_string())),
DecodeError::TooLarge => Err(ReadingError::TooLarge("identifer".to_string())), DecodeError::TooLarge => Err(ReadingError::TooLarge("identifier".to_string())),
}, },
} }
} }

View File

@ -8,7 +8,7 @@ use serde::Serialize;
pub struct CTakeItemEntity { pub struct CTakeItemEntity {
/// The Entity ID of the Item Entity /// The Entity ID of the Item Entity
entity_id: VarInt, entity_id: VarInt,
/// The Entity ID of the Entitiy who is collecting the Item /// The Entity ID of the Entity who is collecting the Item
collector_entity_id: VarInt, collector_entity_id: VarInt,
/// The Number of items in the Stack /// The Number of items in the Stack
stack_amount: VarInt, stack_amount: VarInt,

View File

@ -5,7 +5,7 @@ use serde::Serialize;
#[derive(Serialize)] #[derive(Serialize)]
#[client_packet(STATUS_PONG_RESPONSE)] #[client_packet(STATUS_PONG_RESPONSE)]
pub struct CPingResponse { pub struct CPingResponse {
payload: i64, // must responde with the same as in `SPingRequest` payload: i64, // must respond with the same as in `SPingRequest`
} }
impl CPingResponse { impl CPingResponse {

View File

@ -22,7 +22,7 @@ impl Identifier {
} }
} }
impl Codec<Self> for Identifier { impl Codec<Self> for Identifier {
/// The maximum number of bytes a `Identifer` is the same as for a normal String. /// The maximum number of bytes a `Identifier` is the same as for a normal String.
const MAX_SIZE: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(i16::MAX as usize) }; const MAX_SIZE: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(i16::MAX as usize) };
fn written_size(&self) -> usize { fn written_size(&self) -> usize {
@ -34,10 +34,10 @@ impl Codec<Self> for Identifier {
} }
fn decode(read: &mut impl Buf) -> Result<Self, DecodeError> { fn decode(read: &mut impl Buf) -> Result<Self, DecodeError> {
let identifer = read let identifier = read
.try_get_string_len(Self::MAX_SIZE.get()) .try_get_string_len(Self::MAX_SIZE.get())
.map_err(|_| DecodeError::Incomplete)?; .map_err(|_| DecodeError::Incomplete)?;
match identifer.split_once(":") { match identifier.split_once(":") {
Some((namespace, path)) => Ok(Identifier { Some((namespace, path)) => Ok(Identifier {
namespace: namespace.to_string(), namespace: namespace.to_string(),
path: path.to_string(), path: path.to_string(),
@ -77,11 +77,11 @@ impl<'de> Deserialize<'de> for Identifier {
self.visit_str(&v) self.visit_str(&v)
} }
fn visit_str<E>(self, identifer: &str) -> Result<Self::Value, E> fn visit_str<E>(self, identifier: &str) -> Result<Self::Value, E>
where where
E: serde::de::Error, E: serde::de::Error,
{ {
match identifer.split_once(":") { match identifier.split_once(":") {
Some((namespace, path)) => Ok(Identifier { Some((namespace, path)) => Ok(Identifier {
namespace: namespace.to_string(), namespace: namespace.to_string(),
path: path.to_string(), path: path.to_string(),

View File

@ -10,9 +10,9 @@ use crate::{
type Cipher = cfb8::Decryptor<aes::Aes128>; type Cipher = cfb8::Decryptor<aes::Aes128>;
// Decoder: Client -> Server /// Decoder: Client -> Server
// Supports ZLib decoding/decompression /// Supports ZLib decoding/decompression
// Supports Aes128 Encryption /// Supports Aes128 Encryption
#[derive(Default)] #[derive(Default)]
pub struct PacketDecoder { pub struct PacketDecoder {
buf: BytesMut, buf: BytesMut,

View File

@ -22,7 +22,7 @@ const MAX_COOKIE_LENGTH: usize = 5120;
impl ServerPacket for SConfigCookieResponse { impl ServerPacket for SConfigCookieResponse {
fn read(bytebuf: &mut impl Buf) -> Result<Self, ReadingError> { fn read(bytebuf: &mut impl Buf) -> Result<Self, ReadingError> {
let key = bytebuf.try_get_identifer()?; let key = bytebuf.try_get_identifier()?;
let has_payload = bytebuf.try_get_bool()?; let has_payload = bytebuf.try_get_bool()?;
if !has_payload { if !has_payload {

View File

@ -18,7 +18,7 @@ pub struct SPluginMessage {
impl ServerPacket for SPluginMessage { impl ServerPacket for SPluginMessage {
fn read(bytebuf: &mut impl Buf) -> Result<Self, ReadingError> { fn read(bytebuf: &mut impl Buf) -> Result<Self, ReadingError> {
Ok(Self { Ok(Self {
channel: bytebuf.try_get_identifer()?, channel: bytebuf.try_get_identifier()?,
data: bytebuf.try_copy_to_bytes_len(bytebuf.remaining(), MAX_PAYLOAD_SIZE)?, data: bytebuf.try_copy_to_bytes_len(bytebuf.remaining(), MAX_PAYLOAD_SIZE)?,
}) })
} }

View File

@ -21,7 +21,7 @@ const MAX_COOKIE_LENGTH: usize = 5120;
impl ServerPacket for SLoginCookieResponse { impl ServerPacket for SLoginCookieResponse {
fn read(bytebuf: &mut impl Buf) -> Result<Self, ReadingError> { fn read(bytebuf: &mut impl Buf) -> Result<Self, ReadingError> {
let key = bytebuf.try_get_identifer()?; let key = bytebuf.try_get_identifier()?;
let has_payload = bytebuf.try_get_bool()?; let has_payload = bytebuf.try_get_bool()?;
if !has_payload { if !has_payload {

View File

@ -21,7 +21,7 @@ const MAX_COOKIE_LENGTH: usize = 5120;
impl ServerPacket for SCookieResponse { impl ServerPacket for SCookieResponse {
fn read(bytebuf: &mut impl Buf) -> Result<Self, ReadingError> { fn read(bytebuf: &mut impl Buf) -> Result<Self, ReadingError> {
let key = bytebuf.try_get_identifer()?; let key = bytebuf.try_get_identifier()?;
let has_payload = bytebuf.try_get_bool()?; let has_payload = bytebuf.try_get_bool()?;
if !has_payload { if !has_payload {

View File

@ -40,6 +40,8 @@ pub mod mob;
pub mod player; pub mod player;
pub mod projectile; pub mod projectile;
mod combat;
pub type EntityId = i32; pub type EntityId = i32;
#[async_trait] #[async_trait]

View File

@ -66,14 +66,15 @@ use pumpkin_world::{
}; };
use tokio::sync::{Mutex, Notify, RwLock}; use tokio::sync::{Mutex, Notify, RwLock};
use super::{item::ItemEntity, Entity, EntityId, NBTStorage}; use super::{
combat::{self, player_attack_sound, AttackType},
item::ItemEntity,
Entity, EntityId, NBTStorage,
};
use crate::{ use crate::{
command::{client_suggestions, dispatcher::CommandDispatcher}, command::{client_suggestions, dispatcher::CommandDispatcher},
data::op_data::OPERATOR_CONFIG, data::op_data::OPERATOR_CONFIG,
net::{ net::{Client, PlayerConfig},
combat::{self, player_attack_sound, AttackType},
Client, PlayerConfig,
},
server::Server, server::Server,
world::World, world::World,
}; };

View File

@ -46,7 +46,6 @@ use tokio::sync::Mutex;
use thiserror::Error; use thiserror::Error;
use uuid::Uuid; use uuid::Uuid;
mod authentication; mod authentication;
pub mod combat;
mod container; mod container;
pub mod lan_broadcast; pub mod lan_broadcast;
mod packet; mod packet;

View File

@ -233,11 +233,7 @@ impl Client {
} }
async fn enable_compression(&self) { async fn enable_compression(&self) {
let compression = ADVANCED_CONFIG let compression = ADVANCED_CONFIG.networking.packet_compression.info.clone();
.networking
.packet_compression
.compression_info
.clone();
self.send_packet(&CSetCompression::new(compression.threshold.into())) self.send_packet(&CSetCompression::new(compression.threshold.into()))
.await; .await;
self.set_compression(Some(compression)).await; self.set_compression(Some(compression)).await;
@ -334,17 +330,14 @@ impl Client {
let resource_config = &ADVANCED_CONFIG.resource_pack; let resource_config = &ADVANCED_CONFIG.resource_pack;
if resource_config.enabled { if resource_config.enabled {
let resource_pack = CConfigAddResourcePack::new( let resource_pack = CConfigAddResourcePack::new(
Uuid::new_v3( Uuid::new_v3(&uuid::Uuid::NAMESPACE_DNS, resource_config.url.as_bytes()),
&uuid::Uuid::NAMESPACE_DNS, &resource_config.url,
resource_config.resource_pack_url.as_bytes(), &resource_config.sha1,
),
&resource_config.resource_pack_url,
&resource_config.resource_pack_sha1,
resource_config.force, resource_config.force,
if resource_config.prompt_message.is_empty() { if resource_config.message.is_empty() {
None None
} else { } else {
Some(TextComponent::text(&resource_config.prompt_message)) Some(TextComponent::text(&resource_config.message))
}, },
); );

View File

@ -10,7 +10,7 @@ use crate::{
entity::player::{ChatMode, Hand, Player}, entity::player::{ChatMode, Hand, Player},
error::PumpkinError, error::PumpkinError,
server::Server, server::Server,
world::player_chunker, world::chunker,
}; };
use pumpkin_config::ADVANCED_CONFIG; use pumpkin_config::ADVANCED_CONFIG;
use pumpkin_data::entity::{EntityPose, EntityType}; use pumpkin_data::entity::{EntityPose, EntityType};
@ -204,7 +204,7 @@ impl Player {
) )
.await; .await;
} }
player_chunker::update_position(self).await; chunker::update_position(self).await;
} }
pub async fn handle_position_rotation(self: &Arc<Self>, packet: SPlayerPositionRotation) { pub async fn handle_position_rotation(self: &Arc<Self>, packet: SPlayerPositionRotation) {
@ -296,7 +296,7 @@ impl Player {
) )
.await; .await;
} }
player_chunker::update_position(self).await; chunker::update_position(self).await;
} }
pub async fn handle_rotation(&self, rotation: SPlayerRotation) { pub async fn handle_rotation(&self, rotation: SPlayerRotation) {
@ -614,9 +614,9 @@ impl Player {
return; return;
} }
let (update_skin, update_watched) = { let (update_settings, update_watched) = {
let mut config = self.config.lock().await; let mut config = self.config.lock().await;
let update_skin = config.main_hand != main_hand let update_settings = config.main_hand != main_hand
|| config.skin_parts != client_information.skin_parts; || config.skin_parts != client_information.skin_parts;
let old_view_distance = config.view_distance; let old_view_distance = config.view_distance;
@ -649,14 +649,14 @@ impl Player {
text_filtering: client_information.text_filtering, text_filtering: client_information.text_filtering,
server_listing: client_information.server_listing, server_listing: client_information.server_listing,
}; };
(update_skin, update_watched) (update_settings, update_watched)
}; };
if update_watched { if update_watched {
player_chunker::update_position(self).await; chunker::update_position(self).await;
} }
if update_skin { if update_settings {
log::debug!( log::debug!(
"Player {} ({}) updated their skin.", "Player {} ({}) updated their skin.",
self.gameprofile.name, self.gameprofile.name,

View File

@ -89,12 +89,12 @@ impl RCONClient {
if packet.get_body() == password { if packet.get_body() == password {
self.send(ClientboundPacket::AuthResponse, packet.get_id(), "") self.send(ClientboundPacket::AuthResponse, packet.get_id(), "")
.await?; .await?;
if config.logging.log_logged_successfully { if config.logging.logged_successfully {
log::info!("RCON ({}): Client logged in successfully", self.address); log::info!("RCON ({}): Client logged in successfully", self.address);
} }
self.logged_in = true; self.logged_in = true;
} else { } else {
if config.logging.log_wrong_password { if config.logging.wrong_password {
log::info!("RCON ({}): Client has tried wrong password", self.address); log::info!("RCON ({}): Client has tried wrong password", self.address);
} }
self.send(ClientboundPacket::AuthResponse, -1, "").await?; self.send(ClientboundPacket::AuthResponse, -1, "").await?;
@ -121,7 +121,7 @@ impl RCONClient {
let output = output.lock().await; let output = output.lock().await;
for line in output.iter() { for line in output.iter() {
if config.logging.log_commands { if config.logging.commands {
log::info!("RCON ({}): {}", self.address, line); log::info!("RCON ({}): {}", self.address, line);
} }
self.send(ClientboundPacket::Output, packet.get_id(), line) self.send(ClientboundPacket::Output, packet.get_id(), line)

View File

@ -3,8 +3,8 @@ use std::{
sync::{atomic::Ordering, Arc}, sync::{atomic::Ordering, Arc},
}; };
pub mod level_time; pub mod chunker;
pub mod player_chunker; pub mod time;
use crate::{ use crate::{
command::client_suggestions, command::client_suggestions,
@ -18,7 +18,7 @@ use crate::{
server::Server, server::Server,
PLUGIN_MANAGER, PLUGIN_MANAGER,
}; };
use level_time::LevelTime; use border::Worldborder;
use pumpkin_config::BasicConfiguration; use pumpkin_config::BasicConfiguration;
use pumpkin_data::{ use pumpkin_data::{
entity::EntityType, entity::EntityType,
@ -50,18 +50,18 @@ use pumpkin_world::{
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use scoreboard::Scoreboard; use scoreboard::Scoreboard;
use thiserror::Error; use thiserror::Error;
use time::LevelTime;
use tokio::sync::{mpsc::Receiver, Mutex}; use tokio::sync::{mpsc::Receiver, Mutex};
use tokio::{ use tokio::{
runtime::Handle, runtime::Handle,
sync::{mpsc, RwLock}, sync::{mpsc, RwLock},
}; };
use worldborder::Worldborder;
pub mod border;
pub mod bossbar; pub mod bossbar;
pub mod custom_bossbar; pub mod custom_bossbar;
pub mod scoreboard; pub mod scoreboard;
pub mod weather; pub mod weather;
pub mod worldborder;
use weather::Weather; use weather::Weather;
@ -223,13 +223,23 @@ impl World {
} }
pub async fn play_record(&self, record_id: i32, position: BlockPos) { pub async fn play_record(&self, record_id: i32, position: BlockPos) {
self.broadcast_packet_all(&CLevelEvent::new(1010, position, record_id, false)) self.broadcast_packet_all(&CLevelEvent::new(
.await; WorldEvent::JukeboxStartsPlaying as i32,
position,
record_id,
false,
))
.await;
} }
pub async fn stop_record(&self, position: BlockPos) { pub async fn stop_record(&self, position: BlockPos) {
self.broadcast_packet_all(&CLevelEvent::new(1011, position, 0, false)) self.broadcast_packet_all(&CLevelEvent::new(
.await; WorldEvent::JukeboxStopsPlaying as i32,
position,
0,
false,
))
.await;
} }
pub async fn tick(&self) { pub async fn tick(&self) {
@ -499,7 +509,7 @@ impl World {
} }
// Spawn in initial chunks // Spawn in initial chunks
player_chunker::player_join(&player).await; chunker::player_join(&player).await;
// if let Some(bossbars) = self..lock().await.get_player_bars(&player.gameprofile.id) { // if let Some(bossbars) = self..lock().await.get_player_bars(&player.gameprofile.id) {
// for bossbar in bossbars { // for bossbar in bossbars {
@ -600,7 +610,7 @@ impl World {
.await; .await;
player.send_client_information().await; player.send_client_information().await;
player_chunker::player_join(player).await; chunker::player_join(player).await;
// update commands // update commands
player.set_health(20.0, 20, 20.0).await; player.set_health(20.0, 20, 20.0).await;

View File

@ -0,0 +1 @@
☃