Skip to content

Commit

Permalink
Merge branch 'Snowiiii:master' into docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Erb3 authored Aug 21, 2024
2 parents ab5342c + 0d05e5e commit fe5836a
Show file tree
Hide file tree
Showing 43 changed files with 156 additions and 130 deletions.
19 changes: 2 additions & 17 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -28,8 +14,7 @@
"vscode": {
"extensions": [
"eamodio.gitlens",
"Swellaby.rust-pack",
"vscjava.vscode-java-pack"
"Swellaby.rust-pack"
]
}
}
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -12,5 +12,6 @@ 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"
uuid = { version = "1.10.0", features = ["serde", "v3"] }
17 changes: 17 additions & 0 deletions STRUCTURE.md
Original file line number Diff line number Diff line change
@@ -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
35 changes: 0 additions & 35 deletions mc-source-code/decompile.sh

This file was deleted.

12 changes: 0 additions & 12 deletions mc-source-code/pom.xml

This file was deleted.

7 changes: 0 additions & 7 deletions pumpkin-command/src/lib.rs

This file was deleted.

4 changes: 2 additions & 2 deletions pumpkin-text/Cargo.toml → pumpkin-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "pumpkin-text"
name = "pumpkin-core"
version.workspace = true
edition.workspace = true

[dependencies]
serde = { version = "1.0", features = ["derive"] }
fastnbt = { git = "https://github.com/owengage/fastnbt.git" }
uuid = "1.10"
uuid.workspace = true
1 change: 1 addition & 0 deletions pumpkin-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod text;
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

use crate::{
use super::{
click::ClickEvent,
color::{self, Color},
hover::HoverEvent,
Expand Down
4 changes: 2 additions & 2 deletions pumpkin-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ 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"

uuid = "1.10"
uuid.workspace = true

serde = { version = "1.0", features = ["derive"] }
# to parse strings to json responses
Expand Down
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: 1 addition & 1 deletion pumpkin-protocol/src/client/config/c_add_resource_pack.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pumpkin_core::text::TextComponent;
use pumpkin_macros::packet;
use pumpkin_text::TextComponent;
use serde::Serialize;

use crate::uuid::UUID;
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/play/c_actionbar.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pumpkin_core::text::TextComponent;
use pumpkin_macros::packet;
use pumpkin_text::TextComponent;
use serde::Serialize;

#[derive(Serialize)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pumpkin_core::text::TextComponent;
use pumpkin_macros::packet;
use pumpkin_text::TextComponent;
use serde::Serialize;

use crate::VarInt;
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/play/c_open_screen.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pumpkin_core::text::TextComponent;
use pumpkin_macros::packet;
use pumpkin_text::TextComponent;
use serde::Serialize;

use crate::VarInt;
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/play/c_play_disconnect.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pumpkin_core::text::TextComponent;
use pumpkin_macros::packet;
use pumpkin_text::TextComponent;
use serde::Serialize;

#[derive(Serialize)]
Expand Down
55 changes: 52 additions & 3 deletions pumpkin-protocol/src/client/play/c_player_chat_message.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use num_derive::{FromPrimitive, ToPrimitive};
use num_traits::FromPrimitive;
use pumpkin_core::text::TextComponent;
use pumpkin_macros::packet;
use pumpkin_text::TextComponent;
use serde::Serialize;

use crate::{uuid::UUID, BitSet, VarInt};
use crate::{bytebuf::ByteBuffer, uuid::UUID, BitSet, ClientPacket, VarInt};

#[derive(Serialize)]
#[packet(0x39)]
pub struct CPlayerChatMessage<'a> {
sender: UUID,
Expand All @@ -19,6 +19,9 @@ pub struct CPlayerChatMessage<'a> {
unsigned_content: Option<TextComponent<'a>>,
/// See `FilterType`
filter_type: VarInt,

// TODO: Implement
#[allow(dead_code)]
filter_type_bits: Option<BitSet<'a>>,
chat_type: VarInt,
sender_name: TextComponent<'a>,
Expand Down Expand Up @@ -61,6 +64,52 @@ impl<'a> CPlayerChatMessage<'a> {
}
}

impl<'a> ClientPacket for CPlayerChatMessage<'a> {
fn write(&self, bytebuf: &mut ByteBuffer) {
bytebuf.put_uuid(self.sender.0);
bytebuf.put_var_int(&self.index);
bytebuf.put_option(&self.message_signature, |p, v| p.put_slice(v));
bytebuf.put_string(self.message);
bytebuf.put_i64(self.timestamp);
bytebuf.put_i64(self.salt);

if self.previous_messages_count.0 > 20 {
// TODO: Assert this is <=20
}

bytebuf.put_var_int(&self.previous_messages_count);
for previous_message in self.previous_messages {
bytebuf.put_var_int(&previous_message.message_id);
if let Some(prev_sig) = previous_message.signature {
// TODO: validate whether this should be None or not
bytebuf.put_slice(prev_sig);
}
}

bytebuf.put_option(&self.unsigned_content, |p, v| {
p.put_slice(v.encode().as_slice())
});

bytebuf.put_var_int(&self.filter_type);
match FilterType::from_i32(self.filter_type.0) {
Some(FilterType::PassThrough) => (),
Some(FilterType::FullyFiltered) => {
// TODO: Implement
}
Some(FilterType::PartiallyFiltered) => {
// TODO: Implement
}
None => {
// TODO: Implement
}
}

bytebuf.put_var_int(&self.chat_type);
bytebuf.put_slice(self.sender_name.encode().as_slice());
bytebuf.put_option(&self.target_name, |p, v| p.put_slice(v.encode().as_slice()));
}
}

#[derive(Serialize)]
pub struct PreviousMessage<'a> {
message_id: VarInt,
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/play/c_set_title.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pumpkin_core::text::TextComponent;
use pumpkin_macros::packet;
use pumpkin_text::TextComponent;
use serde::Serialize;

#[derive(Serialize)]
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/play/c_subtitle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pumpkin_core::text::TextComponent;
use pumpkin_macros::packet;
use pumpkin_text::TextComponent;
use serde::Serialize;

#[derive(Serialize)]
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/play/c_system_chat_message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pumpkin_core::text::TextComponent;
use pumpkin_macros::packet;
use pumpkin_text::TextComponent;
use serde::Serialize;

#[derive(Serialize)]
Expand Down
Loading

0 comments on commit fe5836a

Please sign in to comment.