Skip to content

Commit

Permalink
Sum ting wong
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas0008 committed Aug 17, 2024
1 parent 5f8cbdb commit 1c767da
Show file tree
Hide file tree
Showing 29 changed files with 533 additions and 452 deletions.
5 changes: 1 addition & 4 deletions pumpkin-protocol/src/bytebuf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,7 @@ impl ByteBuffer {
/// some, then it also calls the `write` closure.
pub fn put_option<T>(&mut self, val: &Option<T>, write: impl FnOnce(&mut Self, &T)) {
self.put_bool(val.is_some());
match val {
Some(v) => write(self, v),
None => {}
}
if let Some(v) = val { write(self, v) }
}

pub fn get_list<T>(&mut self, val: impl Fn(&mut Self) -> T) -> Vec<T> {
Expand Down
2 changes: 0 additions & 2 deletions pumpkin-protocol/src/client/config/c_plugin_message.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use pumpkin_macros::packet;
use serde::Serialize;

use crate::{bytebuf::ByteBuffer, ClientPacket};

#[derive(Serialize)]
#[packet(0x01)]
pub struct CPluginMessage<'a> {
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/login/c_login_success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<'a> CLoginSuccess<'a> {
impl<'a> ClientPacket for CLoginSuccess<'a> {
fn write(&self, bytebuf: &mut ByteBuffer) {
bytebuf.put_uuid(self.uuid);
bytebuf.put_string(&self.username);
bytebuf.put_string(self.username);
bytebuf.put_list::<Property>(self.properties, |p, v| {
p.put_string(&v.name);
p.put_string(&v.value);
Expand Down
6 changes: 3 additions & 3 deletions pumpkin-protocol/src/client/play/c_chunk_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<'a> ClientPacket for CChunkData<'a> {
data_buf.put_i16(block_count);
//// Block states

let palette = chunk.into_iter().dedup().collect_vec();
let palette = chunk.iter().dedup().collect_vec();
// TODO: make dynamic block_size work
// TODO: make direct block_size work
enum PaletteType {
Expand Down Expand Up @@ -63,7 +63,7 @@ impl<'a> ClientPacket for CChunkData<'a> {
palette.iter().enumerate().for_each(|(i, id)| {
palette_map.insert(*id, i);
// Palette
data_buf.put_var_int(&VarInt(**id as i32));
data_buf.put_var_int(&VarInt(**id));
});
for block_clump in chunk.chunks(64 / block_size as usize) {
let mut out_long: i64 = 0;
Expand Down Expand Up @@ -109,7 +109,7 @@ impl<'a> ClientPacket for CChunkData<'a> {
// Size
buf.put_var_int(&VarInt(data_buf.buf().len() as i32));
// Data
buf.put_slice(&data_buf.buf());
buf.put_slice(data_buf.buf());

// TODO: block entities
buf.put_var_int(&VarInt(0));
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/play/c_player_chat_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use pumpkin_macros::packet;
use pumpkin_text::TextComponent;
use serde::Serialize;

use crate::{uuid::UUID, BitSet, VarInt};
use crate::{uuid::UUID, VarInt};

#[derive(Serialize)]
#[packet(0x39)]
Expand Down
7 changes: 5 additions & 2 deletions pumpkin-protocol/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use bytebuf::{packet_id::Packet, ByteBuffer, DeserializerError};
use bytes::Buf;
use serde::{Deserialize, Serialize, Serializer};
use serde::{Deserialize, Serialize};
use std::io::{self, Write};
use thiserror::Error;

pub mod bytebuf;
pub mod client;
pub mod packet_decoder;
pub mod packet_encoder;
pub mod position;
pub mod server;
pub mod uuid;
pub mod position;

pub const CURRENT_MC_PROTOCOL: u32 = 767;

Expand Down Expand Up @@ -152,6 +152,8 @@ pub enum PacketError {
OutOfBounds,
#[error("malformed packet length VarInt")]
MailformedLength,
#[error("client disconnected")]
ClientDisconnected,
}

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -179,6 +181,7 @@ impl From<VarInt> for ConnectionState {
}
}

#[derive(Debug)]
pub struct RawPacket {
pub id: VarInt,
pub bytebuf: ByteBuffer,
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/packet_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
type Cipher = cfb8::Decryptor<aes::Aes128>;

// Decoder: Client -> Server
#[derive(Default)]
#[derive(Default, Debug)]
pub struct PacketDecoder {
buf: BytesMut,
decompress_buf: BytesMut,
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/packet_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{bytebuf::ByteBuffer, ClientPacket, PacketError, VarInt, MAX_PACKET_S
type Cipher = cfb8::Encryptor<aes::Aes128>;

// Encoder: Server -> Client
#[derive(Default)]
#[derive(Default, Debug)]
pub struct PacketEncoder {
buf: BytesMut,
compress_buf: Vec<u8>,
Expand Down
2 changes: 0 additions & 2 deletions pumpkin-protocol/src/server/play/c_interact.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use pumpkin_macros::packet;
use serde::Deserialize;

use crate::{ServerPacket, VarInt};

#[packet(0x16)]
Expand Down
1 change: 1 addition & 0 deletions pumpkin-protocol/src/server/play/s_player_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{position::WorldPosition, VarInt};

#[derive(serde::Deserialize)]
#[packet(0x24)]
#[allow(dead_code)] // TODO remove
pub struct SPlayerAction {
status: VarInt,
location: WorldPosition,
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/server/status/s_ping_request.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pumpkin_macros::packet;

#[derive(serde::Deserialize)]
#[derive(serde::Deserialize, Debug)]
#[packet(0x01)]
pub struct SPingRequest {
pub payload: i64,
Expand Down
4 changes: 2 additions & 2 deletions pumpkin-world/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ pub struct ChunkHeightmaps {
#[derive(serde::Deserialize, Debug)]
struct ChunkSection {
#[serde(rename = "Y")]
y: i32,
_y: i32,
block_states: Option<ChunkSectionBlockStates>,
}

#[derive(serde::Deserialize, Debug)]
struct ChunkNbt {
#[serde(rename = "DataVersion")]
data_version: usize,
_data_version: usize,
sections: Vec<ChunkSection>,
#[serde(rename = "Heightmaps")]
heightmaps: ChunkHeightmaps,
Expand Down
2 changes: 0 additions & 2 deletions pumpkin-world/src/radial_chunk_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::VecDeque;

pub struct RadialIterator {
radius: i32,
direction: usize,
Expand Down
17 changes: 7 additions & 10 deletions pumpkin-world/src/world.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
use std::{
io::{Read, Seek},
path::PathBuf,
sync::{atomic::AtomicUsize, Arc},
};

use flate2::bufread::ZlibDecoder;
use itertools::Itertools;
use rayon::prelude::*;
use thiserror::Error;
use tokio::{
fs::File,
io::{AsyncReadExt, AsyncSeekExt},
runtime::Handle,
sync::{mpsc, oneshot, Mutex},
task::spawn_blocking,
};
use tokio::sync::mpsc;

use crate::chunk::ChunkData;

Expand Down Expand Up @@ -89,7 +82,11 @@ impl Level {
region_file_path.push(format!("r.{}.{}.mca", region.0, region.1));

// return different error when file is not found (because that means that the chunks have just not been generated yet)
let mut region_file = match std::fs::File::options().read(true).write(false).open(&region_file_path) {
let mut region_file = match std::fs::File::options()
.read(true)
.write(false)
.open(&region_file_path)
{
Ok(f) => f,
Err(err) => match err.kind() {
std::io::ErrorKind::NotFound => {
Expand Down Expand Up @@ -173,7 +170,7 @@ impl Level {
4 => Compression::LZ4,
_ => {
let _ =
channel.send(((chunk.0, chunk.1), Err(WorldError::RegionIsInvalid)));
channel.blocking_send(((chunk.0, chunk.1), Err(WorldError::RegionIsInvalid)));
return;
}
};
Expand Down
Loading

0 comments on commit 1c767da

Please sign in to comment.