Skip to content

Commit

Permalink
Merge pull request #142 from Snowiiii/tokio
Browse files Browse the repository at this point in the history
Move to tokio
  • Loading branch information
Snowiiii authored Oct 19, 2024
2 parents 2945a65 + 59d75d9 commit 650c28f
Show file tree
Hide file tree
Showing 35 changed files with 1,000 additions and 987 deletions.
8 changes: 1 addition & 7 deletions docs/troubleshooting/common_issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@

**Cause:** The server is currently not calculating hit boxes for blocks, we're working on that.

3. ### The Server is unresponsive

**Issue:** You have to wait before reconnecting or can't do basic things while chunks are loading.

**Cause:** The server has currently blocking issues, we're working on that.

4. ### Failed to verify username
3. ### Failed to verify username

**Issue:** Some players reported having issues logging into the Server, including a "Failed to verify username" error.

Expand Down
7 changes: 7 additions & 0 deletions pumpkin-core/src/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ impl<'a> TextComponent<'a> {
}
}

pub fn text_string(text: String) -> Self {
Self {
content: TextContent::Text { text: text.into() },
style: Style::default(),
}
}

pub fn to_pretty_console(self) -> String {
let style = self.style;
let color = style.color;
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-inventory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ num-traits = "0.2"
num-derive = "0.4"
thiserror = "1.0.63"
itertools.workspace = true
parking_lot.workspace = true
crossbeam.workspace = true
tokio.workspace = true
18 changes: 9 additions & 9 deletions pumpkin-inventory/src/drag_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ use crate::container_click::MouseDragType;
use crate::{Container, InventoryError};
use itertools::Itertools;
use num_traits::Euclid;
use parking_lot::{Mutex, RwLock};
use pumpkin_world::item::ItemStack;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::{Mutex, RwLock};
#[derive(Debug, Default)]
pub struct DragHandler(RwLock<HashMap<u64, Arc<Mutex<Drag>>>>);

impl DragHandler {
pub fn new() -> Self {
Self(RwLock::new(HashMap::new()))
}
pub fn new_drag(
pub async fn new_drag(
&self,
container_id: u64,
player: i32,
Expand All @@ -24,21 +24,21 @@ impl DragHandler {
drag_type,
slots: vec![],
};
let mut drags = self.0.write();
let mut drags = self.0.write().await;
drags.insert(container_id, Arc::new(Mutex::new(drag)));
Ok(())
}

pub fn add_slot(
pub async fn add_slot(
&self,
container_id: u64,
player: i32,
slot: usize,
) -> Result<(), InventoryError> {
let drags = self.0.read();
let drags = self.0.read().await;
match drags.get(&container_id) {
Some(drag) => {
let mut drag = drag.lock();
let mut drag = drag.lock().await;
if drag.player != player {
Err(InventoryError::MultiplePlayersDragging)?
}
Expand All @@ -51,7 +51,7 @@ impl DragHandler {
Ok(())
}

pub fn apply_drag<T: Container>(
pub async fn apply_drag<T: Container>(
&self,
maybe_carried_item: &mut Option<ItemStack>,
container: &mut T,
Expand All @@ -63,11 +63,11 @@ impl DragHandler {
return Ok(());
}

let mut drags = self.0.write();
let mut drags = self.0.write().await;
let Some((_, drag)) = drags.remove_entry(container_id) else {
Err(InventoryError::OutOfOrderDragging)?
};
let drag = drag.lock();
let drag = drag.lock().await;

if player != drag.player {
Err(InventoryError::MultiplePlayersDragging)?
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-inventory/src/open_container.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{Container, WindowType};
use parking_lot::Mutex;
use pumpkin_world::item::ItemStack;
use std::sync::Arc;
use tokio::sync::Mutex;

pub struct OpenContainer {
players: Vec<i32>,
Expand Down
4 changes: 2 additions & 2 deletions pumpkin-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ pub enum PacketError {
FailedWrite(String),
#[error("failed to flush decoder")]
FailedFinish,
#[error("failed to write encoded packet to connection: {0}")]
ConnectionWrite(String),
#[error("failed to write encoded packet to connection")]
ConnectionWrite,
#[error("packet exceeds maximum length")]
TooLong,
#[error("packet length is out of bounds")]
Expand Down
38 changes: 18 additions & 20 deletions pumpkin-world/src/cylindrical_chunk_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Cylindrical {
old_cylindrical: Cylindrical,
new_cylindrical: Cylindrical,
mut newly_included: impl FnMut(Vector2<i32>),
just_removed: impl FnMut(Vector2<i32>),
mut just_removed: impl FnMut(Vector2<i32>),
ignore: bool,
) {
let min_x = old_cylindrical.left().min(new_cylindrical.left());
Expand All @@ -29,26 +29,24 @@ impl Cylindrical {

for x in min_x..=max_x {
for z in min_z..=max_z {
// TODO
// let old_is_within = if ignore {
// false
// } else {
// old_cylindrical.is_within_distance(x, z)
// };
// let new_is_within = if ignore {
// true
// } else {
// new_cylindrical.is_within_distance(x, z)
// };
let old_is_within = if ignore {
false
} else {
old_cylindrical.is_within_distance(x, z)
};
let new_is_within = if ignore {
true
} else {
new_cylindrical.is_within_distance(x, z)
};

// if old_is_within != new_is_within {
// if new_is_within {
newly_included(Vector2::new(x, z));
// } else {
// dbg!("aa");
// just_removed(Vector2::new(x, z));
// }
// }
if old_is_within != new_is_within {
if new_is_within {
newly_included(Vector2::new(x, z));
} else {
just_removed(Vector2::new(x, z));
}
}
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions pumpkin-world/src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use rayon::prelude::*;
use tokio::sync::mpsc;

use crate::{
chunk::{anvil::AnvilChunkReader, ChunkData, ChunkReader, ChunkReadingError},
chunk::{
anvil::AnvilChunkReader, ChunkData, ChunkParsingError, ChunkReader, ChunkReadingError,
},
world_gen::{get_world_gen, Seed, WorldGenerator},
};

Expand Down Expand Up @@ -96,7 +98,10 @@ impl Level {
let data = match &self.save_file {
Some(save_file) => {
match self.chunk_reader.read_chunk(save_file, at) {
Err(ChunkReadingError::ChunkNotExist) => {
Err(
ChunkReadingError::ParsingError(ChunkParsingError::ChunkNotGenerated)
| ChunkReadingError::ChunkNotExist,
) => {
// This chunk was not generated yet.
Ok(self.world_gen.generate_chunk(at))
}
Expand Down
4 changes: 0 additions & 4 deletions pumpkin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ png = "0.17.14"
simple_logger = { version = "5.0.0", features = ["threads"] }
log.workspace = true

# networking
mio = { version = "1.0.2", features = ["net", "os-poll"] }

parking_lot.workspace = true
crossbeam.workspace = true
uuid.workspace = true
tokio.workspace = true
Expand Down
Loading

0 comments on commit 650c28f

Please sign in to comment.