Skip to content

Commit

Permalink
Merge branch 'master' into pr/566
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Feb 22, 2025
2 parents 39d6b13 + 2af2fbb commit 1895fdb
Show file tree
Hide file tree
Showing 210 changed files with 674 additions and 520 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ members = [

[workspace.package]
version = "0.1.0"
edition = "2021"
edition = "2024"


[profile.dev]
Expand Down
7 changes: 7 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,17 @@ 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] Players
- [x] Mobs
- [x] Animals
- [x] Entity AI
- [ ] Boss
- [ ] Villagers
- [ ] Mobs Inventory
- Server
- [x] Plugins
- [x] Query
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "pumpkin-fuzz"
version = "0.0.0"
publish = false
edition = "2021"
edition = "2024"

[package.metadata]
cargo-fuzz = true
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-api-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use proc_macro::TokenStream;
use quote::quote;
use std::sync::LazyLock;
use std::sync::Mutex;
use syn::{parse_macro_input, parse_quote, ImplItem, ItemFn, ItemImpl, ItemStruct};
use syn::{ImplItem, ItemFn, ItemImpl, ItemStruct, parse_macro_input, parse_quote};

static PLUGIN_METHODS: LazyLock<Mutex<Vec<String>>> = LazyLock::new(|| Mutex::new(Vec::new()));

Expand Down
11 changes: 6 additions & 5 deletions pumpkin-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chunk::ChunkConfig;
use log::warn;
use logging::LoggingConfig;
use pumpkin_util::{Difficulty, GameMode, PermissionLvl};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde::{Deserialize, Serialize, de::DeserializeOwned};

