Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryntet authored Aug 20, 2024
2 parents e86889f + 3b55bc4 commit 006eacf
Show file tree
Hide file tree
Showing 24 changed files with 79 additions and 68 deletions.
3 changes: 2 additions & 1 deletion pumpkin-inventory/src/player.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use pumpkin_world::item::Item;

#[allow(dead_code)]
pub struct PlayerInventory {
// Main Inventory + Hotbar
crafting: [Option<Item>; 4],
Expand Down Expand Up @@ -41,7 +42,7 @@ impl PlayerInventory {
selected: 0,
}
}

/// Set the contents of an item in a slot
///
/// ## Slot
Expand Down
1 change: 0 additions & 1 deletion pumpkin-protocol/src/client/config/c_plugin_message.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use pumpkin_macros::packet;
use serde::Serialize;


#[derive(Serialize)]
#[packet(0x01)]
pub struct CPluginMessage<'a> {
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
1 change: 1 addition & 0 deletions pumpkin-protocol/src/client/play/c_particle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct CParticle<'a> {
}

impl<'a> CParticle<'a> {
#[allow(clippy::too_many_arguments)]
pub fn new(
long_distance: bool,
x: f64,
Expand Down
3 changes: 1 addition & 2 deletions pumpkin-protocol/src/server/play/s_interact.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use pumpkin_macros::packet;
Expand All @@ -21,7 +20,7 @@ impl ServerPacket for SInteract {
) -> Result<Self, crate::bytebuf::DeserializerError> {
let entity_id = bytebuf.get_var_int();
let typ = bytebuf.get_var_int();
let action = ActionType::from_i32(typ.0 as i32).unwrap();
let action = ActionType::from_i32(typ.0).unwrap();
let target_position: Option<(f32, f32, f32)> = match action {
ActionType::Interact => None,
ActionType::Attack => None,
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 @@ -3,6 +3,7 @@ use pumpkin_macros::packet;
use crate::{position::WorldPosition, VarInt};

#[derive(serde::Deserialize)]
#[allow(dead_code)]
#[packet(0x24)]
pub struct SPlayerAction {
status: VarInt,
Expand Down
1 change: 0 additions & 1 deletion pumpkin-protocol/src/server/play/s_player_command.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use pumpkin_macros::packet;

use crate::{bytebuf::DeserializerError, ServerPacket, VarInt};
Expand Down
1 change: 1 addition & 0 deletions pumpkin-protocol/src/server/play/s_set_creative_slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use pumpkin_macros::packet;
use crate::slot::Slot;

#[derive(serde::Deserialize, Debug)]
#[allow(dead_code)]
#[packet(0x32)]
pub struct SSetCreativeSlot {
pub slot: i16,
Expand Down
1 change: 1 addition & 0 deletions pumpkin-protocol/src/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use pumpkin_world::item::Item;
use crate::VarInt;

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct Slot {
item_count: VarInt,
item_id: Option<VarInt>,
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-text/src/click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[serde(tag = "action", content = "value", rename_all = "snake_case")]
pub enum ClickEvent<'a> {
/// Opens a URL
OpenUrl(Cow<'a, str>),
OpenUrl(Cow<'a, str>),
/// Works in signs, but only on the root text component
RunCommand(Cow<'a, str>),
/// Replaces the contents of the chat box with the text, not necessarily a
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-world/src/block/block_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use lazy_static::lazy_static;

use crate::world::WorldError;
use crate::level::WorldError;

const BLOCKS_JSON: &str = include_str!("../../assets/blocks.json");

Expand Down
31 changes: 3 additions & 28 deletions pumpkin-world/src/chunk.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
// use fastnbt::nbt;

// pub const BLOCKS_AND_BIOMES: [u8; 2000] = [0x80; 2000];
// pub const SKY_LIGHT_ARRAYS: [FixedArray<u8, 2048>; 26] = [FixedArray([0xff; 2048]); 26];

// #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
// #[repr(transparent)]
// pub struct FixedArray<T, const N: usize>(pub [T; N]);

// pub struct TestChunk {
// pub heightmap: Vec<u8>,
// }

// impl Default for TestChunk {
// fn default() -> Self {
// Self::new()
// }
// }

// impl TestChunk {
// pub fn new() -> Self {
// let bytes = fastnbt::to_bytes(&nbt!({"MOTION_BLOCKING": [L; 123, 256]})).unwrap();

// Self { heightmap: bytes }
// }
// }

use std::collections::HashMap;

use fastnbt::LongArray;

use crate::{world::WorldError, WORLD_HEIGHT};
use crate::{level::WorldError, WORLD_HEIGHT};

pub struct ChunkData {
pub blocks: Box<[i32; 16 * 16 * WORLD_HEIGHT]>,
Expand Down Expand Up @@ -58,13 +31,15 @@ pub struct ChunkHeightmaps {
}

#[derive(serde::Deserialize, Debug)]
#[allow(dead_code)]
struct ChunkSection {
#[serde(rename = "Y")]
y: i32,
block_states: Option<ChunkSectionBlockStates>,
}

#[derive(serde::Deserialize, Debug)]
#[allow(dead_code)]
struct ChunkNbt {
#[serde(rename = "DataVersion")]
data_version: usize,
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-world/src/dimension.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::PathBuf;

use crate::world::Level;
use crate::level::Level;

#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub enum Dimension {
Expand Down
1 change: 1 addition & 0 deletions pumpkin-world/src/global_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn get_protocol_id(category: &str, entry: &str) -> u32 {
.expect("No Entry found")
}

#[allow(dead_code)]
pub fn get_default<'a>(category: &str) -> Option<&'a str> {
REGISTRY
.get(category)
Expand Down
2 changes: 2 additions & 0 deletions pumpkin-world/src/item/item_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ lazy_static! {
serde_json::from_str(ITEMS_JSON).expect("Could not parse items.json registry.");
}

#[allow(dead_code)]
pub fn get_item_element(item_id: &str) -> &ItemComponents {
&ITEMS.get(item_id).expect("Item not found").components
}

#[allow(dead_code)]
pub fn get_item_protocol_id(item_id: &str) -> u32 {
global_registry::get_protocol_id(ITEM_REGISTRY, item_id)
}
14 changes: 9 additions & 5 deletions pumpkin-world/src/world.rs → pumpkin-world/src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ use flate2::{bufread::ZlibDecoder, read::GzDecoder};
use itertools::Itertools;
use rayon::prelude::*;
use thiserror::Error;
use tokio::{
io::{AsyncReadExt, AsyncSeekExt},
sync::mpsc,
};
use tokio::sync::mpsc;

use crate::chunk::ChunkData;

#[allow(dead_code)]
/// The Level represents a
pub struct Level {
root_folder: PathBuf,
region_folder: PathBuf,
Expand Down Expand Up @@ -71,8 +70,13 @@ impl Compression {

impl Level {
pub fn from_root_folder(root_folder: PathBuf) -> Self {
// TODO: Check if exists
assert!(root_folder.exists(), "World root folder does not exist!");
let region_folder = root_folder.join("region");
assert!(
region_folder.exists(),
"World region folder does not exist!"
);

Level {
root_folder,
region_folder,
Expand Down
15 changes: 14 additions & 1 deletion pumpkin-world/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use level::Level;

pub mod chunk;
pub mod dimension;
pub const WORLD_HEIGHT: usize = 384;
Expand All @@ -6,6 +8,17 @@ pub const DIRECT_PALETTE_BITS: u32 = 15;
pub mod block;
pub mod global_registry;
pub mod item;
mod level;
pub mod radial_chunk_iterator;
pub mod vector3;
mod world;

pub struct World {
pub level: Level,
// entities, players...
}

impl World {
pub fn load(level: Level) -> Self {
Self { level }
}
}
14 changes: 9 additions & 5 deletions pumpkin/src/client/client_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ impl Client {
self.protocol_version = handshake.protocol_version.0;
self.connection_state = handshake.next_state;
if self.connection_state == ConnectionState::Login {
if self.protocol_version < CURRENT_MC_PROTOCOL as i32 {
let protocol = self.protocol_version;
self.kick(&format!("Client outdated ({protocol}), Server uses Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL}"));
} else if self.protocol_version > CURRENT_MC_PROTOCOL as i32 {
self.kick(&format!("Server outdated, Server uses Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL}"));
let protocol = self.protocol_version;
match protocol.cmp(&(CURRENT_MC_PROTOCOL as i32)) {
std::cmp::Ordering::Less => {
self.kick(&format!("Client outdated ({protocol}), Server uses Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL}"));
}
std::cmp::Ordering::Equal => {}
std::cmp::Ordering::Greater => {
self.kick(&format!("Server outdated, Server uses Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL}"));
}
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions pumpkin/src/client/player_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use pumpkin_entity::EntityId;
use pumpkin_protocol::{
client::play::{
Animation, CBlockUpdate, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation,
CPlayerChatMessage, CUpdateEntityPos, CUpdateEntityPosRot,
CUpdateEntityRot, FilterType,
CPlayerChatMessage, CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot, FilterType,
},
position::WorldPosition,
server::play::{
Expand Down Expand Up @@ -316,7 +315,7 @@ impl Client {
}
}
}
pub fn handle_player_action(&mut self, _server: &mut Server, player_action: SPlayerAction) {}
pub fn handle_player_action(&mut self, _server: &mut Server, _player_action: SPlayerAction) {}

pub fn handle_use_item_on(&mut self, server: &mut Server, use_item_on: SUseItemOn) {
let location = use_item_on.location;
Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/commands/stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ impl<'a> Command<'a> for StopCommand {
const NAME: &'static str = "stop";
const DESCRIPTION: &'static str = "Stops the server";

fn on_execute(sender: &mut super::CommandSender<'a>, command: String) {
fn on_execute(_sender: &mut super::CommandSender<'a>, _command: String) {
std::process::exit(0);
}
fn player_required() -> bool {
Expand Down
1 change: 0 additions & 1 deletion pumpkin/src/entity/player.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::str::FromStr;

use num_derive::{FromPrimitive, ToPrimitive};
use num_traits::Float;
use pumpkin_entity::{entity_type::EntityType, Entity, EntityId};
use pumpkin_inventory::player::PlayerInventory;
use pumpkin_protocol::VarInt;
Expand Down
2 changes: 2 additions & 0 deletions pumpkin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::await_holding_refcell_ref)]

use mio::net::TcpListener;
use mio::{Events, Interest, Poll, Token};
use std::io::{self};
Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/rcon/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Packet {
buf.put_slice(bytes);
buf.put_u8(0);
buf.put_u8(0);
connection.write(&buf).unwrap();
let _ = connection.write(&buf).unwrap();
Ok(())
}

Expand Down
Loading

0 comments on commit 006eacf

Please sign in to comment.