Skip to content

Commit

Permalink
Merge branch 'Pumpkin-MC:master' into chunk_bulk_api_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mili-ssm authored Feb 24, 2025
2 parents 0e792c0 + 110ba3a commit e362d04
Show file tree
Hide file tree
Showing 212 changed files with 1,656 additions and 947 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bytes = "1.10"
rayon = "1.10"
crossbeam = "0.8"

uuid = { version = "1.13", features = ["serde", "v3", "v4"] }
uuid = { version = "1.14", features = ["serde", "v3", "v4"] }
derive_more = { version = "2.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ and customizable experience. It prioritizes performance and player enjoyment whi
- [x] World Saving
- [ ] Redstone
- [ ] Liquid Physics
- [ ] Biomes
- [ ] Vegetation
- [ ] Player Data Saving
- Player
- [x] Skins
- [x] Client brand
Expand All @@ -65,13 +68,18 @@ and customizable experience. It prioritizes performance and player enjoyment whi
- [x] Combat
- [x] Experience
- [x] Hunger
- [ ] Off Hand
- [ ] Advancements
- Entities
- [x] Non-Living (Minecart, Eggs...)
- [x] Entity Effects
- [x] Players
- [x] Mobs
- [x] Animals
- [x] Entity AI
- [ ] Boss
- [ ] Villagers
- [ ] Mobs Inventory
- Server
- [x] Plugins
- [x] Query
Expand Down
41 changes: 41 additions & 0 deletions assets/status_effects.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[
"speed",
"slowness",
"haste",
"mining_fatigue",
"strength",
"instant_health",
"instant_damage",
"jump_boost",
"nausea",
"regeneration",
"resistance",
"fire_resistance",
"water_breathing",
"invisibility",
"blindness",
"night_vision",
"hunger",
"weakness",
"poison",
"wither",
"health_boost",
"absorption",
"saturation",
"glowing",
"levitation",
"luck",
"unluck",
"slow_falling",
"conduit_power",
"dolphins_grace",
"bad_omen",
"hero_of_the_village",
"darkness",
"trial_omen",
"raid_omen",
"wind_charged",
"weaving",
"oozing",
"infested"
]
21 changes: 14 additions & 7 deletions pumpkin-config/src/resource_pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,32 @@ use serde::{Deserialize, Serialize};
pub struct ResourcePackConfig {
pub enabled: bool,
/// The path to the resource pack.
pub url: String,
pub resource_pack_url: String,
/// The SHA1 hash (40) of the resource pack.
pub sha1: String,
pub resource_pack_sha1: String,
/// Custom prompt Text component, Leave blank for none
pub message: String,
pub prompt_message: String,
/// Will force the Player to accept the resource pack
pub force: bool,
}

impl ResourcePackConfig {
pub fn validate(&self) {
if !self.enabled {
return;
}

assert_eq!(
!self.url.is_empty(),
!self.sha1.is_empty(),
!self.resource_pack_url.is_empty(),
!self.resource_pack_sha1.is_empty(),
"Resource Pack path or Sha1 hash is missing"
);

let hash_len = self.resource_pack_sha1.len();
assert!(
self.sha1.len() <= 40,
"Resource pack sha1 hash is too long (max. 40)"
hash_len == 40,
"Resource pack sha1 hash is the wrong length (should be 40, is {})",
hash_len
)
}
}
2 changes: 2 additions & 0 deletions pumpkin-data/build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod screen;
mod sound;
mod sound_category;
mod spawn_egg;
mod status_effect;
mod world_event;

pub fn main() {
Expand All @@ -42,6 +43,7 @@ pub fn main() {
write_generated_file(spawn_egg::build(), "spawn_egg.rs");
write_generated_file(item::build(), "item.rs");
write_generated_file(fluid::build(), "fluid.rs");
write_generated_file(status_effect::build(), "status_effect.rs");
}

pub fn array_to_tokenstream(array: &[String]) -> TokenStream {
Expand Down
51 changes: 51 additions & 0 deletions pumpkin-data/build/status_effect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use heck::ToPascalCase;
use proc_macro2::TokenStream;
use quote::{format_ident, quote};

pub(crate) fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/status_effects.json");

let chunk_status: Vec<String> =
serde_json::from_str(include_str!("../../assets/status_effects.json"))
.expect("Failed to parse status_effects.json");
let mut variants = TokenStream::new();
let mut type_from_name = TokenStream::new();
let mut type_to_name = TokenStream::new();

for status in chunk_status.iter() {
let const_ident = format_ident!("{}", status.to_pascal_case());
let resource_name = status.to_lowercase();

variants.extend([quote! {
#const_ident,
}]);
type_from_name.extend(quote! {
#resource_name => Some(Self::#const_ident),
});
type_to_name.extend(quote! {
Self::#const_ident => #resource_name,
});
}
quote! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum EffectType {
#variants
}

impl EffectType {
#[doc = r" Try to parse a Effect Type from a resource location string"]
pub fn from_name(name: &str) -> Option<Self> {
match name {
#type_from_name
_ => None
}
}

pub const fn to_name(&self) -> &'static str {
match self {
#type_to_name
}
}
}
}
}
1 change: 1 addition & 0 deletions pumpkin-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub mod game_event {
}