use std::{
env, fs,
Expand Down Expand Up @@ -184,14 +184,15 @@ impl LoadConfiguration for BasicConfiguration {
}

fn validate(&self) {
let min = unsafe { NonZeroU8::new_unchecked(2) };
let max = unsafe { NonZeroU8::new_unchecked(32) };

assert!(
self.view_distance
.ge(unsafe { &NonZeroU8::new_unchecked(2) }),
self.view_distance.ge(&min),
"View distance must be at least 2"
);
assert!(
self.view_distance
.le(unsafe { &NonZeroU8::new_unchecked(32) }),
self.view_distance.le(&max),
"View distance must be less than 32"
);
if self.online_mode {
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-data/build/entity_type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use proc_macro2::TokenStream;
use quote::{format_ident, quote, ToTokens};
use quote::{ToTokens, format_ident, quote};
use serde::Deserialize;
use syn::LitInt;

Expand Down
2 changes: 1 addition & 1 deletion pumpkin-data/build/item.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use heck::ToShoutySnakeCase;
use proc_macro2::{Span, TokenStream};
use quote::{format_ident, quote, ToTokens};
use quote::{ToTokens, format_ident, quote};
use syn::{Ident, LitBool, LitFloat, LitInt, LitStr};

include!("../src/tag.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
4 changes: 2 additions & 2 deletions pumpkin-inventory/src/crafting.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use pumpkin_data::{
item::Item,
tag::{get_tag_values, RegistryEntryList, RegistryKey, TagType},
tag::{RegistryEntryList, RegistryKey, TagType, get_tag_values},
};
use pumpkin_registry::{flatten_3x3, RecipeResult, RECIPES};
use pumpkin_registry::{RECIPES, RecipeResult, flatten_3x3};
use pumpkin_world::item::ItemStack;
use rayon::prelude::*;

Expand Down
8 changes: 2 additions & 6 deletions pumpkin-inventory/src/open_container.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::crafting::check_if_matches_crafting;
use crate::Container;
use crate::crafting::check_if_matches_crafting;
use pumpkin_data::screen::WindowType;
use pumpkin_util::math::position::BlockPos;
use pumpkin_world::block::registry::Block;
Expand Down Expand Up @@ -34,11 +34,7 @@ impl OpenContainer {

pub fn remove_player(&mut self, player_id: i32) {
if let Some(index) = self.players.iter().enumerate().find_map(|(index, id)| {
if *id == player_id {
Some(index)
} else {
None
}
if *id == player_id { Some(index) } else { None }
}) {
self.players.remove(index);
}
Expand Down
86 changes: 70 additions & 16 deletions pumpkin-inventory/src/player.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
use crate::container_click::MouseClick;
use crate::crafting::check_if_matches_crafting;
use crate::{handle_item_change, Container, InventoryError, WindowType};
use crate::{Container, InventoryError, WindowType, handle_item_change};
use pumpkin_data::item::Item;
use pumpkin_world::item::ItemStack;
use std::iter::Chain;
use std::slice::IterMut;

/*
Inventory Layout:
- 0: Crafting Output
- 1-4: Crafting Input
- 5-8: Armor
- 9-35: Main Inventory
- 36-44: Hotbar
- 45: Offhand
*/

pub struct PlayerInventory {
// Main Inventory + Hotbar
crafting: [Option<ItemStack>; 4],
Expand Down Expand Up @@ -137,24 +149,10 @@ impl PlayerInventory {
false
}

pub fn get_slot_with_item(&self, item_id: u16, max_stack: u8) -> Option<usize> {
for slot in 9..=44 {
match &self.items[slot - 9] {
Some(item) if item.item.id == item_id && item.item_count <= max_stack => {
return Some(slot)
}
_ => continue,
}
}

None
}

/// Checks if we can merge an existing item into an Stack or if a any new Slot is empty
pub fn collect_item_slot(&self, item_id: u16) -> Option<usize> {
// Lets try to merge first
// TODO: Max stack size
if let Some(stack) = self.get_slot_with_item(item_id, 64) {
if let Some(stack) = self.get_nonfull_slot_with_item(item_id) {
return Some(stack);
}
if let Some(empty) = self.get_empty_slot() {
Expand All @@ -177,7 +175,63 @@ impl PlayerInventory {
self.selected
}

pub fn get_nonfull_slot_with_item(&self, item_id: u16) -> Option<usize> {
let max_stack = Item::from_id(item_id)
.unwrap_or(Item::AIR)
.components
.max_stack_size;

// Check selected slot
if let Some(item) = &self.items[self.selected as usize + 36 - 9] {
if item.item.id == item_id && item.item_count < max_stack {
// + 9 - 9 is 0
return Some(self.selected as usize + 36);
}
}

// Check hotbar slots (27-35) first
if let Some(index) = self.items[27..36].iter().position(|slot| {
slot.is_some_and(|item| item.item.id == item_id && item.item_count < max_stack)
}) {
return Some(index + 27 + 9);
}

// Then check main inventory slots (0-26)
if let Some(index) = self.items[0..27].iter().position(|slot| {
slot.is_some_and(|item| item.item.id == item_id && item.item_count < max_stack)
}) {
return Some(index + 9);
}

None
}

pub fn get_slot_with_item(&self, item_id: u16) -> Option<usize> {
for slot in 9..=44 {
match &self.items[slot - 9] {
Some(item) if item.item.id == item_id => return Some(slot),
_ => continue,
}
}

None
}

pub fn get_empty_slot(&self) -> Option<usize> {
// Check hotbar slots (27-35) first
if let Some(index) = self.items[27..36].iter().position(|slot| slot.is_none()) {
return Some(index + 27 + 9);
}

// Then check main inventory slots (0-26)
if let Some(index) = self.items[0..27].iter().position(|slot| slot.is_none()) {
return Some(index + 9);
}

None
}

pub fn get_empty_slot_no_order(&self) -> Option<usize> {
self.items
.iter()
.position(|slot| slot.is_none())
Expand Down
23 changes: 12 additions & 11 deletions pumpkin-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use proc_macro::TokenStream;
use pumpkin_data::item::Item;
use quote::quote;
use syn::{
Block, Expr, Field, Fields, ItemStruct, Stmt,
parse::{Nothing, Parser},
parse_macro_input, Block, Expr, Field, Fields, ItemStruct, Stmt,
parse_macro_input,
};

extern crate proc_macro;
Expand Down Expand Up @@ -161,14 +162,14 @@ pub fn client_packet(input: TokenStream, item: TokenStream) -> TokenStream {
let input: proc_macro2::TokenStream = input.into();
let item: proc_macro2::TokenStream = item.into();

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

gen.into()
code.into()
}

#[proc_macro_attribute]
Expand All @@ -180,14 +181,14 @@ pub fn server_packet(input: TokenStream, item: TokenStream) -> TokenStream {
let input: proc_macro2::TokenStream = input.into();
let item: proc_macro2::TokenStream = item.into();

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

gen.into()
code.into()
}

#[proc_macro_attribute]
Expand All @@ -205,15 +206,15 @@ pub fn pumpkin_block(input: TokenStream, item: TokenStream) -> TokenStream {

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

let gen = quote! {
let code = quote! {
#item
impl #impl_generics crate::block::pumpkin_block::BlockMetadata for #name #ty_generics {
const NAMESPACE: &'static str = #namespace;
const ID: &'static str = #id;
}
};

gen.into()
code.into()
}

#[proc_macro_attribute]
Expand All @@ -229,14 +230,14 @@ pub fn pumpkin_item(input: TokenStream, item: TokenStream) -> TokenStream {

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

let gen = quote! {
let code = quote! {
#item
impl #impl_generics crate::item::pumpkin_item::ItemMetadata for #name #ty_generics {
const ID: u16 = #id;
}
};

gen.into()
code.into()
}

#[proc_macro_attribute]
Expand Down Expand Up @@ -351,7 +352,7 @@ pub fn block_property(input: TokenStream, item: TokenStream) -> TokenStream {
}
};

let gen = quote! {
let code = quote! {
#item
impl #impl_generics crate::block::properties::BlockPropertyMetadata for #name #ty_generics {
fn name(&self) -> &'static str {
Expand All @@ -372,7 +373,7 @@ pub fn block_property(input: TokenStream, item: TokenStream) -> TokenStream {
#extra
};

gen.into()
code.into()
}

mod block_state;
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-nbt/src/compound.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::deserializer::ReadAdaptor;
use crate::serializer::WriteAdaptor;
use crate::tag::NbtTag;
use crate::{get_nbt_string, Error, Nbt, END_ID};
use crate::{END_ID, Error, Nbt, get_nbt_string};
use std::io::{ErrorKind, Read, Write};
use std::vec::IntoIter;

Expand Down
2 changes: 1 addition & 1 deletion pumpkin-nbt/src/deserializer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::*;
use io::Read;
use serde::de::{self, DeserializeSeed, IntoDeserializer, MapAccess, SeqAccess, Visitor};
use serde::{forward_to_deserialize_any, Deserialize};
use serde::{Deserialize, forward_to_deserialize_any};

pub type Result<T> = std::result::Result<T, Error>;

Expand Down
Loading

0 comments on commit 1895fdb

Please sign in to comment.