From a2828a8ac0574303b5204e5f719bbc56dba1576d Mon Sep 17 00:00:00 2001 From: Luk-ESC Date: Wed, 21 Aug 2024 12:29:59 +0200 Subject: [PATCH 01/10] add required feature to tokio --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 112838e17..55d43289e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,5 +12,5 @@ lto = true codegen-units = 1 [workspace.dependencies] -tokio = { version = "1.39.2", features = ["net", "macros", "rt-multi-thread", "fs", "io-util"] } +tokio = { version = "1.39.2", features = ["net", "macros", "rt-multi-thread", "fs", "io-util", "sync"] } rayon = "1.10.0" From 8263d886ce9acfd02f7c6a41c64bcca93eeb83f5 Mon Sep 17 00:00:00 2001 From: Luk-ESC Date: Wed, 21 Aug 2024 12:31:12 +0200 Subject: [PATCH 02/10] move uuid to workspace --- Cargo.toml | 1 + pumpkin-protocol/Cargo.toml | 2 +- pumpkin-text/Cargo.toml | 2 +- pumpkin/Cargo.toml | 3 +-- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 55d43289e..c6564f7a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ codegen-units = 1 [workspace.dependencies] tokio = { version = "1.39.2", features = ["net", "macros", "rt-multi-thread", "fs", "io-util", "sync"] } rayon = "1.10.0" +uuid = { version = "1.10.0", features = ["serde", "v3"] } diff --git a/pumpkin-protocol/Cargo.toml b/pumpkin-protocol/Cargo.toml index 27c0c6566..e9805fecb 100644 --- a/pumpkin-protocol/Cargo.toml +++ b/pumpkin-protocol/Cargo.toml @@ -10,7 +10,7 @@ pumpkin-text = { path = "../pumpkin-text" } bytes = "1.7" -uuid = "1.10" +uuid.workspace = true serde = { version = "1.0", features = ["derive"] } # to parse strings to json responses diff --git a/pumpkin-text/Cargo.toml b/pumpkin-text/Cargo.toml index d687a00b6..727d06ccd 100644 --- a/pumpkin-text/Cargo.toml +++ b/pumpkin-text/Cargo.toml @@ -6,4 +6,4 @@ edition.workspace = true [dependencies] serde = { version = "1.0", features = ["derive"] } fastnbt = { git = "https://github.com/owengage/fastnbt.git" } -uuid = "1.10" +uuid.workspace = true diff --git a/pumpkin/Cargo.toml b/pumpkin/Cargo.toml index 3085385ea..bbbced5c3 100644 --- a/pumpkin/Cargo.toml +++ b/pumpkin/Cargo.toml @@ -61,7 +61,6 @@ log = "0.4" mio = { version = "1.0.1", features = ["os-poll", "net"]} crossbeam-channel = "0.5.13" -uuid = { version = "1.10", features = ["serde", "v3"]} - +uuid.workspace = true tokio.workspace = true rayon.workspace = true From 3f0a24170cd8284d1ea1ce55f037b25339d88522 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev <71594357+Snowiiii@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:44:21 +0100 Subject: [PATCH 03/10] Remove minecraft source decompiler script There are many 3th-party software's out there which can easily decompile your the Minecraft source. You also often don't need the Source for most things. --- .devcontainer/devcontainer.json | 19 ++---------------- mc-source-code/decompile.sh | 35 --------------------------------- mc-source-code/pom.xml | 12 ----------- 3 files changed, 2 insertions(+), 64 deletions(-) delete mode 100755 mc-source-code/decompile.sh delete mode 100644 mc-source-code/pom.xml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 361cae3be..ada7e38b1 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,23 +2,9 @@ "name": "Pumpkin", "image": "mcr.microsoft.com/devcontainers/base:noble", "features": { - // rust is needed for compiling the server's code - "ghcr.io/devcontainers/features/rust:1": {}, - // java is needed for decompiling Mojang's server jar - "ghcr.io/devcontainers/features/java:1": { - "version": "21", - "jdkDistro": "oracle", - "installMaven": true, - "mavenVersion": "latest" - }, - // python is needed for decompiling Mojang's server jar - "ghcr.io/devcontainers/features/python:1": { - "installTools": true, - "version": "3.7" - } + "ghcr.io/devcontainers/features/rust:1": {} }, "mounts": [ - // mount SSH config & public keys from host to enable SSH-based Git remotes "source=${localEnv:HOME}${localEnv:USERPROFILE}/.ssh,target=/home/vscode/.ssh,readonly,type=bind" ], "forwardPorts": [ @@ -28,8 +14,7 @@ "vscode": { "extensions": [ "eamodio.gitlens", - "Swellaby.rust-pack", - "vscjava.vscode-java-pack" + "Swellaby.rust-pack" ] } } diff --git a/mc-source-code/decompile.sh b/mc-source-code/decompile.sh deleted file mode 100755 index a347f8d62..000000000 --- a/mc-source-code/decompile.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -# This script decompiles the official Minecraft server JAR file. -# Be careful, as releasing the decompiled source code is against Minecraft's EULA. - -# configure which version we want to decompile -MC_VERSION="1.21" - -# remove folders if they already exist -if [ -d "DecompilerMC" ]; then rm -r DecompilerMC; fi -if [ -d "src" ]; then rm -r src; fi -if [ -d "target" ]; then rm -r target; fi - -# clone DecompilerMC for automatic decompilation -# look here for more informations: -# - https://minecraft.fandom.com/wiki/Tutorials/See_Minecraft%27s_code -# - https://github.com/hube12/DecompilerMC -git clone https://github.com/hube12/DecompilerMC.git -echo "DecompilerMC cloned successfully." - -# decompile the server JAR file -echo "Decompilation might take a while, please be patient." -cd DecompilerMC -python3 main.py -mcv $MC_VERSION -s server -na -f -rmap -rjar -dm -dj -dd -dec -q -c - -# move it to the correct directory -mv src .. -cd .. - -# move the custom made pom.xml -cp pom.xml src/$MC_VERSION/server - -# install the dependencies -cd ../src/$MC_VERSION/server -# mvn clean install \ No newline at end of file diff --git a/mc-source-code/pom.xml b/mc-source-code/pom.xml deleted file mode 100644 index e051d6cc7..000000000 --- a/mc-source-code/pom.xml +++ /dev/null @@ -1,12 +0,0 @@ - - 4.0.0 - - com.mojang - minecraft-server - 1.21 - - - - \ No newline at end of file From 5d023e696c04c658ed4044354b5fd2f53f5c8689 Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Wed, 21 Aug 2024 15:53:28 +0200 Subject: [PATCH 04/10] Delete unused `pumpkin-command` --- pumpkin-command/src/lib.rs | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 pumpkin-command/src/lib.rs diff --git a/pumpkin-command/src/lib.rs b/pumpkin-command/src/lib.rs deleted file mode 100644 index 5ca92f1e0..000000000 --- a/pumpkin-command/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -pub trait Command<'a> { - const NAME: &'a str; - const ALIEASES: [&'a str]; - const DESCRIPTION: &'a str; - - fn on_execute(client: &mut Cli); -} \ No newline at end of file From 8eb894ef13f4fa38659ea2583ccf5e66d77bcb98 Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Wed, 21 Aug 2024 16:12:09 +0200 Subject: [PATCH 05/10] Create pumpkin-core, and move pumpkin-text --- Cargo.lock | 24 +++++++++---------- Cargo.toml | 2 +- {pumpkin-text => pumpkin-core}/Cargo.toml | 2 +- pumpkin-core/src/lib.rs | 1 + .../src/text/_README.md | 0 .../src => pumpkin-core/src/text}/click.rs | 0 .../src => pumpkin-core/src/text}/color.rs | 0 .../src => pumpkin-core/src/text}/hover.rs | 2 +- .../lib.rs => pumpkin-core/src/text/mod.rs | 0 .../src => pumpkin-core/src/text}/style.rs | 2 +- pumpkin-protocol/Cargo.toml | 2 +- .../src/client/config/c_add_resource_pack.rs | 2 +- .../src/client/play/c_actionbar.rs | 2 +- .../client/play/c_disguised_chat_message.rs | 2 +- .../src/client/play/c_open_screen.rs | 2 +- .../src/client/play/c_play_disconnect.rs | 2 +- .../src/client/play/c_player_chat_message.rs | 2 +- .../src/client/play/c_set_title.rs | 2 +- .../src/client/play/c_subtitle.rs | 2 +- .../src/client/play/c_system_chat_message.rs | 2 +- pumpkin-protocol/src/slot.rs | 9 +++---- pumpkin-registry/Cargo.toml | 2 +- pumpkin-registry/src/chat_type.rs | 2 +- pumpkin/Cargo.toml | 2 +- pumpkin/src/client/client_packet.rs | 2 +- pumpkin/src/client/mod.rs | 2 +- pumpkin/src/client/player_packet.rs | 2 +- pumpkin/src/commands/cmd_gamemode.rs | 2 +- pumpkin/src/commands/cmd_help.rs | 2 +- pumpkin/src/commands/cmd_pumpkin.rs | 2 +- pumpkin/src/commands/mod.rs | 4 ++-- 31 files changed, 43 insertions(+), 41 deletions(-) rename {pumpkin-text => pumpkin-core}/Cargo.toml (90%) create mode 100644 pumpkin-core/src/lib.rs rename pumpkin-text/README.md => pumpkin-core/src/text/_README.md (100%) rename {pumpkin-text/src => pumpkin-core/src/text}/click.rs (100%) rename {pumpkin-text/src => pumpkin-core/src/text}/color.rs (100%) rename {pumpkin-text/src => pumpkin-core/src/text}/hover.rs (98%) rename pumpkin-text/src/lib.rs => pumpkin-core/src/text/mod.rs (100%) rename {pumpkin-text/src => pumpkin-core/src/text}/style.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index ce1e60d14..28e90afa5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1203,11 +1203,11 @@ dependencies = [ "num-bigint", "num-derive", "num-traits", + "pumpkin-core", "pumpkin-entity", "pumpkin-inventory", "pumpkin-protocol", "pumpkin-registry", - "pumpkin-text", "pumpkin-world", "rand", "rayon", @@ -1225,6 +1225,15 @@ dependencies = [ "uuid", ] +[[package]] +name = "pumpkin-core" +version = "0.1.0" +dependencies = [ + "fastnbt", + "serde", + "uuid", +] + [[package]] name = "pumpkin-entity" version = "0.1.0" @@ -1264,8 +1273,8 @@ dependencies = [ "log", "num-derive", "num-traits", + "pumpkin-core", "pumpkin-macros", - "pumpkin-text", "pumpkin-world", "serde", "serde_json", @@ -1280,20 +1289,11 @@ version = "0.1.0" dependencies = [ "fastnbt", "fastsnbt", + "pumpkin-core", "pumpkin-protocol", - "pumpkin-text", "serde", ] -[[package]] -name = "pumpkin-text" -version = "0.1.0" -dependencies = [ - "fastnbt", - "serde", - "uuid", -] - [[package]] name = "pumpkin-world" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index c6564f7a0..26b8f75a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = [ "pumpkin-entity", "pumpkin-inventory", "pumpkin-macros/", "pumpkin-protocol/", "pumpkin-registry/", "pumpkin-world", "pumpkin/" ] +members = [ "pumpkin-core", "pumpkin-entity", "pumpkin-inventory", "pumpkin-macros/", "pumpkin-protocol/", "pumpkin-registry/", "pumpkin-world", "pumpkin/"] [workspace.package] version = "0.1.0" diff --git a/pumpkin-text/Cargo.toml b/pumpkin-core/Cargo.toml similarity index 90% rename from pumpkin-text/Cargo.toml rename to pumpkin-core/Cargo.toml index 727d06ccd..34ad5239d 100644 --- a/pumpkin-text/Cargo.toml +++ b/pumpkin-core/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pumpkin-text" +name = "pumpkin-core" version.workspace = true edition.workspace = true diff --git a/pumpkin-core/src/lib.rs b/pumpkin-core/src/lib.rs new file mode 100644 index 000000000..481c63acc --- /dev/null +++ b/pumpkin-core/src/lib.rs @@ -0,0 +1 @@ +pub mod text; diff --git a/pumpkin-text/README.md b/pumpkin-core/src/text/_README.md similarity index 100% rename from pumpkin-text/README.md rename to pumpkin-core/src/text/_README.md diff --git a/pumpkin-text/src/click.rs b/pumpkin-core/src/text/click.rs similarity index 100% rename from pumpkin-text/src/click.rs rename to pumpkin-core/src/text/click.rs diff --git a/pumpkin-text/src/color.rs b/pumpkin-core/src/text/color.rs similarity index 100% rename from pumpkin-text/src/color.rs rename to pumpkin-core/src/text/color.rs diff --git a/pumpkin-text/src/hover.rs b/pumpkin-core/src/text/hover.rs similarity index 98% rename from pumpkin-text/src/hover.rs rename to pumpkin-core/src/text/hover.rs index 73bafd178..f01d8f30b 100644 --- a/pumpkin-text/src/hover.rs +++ b/pumpkin-core/src/text/hover.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use serde::{Deserialize, Serialize}; -use crate::Text; +use super::Text; #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(tag = "action", content = "contents", rename_all = "snake_case")] diff --git a/pumpkin-text/src/lib.rs b/pumpkin-core/src/text/mod.rs similarity index 100% rename from pumpkin-text/src/lib.rs rename to pumpkin-core/src/text/mod.rs diff --git a/pumpkin-text/src/style.rs b/pumpkin-core/src/text/style.rs similarity index 99% rename from pumpkin-text/src/style.rs rename to pumpkin-core/src/text/style.rs index 41a251243..f24bc8bea 100644 --- a/pumpkin-text/src/style.rs +++ b/pumpkin-core/src/text/style.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::{ +use super::{ click::ClickEvent, color::{self, Color}, hover::HoverEvent, diff --git a/pumpkin-protocol/Cargo.toml b/pumpkin-protocol/Cargo.toml index e9805fecb..f35275d96 100644 --- a/pumpkin-protocol/Cargo.toml +++ b/pumpkin-protocol/Cargo.toml @@ -6,7 +6,7 @@ edition.workspace = true [dependencies] pumpkin-macros = { path = "../pumpkin-macros" } pumpkin-world = { path = "../pumpkin-world" } -pumpkin-text = { path = "../pumpkin-text" } +pumpkin-core = { path = "../pumpkin-core" } bytes = "1.7" diff --git a/pumpkin-protocol/src/client/config/c_add_resource_pack.rs b/pumpkin-protocol/src/client/config/c_add_resource_pack.rs index ae8212aba..50f349886 100644 --- a/pumpkin-protocol/src/client/config/c_add_resource_pack.rs +++ b/pumpkin-protocol/src/client/config/c_add_resource_pack.rs @@ -1,5 +1,5 @@ use pumpkin_macros::packet; -use pumpkin_text::TextComponent; +use pumpkin_core::text::TextComponent; use serde::Serialize; use crate::uuid::UUID; diff --git a/pumpkin-protocol/src/client/play/c_actionbar.rs b/pumpkin-protocol/src/client/play/c_actionbar.rs index fb8fe68ba..7c68ce805 100644 --- a/pumpkin-protocol/src/client/play/c_actionbar.rs +++ b/pumpkin-protocol/src/client/play/c_actionbar.rs @@ -1,5 +1,5 @@ +use pumpkin_core::text::TextComponent; use pumpkin_macros::packet; -use pumpkin_text::TextComponent; use serde::Serialize; #[derive(Serialize)] diff --git a/pumpkin-protocol/src/client/play/c_disguised_chat_message.rs b/pumpkin-protocol/src/client/play/c_disguised_chat_message.rs index 65b43b9b8..3647e2f64 100644 --- a/pumpkin-protocol/src/client/play/c_disguised_chat_message.rs +++ b/pumpkin-protocol/src/client/play/c_disguised_chat_message.rs @@ -1,5 +1,5 @@ use pumpkin_macros::packet; -use pumpkin_text::TextComponent; +use pumpkin_core::text::TextComponent; use serde::Serialize; use crate::VarInt; diff --git a/pumpkin-protocol/src/client/play/c_open_screen.rs b/pumpkin-protocol/src/client/play/c_open_screen.rs index 7c5b07a22..5081d0b52 100644 --- a/pumpkin-protocol/src/client/play/c_open_screen.rs +++ b/pumpkin-protocol/src/client/play/c_open_screen.rs @@ -1,5 +1,5 @@ use pumpkin_macros::packet; -use pumpkin_text::TextComponent; +use pumpkin_core::text::TextComponent; use serde::Serialize; use crate::VarInt; diff --git a/pumpkin-protocol/src/client/play/c_play_disconnect.rs b/pumpkin-protocol/src/client/play/c_play_disconnect.rs index dd861d732..7140e3f63 100644 --- a/pumpkin-protocol/src/client/play/c_play_disconnect.rs +++ b/pumpkin-protocol/src/client/play/c_play_disconnect.rs @@ -1,5 +1,5 @@ +use pumpkin_core::text::TextComponent; use pumpkin_macros::packet; -use pumpkin_text::TextComponent; use serde::Serialize; #[derive(Serialize)] diff --git a/pumpkin-protocol/src/client/play/c_player_chat_message.rs b/pumpkin-protocol/src/client/play/c_player_chat_message.rs index 03f2160b5..712538615 100644 --- a/pumpkin-protocol/src/client/play/c_player_chat_message.rs +++ b/pumpkin-protocol/src/client/play/c_player_chat_message.rs @@ -1,7 +1,7 @@ use num_derive::{FromPrimitive, ToPrimitive}; use num_traits::FromPrimitive; use pumpkin_macros::packet; -use pumpkin_text::TextComponent; +use pumpkin_core::text::TextComponent; use serde::Serialize; use crate::{bytebuf::ByteBuffer, uuid::UUID, BitSet, ClientPacket, VarInt}; diff --git a/pumpkin-protocol/src/client/play/c_set_title.rs b/pumpkin-protocol/src/client/play/c_set_title.rs index 4e043da0f..b18b46ded 100644 --- a/pumpkin-protocol/src/client/play/c_set_title.rs +++ b/pumpkin-protocol/src/client/play/c_set_title.rs @@ -1,5 +1,5 @@ use pumpkin_macros::packet; -use pumpkin_text::TextComponent; +use pumpkin_core::text::TextComponent; use serde::Serialize; #[derive(Serialize)] diff --git a/pumpkin-protocol/src/client/play/c_subtitle.rs b/pumpkin-protocol/src/client/play/c_subtitle.rs index 10f86d1ef..0d8fed039 100644 --- a/pumpkin-protocol/src/client/play/c_subtitle.rs +++ b/pumpkin-protocol/src/client/play/c_subtitle.rs @@ -1,5 +1,5 @@ use pumpkin_macros::packet; -use pumpkin_text::TextComponent; +use pumpkin_core::text::TextComponent; use serde::Serialize; #[derive(Serialize)] diff --git a/pumpkin-protocol/src/client/play/c_system_chat_message.rs b/pumpkin-protocol/src/client/play/c_system_chat_message.rs index fd88e622a..a0f2342d1 100644 --- a/pumpkin-protocol/src/client/play/c_system_chat_message.rs +++ b/pumpkin-protocol/src/client/play/c_system_chat_message.rs @@ -1,5 +1,5 @@ +use pumpkin_core::text::TextComponent; use pumpkin_macros::packet; -use pumpkin_text::TextComponent; use serde::Serialize; #[derive(Serialize)] diff --git a/pumpkin-protocol/src/slot.rs b/pumpkin-protocol/src/slot.rs index 22223f3b4..6685ec207 100644 --- a/pumpkin-protocol/src/slot.rs +++ b/pumpkin-protocol/src/slot.rs @@ -1,7 +1,7 @@ use crate::VarInt; use pumpkin_world::item::Item; use serde::{ - de::{self, SeqAccess, Visitor}, + de::{self, SeqAccess}, Deserialize, }; @@ -21,8 +21,8 @@ impl<'de> Deserialize<'de> for Slot { where D: de::Deserializer<'de>, { - struct VarIntVisitor; - impl<'de> Visitor<'de> for VarIntVisitor { + struct Visitor; + impl<'de> de::Visitor<'de> for Visitor { type Value = Slot; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { @@ -72,9 +72,10 @@ impl<'de> Deserialize<'de> for Slot { } } - deserializer.deserialize_seq(VarIntVisitor) + deserializer.deserialize_seq(Visitor) } } + impl Slot { pub fn to_item(self) -> Option { let item_id = self.item_id?.0.try_into().unwrap(); diff --git a/pumpkin-registry/Cargo.toml b/pumpkin-registry/Cargo.toml index 3087a0ec3..f1e53cba3 100644 --- a/pumpkin-registry/Cargo.toml +++ b/pumpkin-registry/Cargo.toml @@ -5,7 +5,7 @@ edition.workspace = true [dependencies] pumpkin-protocol = { path = "../pumpkin-protocol"} -pumpkin-text = { path = "../pumpkin-text"} +pumpkin-core = { path = "../pumpkin-core"} # nbt fastnbt = { git = "https://github.com/owengage/fastnbt.git" } diff --git a/pumpkin-registry/src/chat_type.rs b/pumpkin-registry/src/chat_type.rs index e5d533527..647c89dd1 100644 --- a/pumpkin-registry/src/chat_type.rs +++ b/pumpkin-registry/src/chat_type.rs @@ -1,4 +1,4 @@ -use pumpkin_text::style::Style; +use pumpkin_core::text::style::Style; use serde::Serialize; #[derive(Debug, Clone, Serialize)] diff --git a/pumpkin/Cargo.toml b/pumpkin/Cargo.toml index bbbced5c3..c6d12a44c 100644 --- a/pumpkin/Cargo.toml +++ b/pumpkin/Cargo.toml @@ -13,7 +13,7 @@ dhat-heap = ["dhat"] dhat = { version = "0.3.3", optional = true } # pumpkin -pumpkin-text = { path = "../pumpkin-text" } +pumpkin-core = { path = "../pumpkin-core"} pumpkin-inventory = { path = "../pumpkin-inventory"} pumpkin-world = { path = "../pumpkin-world"} pumpkin-entity = { path = "../pumpkin-entity"} diff --git a/pumpkin/src/client/client_packet.rs b/pumpkin/src/client/client_packet.rs index 7be9a4d1d..a9e4f4928 100644 --- a/pumpkin/src/client/client_packet.rs +++ b/pumpkin/src/client/client_packet.rs @@ -13,7 +13,7 @@ use pumpkin_protocol::{ }, ConnectionState, KnownPack, CURRENT_MC_PROTOCOL, }; -use pumpkin_text::TextComponent; +use pumpkin_core::text::TextComponent; use rsa::Pkcs1v15Encrypt; use sha1::{Digest, Sha1}; diff --git a/pumpkin/src/client/mod.rs b/pumpkin/src/client/mod.rs index 837976873..339ea3856 100644 --- a/pumpkin/src/client/mod.rs +++ b/pumpkin/src/client/mod.rs @@ -36,7 +36,7 @@ use pumpkin_protocol::{ }, ClientPacket, ConnectionState, PacketError, RawPacket, ServerPacket, }; -use pumpkin_text::TextComponent; +use pumpkin_core::text::TextComponent; use std::io::Read; use thiserror::Error; diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index bd040469d..d5d29539f 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -22,7 +22,7 @@ use pumpkin_protocol::{ SUseItemOn, Status, }, }; -use pumpkin_text::TextComponent; +use pumpkin_core::text::TextComponent; use pumpkin_world::block::BlockFace; use pumpkin_world::global_registry; diff --git a/pumpkin/src/commands/cmd_gamemode.rs b/pumpkin/src/commands/cmd_gamemode.rs index b054fdc24..526ac9e56 100644 --- a/pumpkin/src/commands/cmd_gamemode.rs +++ b/pumpkin/src/commands/cmd_gamemode.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use num_traits::FromPrimitive; -use pumpkin_text::TextComponent; +use pumpkin_core::text::TextComponent; use crate::commands::arg_player::{consume_arg_player, parse_arg_player}; diff --git a/pumpkin/src/commands/cmd_help.rs b/pumpkin/src/commands/cmd_help.rs index 7ffa733c1..893f19568 100644 --- a/pumpkin/src/commands/cmd_help.rs +++ b/pumpkin/src/commands/cmd_help.rs @@ -3,7 +3,7 @@ use crate::commands::dispatcher::{CommandDispatcher, InvalidTreeError}; use crate::commands::tree::{CommandTree, ConsumedArgs, RawArgs}; use crate::commands::tree_builder::argument; use crate::commands::{dispatcher_init, CommandSender, DISPATCHER}; -use pumpkin_text::TextComponent; +use pumpkin_core::text::TextComponent; pub(crate) const NAME: &str = "help"; pub(crate) const ALIAS: &str = "?"; diff --git a/pumpkin/src/commands/cmd_pumpkin.rs b/pumpkin/src/commands/cmd_pumpkin.rs index cbbac0680..25d515791 100644 --- a/pumpkin/src/commands/cmd_pumpkin.rs +++ b/pumpkin/src/commands/cmd_pumpkin.rs @@ -1,6 +1,6 @@ use crate::server::CURRENT_MC_VERSION; +use pumpkin_core::text::{color::NamedColor, TextComponent}; use pumpkin_protocol::CURRENT_MC_PROTOCOL; -use pumpkin_text::{color::NamedColor, TextComponent}; use crate::commands::tree::CommandTree; diff --git a/pumpkin/src/commands/mod.rs b/pumpkin/src/commands/mod.rs index c622691d6..0dfa5483f 100644 --- a/pumpkin/src/commands/mod.rs +++ b/pumpkin/src/commands/mod.rs @@ -1,4 +1,4 @@ -use pumpkin_text::TextComponent; +use pumpkin_core::text::TextComponent; use std::collections::HashMap; use std::sync::OnceLock; @@ -86,7 +86,7 @@ pub fn handle_command(sender: &mut CommandSender, cmd: &str) { if let Err(err) = dispatcher.dispatch(sender, cmd) { sender.send_message( - TextComponent::text(&err).color_named(pumpkin_text::color::NamedColor::Red), + TextComponent::text(&err).color_named(pumpkin_core::text::color::NamedColor::Red), ) } } From e6f0e126cabf32a5bc0671813af0f5644e6b19c1 Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Wed, 21 Aug 2024 16:16:37 +0200 Subject: [PATCH 06/10] Cargo fmt --- pumpkin-protocol/src/client/config/c_add_resource_pack.rs | 2 +- pumpkin-protocol/src/client/play/c_disguised_chat_message.rs | 2 +- pumpkin-protocol/src/client/play/c_open_screen.rs | 2 +- pumpkin-protocol/src/client/play/c_player_chat_message.rs | 2 +- pumpkin-protocol/src/client/play/c_set_title.rs | 2 +- pumpkin-protocol/src/client/play/c_subtitle.rs | 2 +- pumpkin/src/client/client_packet.rs | 2 +- pumpkin/src/client/mod.rs | 2 +- pumpkin/src/client/player_packet.rs | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pumpkin-protocol/src/client/config/c_add_resource_pack.rs b/pumpkin-protocol/src/client/config/c_add_resource_pack.rs index 50f349886..824141e25 100644 --- a/pumpkin-protocol/src/client/config/c_add_resource_pack.rs +++ b/pumpkin-protocol/src/client/config/c_add_resource_pack.rs @@ -1,5 +1,5 @@ -use pumpkin_macros::packet; use pumpkin_core::text::TextComponent; +use pumpkin_macros::packet; use serde::Serialize; use crate::uuid::UUID; diff --git a/pumpkin-protocol/src/client/play/c_disguised_chat_message.rs b/pumpkin-protocol/src/client/play/c_disguised_chat_message.rs index 3647e2f64..9408768ec 100644 --- a/pumpkin-protocol/src/client/play/c_disguised_chat_message.rs +++ b/pumpkin-protocol/src/client/play/c_disguised_chat_message.rs @@ -1,5 +1,5 @@ -use pumpkin_macros::packet; use pumpkin_core::text::TextComponent; +use pumpkin_macros::packet; use serde::Serialize; use crate::VarInt; diff --git a/pumpkin-protocol/src/client/play/c_open_screen.rs b/pumpkin-protocol/src/client/play/c_open_screen.rs index 5081d0b52..214623cd3 100644 --- a/pumpkin-protocol/src/client/play/c_open_screen.rs +++ b/pumpkin-protocol/src/client/play/c_open_screen.rs @@ -1,5 +1,5 @@ -use pumpkin_macros::packet; use pumpkin_core::text::TextComponent; +use pumpkin_macros::packet; use serde::Serialize; use crate::VarInt; diff --git a/pumpkin-protocol/src/client/play/c_player_chat_message.rs b/pumpkin-protocol/src/client/play/c_player_chat_message.rs index 712538615..e47e9d225 100644 --- a/pumpkin-protocol/src/client/play/c_player_chat_message.rs +++ b/pumpkin-protocol/src/client/play/c_player_chat_message.rs @@ -1,7 +1,7 @@ use num_derive::{FromPrimitive, ToPrimitive}; use num_traits::FromPrimitive; -use pumpkin_macros::packet; use pumpkin_core::text::TextComponent; +use pumpkin_macros::packet; use serde::Serialize; use crate::{bytebuf::ByteBuffer, uuid::UUID, BitSet, ClientPacket, VarInt}; diff --git a/pumpkin-protocol/src/client/play/c_set_title.rs b/pumpkin-protocol/src/client/play/c_set_title.rs index b18b46ded..4618b0d6e 100644 --- a/pumpkin-protocol/src/client/play/c_set_title.rs +++ b/pumpkin-protocol/src/client/play/c_set_title.rs @@ -1,5 +1,5 @@ -use pumpkin_macros::packet; use pumpkin_core::text::TextComponent; +use pumpkin_macros::packet; use serde::Serialize; #[derive(Serialize)] diff --git a/pumpkin-protocol/src/client/play/c_subtitle.rs b/pumpkin-protocol/src/client/play/c_subtitle.rs index 0d8fed039..ddca5c52c 100644 --- a/pumpkin-protocol/src/client/play/c_subtitle.rs +++ b/pumpkin-protocol/src/client/play/c_subtitle.rs @@ -1,5 +1,5 @@ -use pumpkin_macros::packet; use pumpkin_core::text::TextComponent; +use pumpkin_macros::packet; use serde::Serialize; #[derive(Serialize)] diff --git a/pumpkin/src/client/client_packet.rs b/pumpkin/src/client/client_packet.rs index a9e4f4928..065cf2c4e 100644 --- a/pumpkin/src/client/client_packet.rs +++ b/pumpkin/src/client/client_packet.rs @@ -1,4 +1,5 @@ use num_traits::FromPrimitive; +use pumpkin_core::text::TextComponent; use pumpkin_protocol::{ client::{ config::{CConfigAddResourcePack, CFinishConfig, CKnownPacks, CRegistryData}, @@ -13,7 +14,6 @@ use pumpkin_protocol::{ }, ConnectionState, KnownPack, CURRENT_MC_PROTOCOL, }; -use pumpkin_core::text::TextComponent; use rsa::Pkcs1v15Encrypt; use sha1::{Digest, Sha1}; diff --git a/pumpkin/src/client/mod.rs b/pumpkin/src/client/mod.rs index 339ea3856..30121afdc 100644 --- a/pumpkin/src/client/mod.rs +++ b/pumpkin/src/client/mod.rs @@ -13,6 +13,7 @@ use crate::{ use authentication::GameProfile; use mio::{event::Event, net::TcpStream, Token}; use num_traits::ToPrimitive; +use pumpkin_core::text::TextComponent; use pumpkin_protocol::{ bytebuf::packet_id::Packet, client::{ @@ -36,7 +37,6 @@ use pumpkin_protocol::{ }, ClientPacket, ConnectionState, PacketError, RawPacket, ServerPacket, }; -use pumpkin_core::text::TextComponent; use std::io::Read; use thiserror::Error; diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index d5d29539f..820d3564d 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -7,6 +7,7 @@ use crate::{ util::math::wrap_degrees, }; use num_traits::FromPrimitive; +use pumpkin_core::text::TextComponent; use pumpkin_entity::EntityId; use pumpkin_protocol::{ client::play::{ @@ -22,7 +23,6 @@ use pumpkin_protocol::{ SUseItemOn, Status, }, }; -use pumpkin_core::text::TextComponent; use pumpkin_world::block::BlockFace; use pumpkin_world::global_registry; From e23587b698b10f73065818ad385bb4683b4fd23b Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Wed, 21 Aug 2024 16:30:38 +0200 Subject: [PATCH 07/10] Create a basic structure guide --- CONTRIBUTING.md | 4 ++++ STRUCTURE.md | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 STRUCTURE.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 357ab14dd..9ad4b7ab9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,6 +25,10 @@ There are several ways you can contribute to Pumpkin: Ensure your code adheres to the project's coding style guidelines (if any). Write clear and concise commit messages that describe your changes. +### Project Structure + +Before contributing, it would be helpful to get to know the project structure, for further information, visit [STRUCTURE.md](STRUCTURE.md) + ### Additional Information We encourage you to comment on existing issues and pull requests to share your thoughts and provide feedback. diff --git a/STRUCTURE.md b/STRUCTURE.md new file mode 100644 index 000000000..52f2208f5 --- /dev/null +++ b/STRUCTURE.md @@ -0,0 +1,17 @@ +# Project Structure + +## Overview + +Pumpkin is split into multiple crates, thus having a set project structure between contributors is essential. + +## Pumpkin-Core + +The core crate has some special rules that only apply to it: + +- It may not depend on any other pumpkin crate +- There may not be any files directly under src/, except for the mod.rs file (this is to help with organisation) + +## Other crate rules + +- [`pumpkin-protocol`](/pumpkin-protocol/) - contains definitions for packet types **and** their serialization (be it through serde, or manually implementing `ClientPacket`/`ServerPacket`), only the `pumpkin` crate may depend on this +- `pumpkin-macros` - similarly to `pumpkin-core`, it may not depend on any other pumpkin crate From b37039126ac1e5a4c1c0e104f78923e3b3c5f4f9 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev <71594357+Snowiiii@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:49:28 +0100 Subject: [PATCH 08/10] Make Icon Optional --- pumpkin-protocol/src/lib.rs | 4 ++-- pumpkin/src/client/player_packet.rs | 2 +- pumpkin/src/server.rs | 10 ++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pumpkin-protocol/src/lib.rs b/pumpkin-protocol/src/lib.rs index 96abdc31f..3f7a4b607 100644 --- a/pumpkin-protocol/src/lib.rs +++ b/pumpkin-protocol/src/lib.rs @@ -188,8 +188,8 @@ pub struct StatusResponse { pub version: Version, pub players: Players, pub description: String, - pub favicon: String, // data:image/png;base64, - // Players, favicon ... + pub favicon: Option, // data:image/png;base64, + // Players, favicon ... } #[derive(Serialize)] pub struct Version { diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index 820d3564d..b8a7853d7 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -302,7 +302,7 @@ impl Client { if config.hurt_animation { // TODO // thats how we prevent borrow errors :c - let packet = &CHurtAnimation::new(&entity_id, 10.0); + let packet = &CHurtAnimation::new(&entity_id, attacker_player.entity.yaw); self.send_packet(packet); client.send_packet(packet); server.broadcast_packet_expect( diff --git a/pumpkin/src/server.rs b/pumpkin/src/server.rs index db1e45022..38133844b 100644 --- a/pumpkin/src/server.rs +++ b/pumpkin/src/server.rs @@ -2,6 +2,7 @@ use std::{ cell::{RefCell, RefMut}, collections::HashMap, io::Cursor, + path::Path, rc::Rc, sync::{ atomic::{AtomicI32, Ordering}, @@ -408,7 +409,12 @@ impl Server { } pub fn build_response(config: &BasicConfiguration) -> StatusResponse { - let path = concat!(env!("CARGO_MANIFEST_DIR"), "/icon.png"); + let icon_path = concat!(env!("CARGO_MANIFEST_DIR"), "/icon.png"); + let icon = if Path::new(icon_path).exists() { + Some(Self::load_icon(icon_path)) + } else { + None + }; StatusResponse { version: Version { @@ -424,7 +430,7 @@ impl Server { }], }, description: config.motd.clone(), - favicon: Self::load_icon(path), + favicon: icon, } } From 0d05e5ef3640d96e1c1c08093541032551fda894 Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Wed, 21 Aug 2024 17:31:43 +0200 Subject: [PATCH 09/10] Add .set_block on ChunkData --- pumpkin-protocol/src/bytebuf/mod.rs | 5 +---- pumpkin-world/src/chunk.rs | 19 ++++++++++++++++++- pumpkin-world/src/level.rs | 2 ++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/pumpkin-protocol/src/bytebuf/mod.rs b/pumpkin-protocol/src/bytebuf/mod.rs index 34f8980a1..fa275bb15 100644 --- a/pumpkin-protocol/src/bytebuf/mod.rs +++ b/pumpkin-protocol/src/bytebuf/mod.rs @@ -168,10 +168,7 @@ impl ByteBuffer { /// some, then it also calls the `write` closure. pub fn put_option(&mut self, val: &Option, 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(&mut self, val: impl Fn(&mut Self) -> T) -> Vec { diff --git a/pumpkin-world/src/chunk.rs b/pumpkin-world/src/chunk.rs index 70869857e..c3fe94ff7 100644 --- a/pumpkin-world/src/chunk.rs +++ b/pumpkin-world/src/chunk.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use fastnbt::LongArray; -use crate::{level::WorldError, WORLD_HEIGHT}; +use crate::{level::WorldError, vector3::Vector3, WORLD_HEIGHT, WORLD_Y_START_AT}; pub struct ChunkData { pub blocks: Box<[i32; 16 * 16 * WORLD_HEIGHT]>, @@ -110,4 +110,21 @@ impl ChunkData { heightmaps: chunk_data.heightmaps, }) } + /// Sets the given block in the chunk, returning the old block + pub fn set_block(&mut self, at: Vector3, block_id: i32) -> Result { + let x = at.x - self.position.0 * 16; + let z = at.z - self.position.1 * 16; + let y = at.y - WORLD_Y_START_AT; + if !(0..16).contains(&x) + || !(0..16).contains(&z) + || !(0..(WORLD_HEIGHT as i32)).contains(&y) + { + return Err(WorldError::BlockOutsideChunk); + } + + Ok(std::mem::replace( + &mut self.blocks[(y * 16 * 16 + z * 16 + x) as usize], + block_id, + )) + } } diff --git a/pumpkin-world/src/level.rs b/pumpkin-world/src/level.rs index 96dbfb5ad..3ccff077d 100644 --- a/pumpkin-world/src/level.rs +++ b/pumpkin-world/src/level.rs @@ -36,6 +36,8 @@ pub enum WorldError { ErrorDeserializingChunk(String), #[error("The requested block state id does not exist")] BlockStateIdNotFound, + #[error("The block is not inside of the chunk")] + BlockOutsideChunk, } #[derive(Error, Debug)] From c02200c7fd8533be658bcc0ca09f5211eabaad44 Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Wed, 21 Aug 2024 18:06:57 +0200 Subject: [PATCH 10/10] Cargo fmt + added *.local.nbt to .gitignore --- .gitignore | 5 ++++- pumpkin-protocol/src/bytebuf/mod.rs | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9d1ee4bda..a8bc3a134 100644 --- a/.gitignore +++ b/.gitignore @@ -85,4 +85,7 @@ world/ # project's binary configurations configuration.toml -features.toml \ No newline at end of file +features.toml + + +*.local.nbt \ No newline at end of file diff --git a/pumpkin-protocol/src/bytebuf/mod.rs b/pumpkin-protocol/src/bytebuf/mod.rs index fa275bb15..11d304223 100644 --- a/pumpkin-protocol/src/bytebuf/mod.rs +++ b/pumpkin-protocol/src/bytebuf/mod.rs @@ -168,7 +168,9 @@ impl ByteBuffer { /// some, then it also calls the `write` closure. pub fn put_option(&mut self, val: &Option, write: impl FnOnce(&mut Self, &T)) { self.put_bool(val.is_some()); - if let Some(v) = val { write(self, v) } + if let Some(v) = val { + write(self, v) + } } pub fn get_list(&mut self, val: impl Fn(&mut Self) -> T) -> Vec {