pub mod entity {
include!(concat!(env!("OUT_DIR"), "/status_effect.rs"));
include!(concat!(env!("OUT_DIR"), "/spawn_egg.rs"));
include!(concat!(env!("OUT_DIR"), "/entity_type.rs"));
include!(concat!(env!("OUT_DIR"), "/entity_pose.rs"));
Expand Down
5 changes: 4 additions & 1 deletion pumpkin-inventory/src/container_click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl Click {
}
}

#[derive(Debug)]
pub enum ClickType {
MouseClick(MouseClick),
ShiftClick,
Expand All @@ -114,6 +115,7 @@ pub enum MouseClick {
Right,
}

#[derive(Debug)]
pub enum KeyClick {
Slot(u8),
Offhand,
Expand All @@ -124,6 +126,7 @@ pub enum Slot {
OutsideInventory,
}

#[derive(Debug)]
pub enum DropType {
SingleItem,
FullStack,
Expand All @@ -134,7 +137,7 @@ pub enum MouseDragType {
Right,
Middle,
}
#[derive(PartialEq)]
#[derive(PartialEq, Debug)]
pub enum MouseDragState {
Start(MouseDragType),
AddSlot(usize),
Expand Down
21 changes: 1 addition & 20 deletions pumpkin-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,7 @@ pub fn send_cancellable(input: TokenStream) -> TokenStream {
}

#[proc_macro_attribute]
pub fn client_packet(input: TokenStream, item: TokenStream) -> TokenStream {
let ast: syn::DeriveInput = syn::parse(item.clone()).unwrap();
let name = &ast.ident;
let (impl_generics, ty_generics, _) = ast.generics.split_for_impl();

let input: proc_macro2::TokenStream = input.into();
let item: proc_macro2::TokenStream = item.into();

let code = quote! {
#item
impl #impl_generics crate::bytebuf::packet::Packet for #name #ty_generics {
const PACKET_ID: i32 = #input;
}
};

code.into()
}

#[proc_macro_attribute]
pub fn server_packet(input: TokenStream, item: TokenStream) -> TokenStream {
pub fn packet(input: TokenStream, item: TokenStream) -> TokenStream {
let ast: syn::DeriveInput = syn::parse(item.clone()).unwrap();
let name = &ast.ident;
let (impl_generics, ty_generics, _) = ast.generics.split_for_impl();
Expand Down
5 changes: 4 additions & 1 deletion pumpkin-protocol/src/bytebuf/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<B: BufMut> ser::Serializer for &mut Serializer<B> {
unimplemented!()
}
fn serialize_unit_struct(self, _name: &'static str) -> Result<Self::Ok, Self::Error> {
todo!()
Ok(())
}
fn serialize_unit_variant(
self,
Expand All @@ -219,6 +219,9 @@ impl<B: BufMut> ser::Serializer for &mut Serializer<B> {
self.output.put_var_int(&variant_index.into());
Ok(())
}
fn is_human_readable(&self) -> bool {
false
}
}

impl<B: BufMut> ser::SerializeSeq for &mut Serializer<B> {
Expand Down
9 changes: 5 additions & 4 deletions pumpkin-protocol/src/client/config/add_resource_pack.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use pumpkin_util::text::TextComponent;

use pumpkin_macros::client_packet;
use pumpkin_macros::packet;
use serde::Serialize;

use pumpkin_data::packet::clientbound::CONFIG_RESOURCE_PACK_PUSH;

#[derive(Serialize)]
#[client_packet(CONFIG_RESOURCE_PACK_PUSH)]
#[packet(CONFIG_RESOURCE_PACK_PUSH)]
pub struct CConfigAddResourcePack<'a> {
uuid: uuid::Uuid,
#[serde(with = "uuid::serde::compact")]
uuid: &'a uuid::Uuid,
url: &'a str,
hash: &'a str, // max 40
forced: bool,
Expand All @@ -17,7 +18,7 @@ pub struct CConfigAddResourcePack<'a> {

impl<'a> CConfigAddResourcePack<'a> {
pub fn new(
uuid: uuid::Uuid,
uuid: &'a uuid::Uuid,
url: &'a str,
hash: &'a str,
forced: bool,
Expand Down
10 changes: 5 additions & 5 deletions pumpkin-protocol/src/client/config/config_disconnect.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use pumpkin_macros::client_packet;

use pumpkin_data::packet::clientbound::CONFIG_DISCONNECT;
use pumpkin_macros::packet;
use serde::Deserialize;

#[derive(serde::Serialize)]
#[client_packet(CONFIG_DISCONNECT)]
#[derive(serde::Serialize, Deserialize)]
#[packet(CONFIG_DISCONNECT)]
pub struct CConfigDisconnect<'a> {
reason: &'a str,
pub reason: &'a str,
}

impl<'a> CConfigDisconnect<'a> {
Expand Down
6 changes: 3 additions & 3 deletions pumpkin-protocol/src/client/config/cookie_request.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use pumpkin_data::packet::clientbound::CONFIG_COOKIE_REQUEST;
use pumpkin_macros::client_packet;
use pumpkin_macros::packet;

use crate::codec::identifier::Identifier;

#[derive(serde::Serialize)]
#[client_packet(CONFIG_COOKIE_REQUEST)]
#[packet(CONFIG_COOKIE_REQUEST)]
/// Requests a cookie that was previously stored.
pub struct CCookieRequest<'a> {
key: &'a Identifier,
pub key: &'a Identifier,
}

impl<'a> CCookieRequest<'a> {
Expand Down
21 changes: 5 additions & 16 deletions pumpkin-protocol/src/client/config/finish_config.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
use pumpkin_data::packet::clientbound::CONFIG_FINISH_CONFIGURATION;
use pumpkin_macros::client_packet;
use pumpkin_macros::packet;
use serde::Serialize;

#[derive(serde::Serialize)]
#[client_packet(CONFIG_FINISH_CONFIGURATION)]
pub struct CFinishConfig {}

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

impl CFinishConfig {
pub fn new() -> Self {
Self {}
}
}
#[derive(Serialize)]
#[packet(CONFIG_FINISH_CONFIGURATION)]
pub struct CFinishConfig;
6 changes: 3 additions & 3 deletions pumpkin-protocol/src/client/config/known_packs.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use bytes::BufMut;
use pumpkin_data::packet::clientbound::CONFIG_SELECT_KNOWN_PACKS;
use pumpkin_macros::client_packet;
use pumpkin_macros::packet;

use crate::{ClientPacket, KnownPack, bytebuf::ByteBufMut};

#[client_packet(CONFIG_SELECT_KNOWN_PACKS)]
#[packet(CONFIG_SELECT_KNOWN_PACKS)]
pub struct CKnownPacks<'a> {
known_packs: &'a [KnownPack<'a>],
pub known_packs: &'a [KnownPack<'a>],
}

impl<'a> CKnownPacks<'a> {
Expand Down
8 changes: 4 additions & 4 deletions pumpkin-protocol/src/client/config/plugin_message.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use pumpkin_data::packet::clientbound::CONFIG_CUSTOM_PAYLOAD;
use pumpkin_macros::client_packet;
use pumpkin_macros::packet;
use serde::Serialize;

#[derive(Serialize)]
#[client_packet(CONFIG_CUSTOM_PAYLOAD)]
#[packet(CONFIG_CUSTOM_PAYLOAD)]
pub struct CPluginMessage<'a> {
channel: &'a str,
data: &'a [u8],
pub channel: &'a str,
pub data: &'a [u8],
}

impl<'a> CPluginMessage<'a> {
Expand Down
Loading

0 comments on commit e362d04

Please sign in to comment.