Add Particles

This commit is contained in:
Snowiiii 2024-08-16 12:45:58 +02:00
parent 3b43322567
commit bf92fe22a0
6 changed files with 80 additions and 40 deletions

View File

@ -59,6 +59,7 @@ and customizable experience. It prioritizes performance and player enjoyment whi
- [ ] Query - [ ] Query
- [x] RCON - [x] RCON
- [x] Inventories - [x] Inventories
- [x] Particles
- [x] Chat - [x] Chat
- [x] Commands - [x] Commands
- Proxy - Proxy

View File

@ -0,0 +1,51 @@
use pumpkin_macros::packet;
use serde::Serialize;
use crate::VarInt;
#[derive(Serialize)]
#[packet(0x29)]
pub struct CParticle<'a> {
/// If true, particle distance increases from 256 to 65536.
long_distance: bool,
x: f64,
y: f64,
z: f64,
offset_x: f32,
offset_y: f32,
offset_z: f32,
max_speed: f32,
particle_count: i32,
pariticle_id: VarInt,
data: &'a [u8],
}
impl<'a> CParticle<'a> {
pub fn new(
long_distance: bool,
x: f64,
y: f64,
z: f64,
offset_x: f32,
offset_y: f32,
offset_z: f32,
max_speed: f32,
particle_count: i32,
pariticle_id: VarInt,
data: &'a [u8],
) -> Self {
Self {
long_distance,
x,
y,
z,
offset_x,
offset_y,
offset_z,
max_speed,
particle_count,
pariticle_id,
data,
}
}
}

View File

@ -11,6 +11,7 @@ mod c_head_rot;
mod c_hurt_animation; mod c_hurt_animation;
mod c_login; mod c_login;
mod c_open_screen; mod c_open_screen;
mod c_particle;
mod c_play_disconnect; mod c_play_disconnect;
mod c_player_abilities; mod c_player_abilities;
mod c_player_chat_message; mod c_player_chat_message;
@ -41,6 +42,7 @@ pub use c_head_rot::*;
pub use c_hurt_animation::*; pub use c_hurt_animation::*;
pub use c_login::*; pub use c_login::*;
pub use c_open_screen::*; pub use c_open_screen::*;
pub use c_particle::*;
pub use c_play_disconnect::*; pub use c_play_disconnect::*;
pub use c_player_abilities::*; pub use c_player_abilities::*;
pub use c_player_chat_message::*; pub use c_player_chat_message::*;

View File

@ -114,17 +114,8 @@ impl ChunkData {
}; };
let mask = (1 << block_size) - 1; let mask = (1 << block_size) - 1;
// println!("{block_size} {:#08b}", mask);
// println!(
// "{} {}",
// block_size,
// palette.iter().map(|v| v.to_string()).join(",")
// );
let mut blocks_left = 16 * 16 * 16; let mut blocks_left = 16 * 16 * 16;
'block_loop: for (j, block) in block_data.iter().enumerate() { 'block_loop: for (j, block) in block_data.iter().enumerate() {
// if at == (0,0) && block_size != 4 {
// println!("{} {:#066b}", 64 - (64 / block_size) * block_size, *block);
// }
for i in 0..64 / block_size { for i in 0..64 / block_size {
if blocks_left <= 0 { if blocks_left <= 0 {
break 'block_loop; break 'block_loop;
@ -138,24 +129,6 @@ impl ChunkData {
} }
} }
// std::fs::File::create_new("../mafaile.txt")
// .unwrap()
// .write_all(
// blocks
// .iter()
// .map(|v| v.to_string())
// .collect::<Vec<_>>()
// .join(",")
// .as_bytes(),
// );
// if at == (0, 0) {
// println!(
// "[{}]",
// &blocks[0..10000].iter().map(|v| v.to_string()).join(",")
// );
// }
// dbg!("{}", blocks.iter().filter(|v| **v == 2005).collect_vec().len());
Ok(ChunkData { Ok(ChunkData {
blocks, blocks,
position: at, position: at,

View File

@ -57,6 +57,18 @@ pub enum Compression {
LZ4, LZ4,
} }
impl Compression {
pub fn from_byte(byte: u8) -> Option<Self> {
match byte {
1 => Some(Self::Gzip),
2 => Some(Self::Zlib),
3 => Some(Self::None),
4 => Some(Self::LZ4),
_ => None,
}
}
}
impl Level { impl Level {
pub fn from_root_folder(root_folder: PathBuf) -> Self { pub fn from_root_folder(root_folder: PathBuf) -> Self {
// TODO: Check if exists // TODO: Check if exists
@ -177,13 +189,10 @@ impl Level {
// TODO: check checksum to make sure chunk is not corrupted // TODO: check checksum to make sure chunk is not corrupted
let header = file_buf.drain(0..5).collect_vec(); let header = file_buf.drain(0..5).collect_vec();
let compression = match header[4] { let compression = match Compression::from_byte(header[4]) {
1 => Compression::Gzip, Some(c) => c,
2 => Compression::Zlib, None => {
3 => Compression::None, let _ = channel.blocking_send((
4 => Compression::LZ4,
_ => {
let _ = channel.send((
(chunk.0, chunk.1), (chunk.0, chunk.1),
Err(WorldError::Compression( Err(WorldError::Compression(
CompressionError::UnknownCompression, CompressionError::UnknownCompression,
@ -193,20 +202,23 @@ impl Level {
} }
}; };
let size = u32::from_be_bytes(header[0..4].try_into().unwrap()); let size = u32::from_be_bytes(header[..4].try_into().unwrap());
// size includes the compression scheme byte, so we need to subtract 1 // size includes the compression scheme byte, so we need to subtract 1
let chunk_data = file_buf.drain(0..size as usize - 1).collect_vec(); let chunk_data = file_buf.drain(0..size as usize - 1).collect_vec();
let decompressed_chunk = match Self::decompress_data(compression, chunk_data) { let decompressed_chunk = match Self::decompress_data(compression, chunk_data) {
Ok(data) => data, Ok(data) => data,
Err(e) => { Err(e) => {
let _ = channel.send(((chunk.0, chunk.1), Err(WorldError::Compression(e)))); channel
.blocking_send(((chunk.0, chunk.1), Err(WorldError::Compression(e))))
.expect("Failed to send Compression error");
return; return;
} }
}; };
let _ = channel channel
.blocking_send((chunk, ChunkData::from_bytes(decompressed_chunk, chunk))); .blocking_send((chunk, ChunkData::from_bytes(decompressed_chunk, chunk)))
.expect("Error sending decompressed chunk");
}) })
.collect::<Vec<()>>(); .collect::<Vec<()>>();
} }

View File

@ -2,8 +2,8 @@ use num_traits::FromPrimitive;
use pumpkin_entity::EntityId; use pumpkin_entity::EntityId;
use pumpkin_protocol::{ use pumpkin_protocol::{
client::play::{ client::play::{
Animation, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation, CSystemChatMessge, Animation, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation,
CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot, CSystemChatMessge, CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot,
}, },
server::play::{ server::play::{
Action, SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract, Action, SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract,
@ -217,6 +217,7 @@ impl Client {
false, false,
), ),
); );
/* server.broadcast_packet( /* server.broadcast_packet(
self, self,
CPlayerChatMessage::new( CPlayerChatMessage::new(