Skip to content

Commit

Permalink
Merge branch 'master' into fix_global_inventories
Browse files Browse the repository at this point in the history
  • Loading branch information
OfficialKris committed Dec 24, 2024
2 parents f8bea62 + f5c20fb commit aad44d8
Show file tree
Hide file tree
Showing 173 changed files with 2,348 additions and 1,799 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v4
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --all-targets --all-features --no-default-features
- run: cargo clippy --all-targets --all-features
build_and_test:
name: Build project and test
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -77,4 +77,4 @@ jobs:
- uses: actions/checkout@v4
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --release --all-targets --all-features --no-default-features
- run: cargo clippy --release --all-targets --all-features
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ gradle-app.setting
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
Expand Down
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ members = [
version = "0.1.0"
edition = "2021"

[profile.dev.package."*"]
opt-level = 3

[profile.dev]
opt-level = 1
Expand Down Expand Up @@ -61,5 +59,3 @@ uuid = { version = "1.11.0", features = ["serde", "v3", "v4"] }
derive_more = { version = "1.0.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

itertools = "0.13.0"
4 changes: 2 additions & 2 deletions extractor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "2.0.21"
id("fabric-loom") version "1.8.9"
kotlin("jvm") version "2.1.0"
id("fabric-loom") version "1.9-SNAPSHOT"
id("maven-publish")
}

Expand Down
8 changes: 3 additions & 5 deletions extractor/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ org.gradle.parallel=true
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.1
yarn_mappings=1.21.4+build.2
loader_version=0.16.9
kotlin_loader_version=1.12.3+kotlin.2.0.21
kotlin_loader_version=1.13.0+kotlin.2.1.0
# Mod Properties
mod_version=1.0-SNAPSHOT
maven_group=de.snowii
archives_base_name=extractor
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.110.5+1.21.4
fabric_version=0.112.1+1.21.4
40 changes: 27 additions & 13 deletions pumpkin-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use query::QueryConfig;
use serde::{de::DeserializeOwned, Deserialize, Serialize};

use std::{
fs,
env, fs,
net::{Ipv4Addr, SocketAddr},
num::NonZeroU8,
path::Path,
sync::LazyLock,
};
Expand Down Expand Up @@ -35,6 +36,8 @@ mod server_links;
use proxy::ProxyConfig;
use resource_pack::ResourcePackConfig;

const CONFIG_ROOT_FOLDER: &str = "config/";

pub static ADVANCED_CONFIG: LazyLock<AdvancedConfiguration> =
LazyLock::new(AdvancedConfiguration::load);

Expand Down Expand Up @@ -71,9 +74,9 @@ pub struct BasicConfiguration {
/// The maximum number of players allowed on the server. Specifying `0` disables the limit.
pub max_players: u32,
/// The maximum view distance for players.
pub view_distance: u8,
pub view_distance: NonZeroU8,
/// The maximum simulated view distance.
pub simulation_distance: u8,
pub simulation_distance: NonZeroU8,
/// The default game difficulty.
pub default_difficulty: Difficulty,
/// Whether the Nether dimension is enabled.
Expand Down Expand Up @@ -103,8 +106,8 @@ impl Default for BasicConfiguration {
server_address: SocketAddr::new(Ipv4Addr::new(0, 0, 0, 0).into(), 25565),
seed: "".to_string(),
max_players: 100000,
view_distance: 10,
simulation_distance: 10,
view_distance: NonZeroU8::new(10).unwrap(),
simulation_distance: NonZeroU8::new(10).unwrap(),
default_difficulty: Difficulty::Normal,
allow_nether: true,
hardcore: false,
Expand All @@ -125,26 +128,32 @@ trait LoadConfiguration {
where
Self: Sized + Default + Serialize + DeserializeOwned,
{
let path = Self::get_path();
let exe_dir = env::current_dir().unwrap();
let config_dir = exe_dir.join(CONFIG_ROOT_FOLDER);
if !config_dir.exists() {
log::debug!("creating new config root folder");
fs::create_dir(&config_dir).expect("Failed to create Config root folder");
}
let path = config_dir.join(Self::get_path());

let config = if path.exists() {
let file_content = fs::read_to_string(path)
.unwrap_or_else(|_| panic!("Couldn't read configuration file at {:?}", path));
let file_content = fs::read_to_string(&path)
.unwrap_or_else(|_| panic!("Couldn't read configuration file at {:?}", &path));

toml::from_str(&file_content).unwrap_or_else(|err| {
panic!(
"Couldn't parse config at {:?}. Reason: {}. This is is proberbly caused by an Config update, Just delete the old Config and start Pumpkin again",
path,
&path,
err.message()
)
})
} else {
let content = Self::default();

if let Err(err) = fs::write(path, toml::to_string(&content).unwrap()) {
if let Err(err) = fs::write(&path, toml::to_string(&content).unwrap()) {
warn!(
"Couldn't write default config to {:?}. Reason: {}. This is is proberbly caused by an Config update, Just delete the old Config and start Pumpkin again",
path, err
&path, err
);
}

Expand Down Expand Up @@ -176,9 +185,14 @@ impl LoadConfiguration for BasicConfiguration {
}

fn validate(&self) {
assert!(self.view_distance >= 2, "View distance must be at least 2");
assert!(
self.view_distance <= 32,
self.view_distance
.ge(unsafe { &NonZeroU8::new_unchecked(2) }),
"View distance must be at least 2"
);
assert!(
self.view_distance
.le(unsafe { &NonZeroU8::new_unchecked(32) }),
"View distance must be less than 32"
);
if self.online_mode {
Expand Down
2 changes: 0 additions & 2 deletions pumpkin-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ num-derive.workspace = true

colored = "2"
md5 = "0.7.0"

enum_dispatch = "0.3.13"
2 changes: 1 addition & 1 deletion pumpkin-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use gamemode::GameMode;

use serde::{Deserialize, Serialize};

#[derive(PartialEq, Serialize, Deserialize)]
#[derive(PartialEq, Serialize, Deserialize, Clone)]
pub enum Difficulty {
Peaceful,
Easy,
Expand Down
29 changes: 27 additions & 2 deletions pumpkin-core/src/random/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
use std::{
sync::atomic::{AtomicU64, Ordering},
time,
};

use legacy_rand::{LegacyRand, LegacySplitter};
use xoroshiro128::{Xoroshiro, XoroshiroSplitter};

mod gaussian;
pub mod legacy_rand;
pub mod xoroshiro128;

static SEED_UNIQUIFIER: AtomicU64 = AtomicU64::new(8682522807148012u64);

pub fn get_seed() -> u64 {
let seed = SEED_UNIQUIFIER
.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |val| {
Some(val.wrapping_mul(1181783497276652981u64))
})
// We always return Some, so there will always be an Ok result
.unwrap();

let nanos = time::SystemTime::now()
.duration_since(time::SystemTime::UNIX_EPOCH)
.unwrap()
.as_nanos();

let nano_upper = (nanos >> 8) as u64;
let nano_lower = nanos as u64;
seed ^ nano_upper ^ nano_lower
}

pub enum RandomGenerator {
Xoroshiro(Xoroshiro),
Legacy(LegacyRand),
Expand Down Expand Up @@ -186,7 +211,7 @@ pub trait RandomDeriverImpl {
fn split_pos(&self, x: i32, y: i32, z: i32) -> impl RandomImpl;
}

fn hash_block_pos(x: i32, y: i32, z: i32) -> i64 {
pub fn hash_block_pos(x: i32, y: i32, z: i32) -> i64 {
let l = (x.wrapping_mul(3129871) as i64) ^ ((z as i64).wrapping_mul(116129781i64)) ^ (y as i64);
let l = l
.wrapping_mul(l)
Expand All @@ -195,7 +220,7 @@ fn hash_block_pos(x: i32, y: i32, z: i32) -> i64 {
l >> 16
}

fn java_string_hash(string: &str) -> i32 {
pub fn java_string_hash(string: &str) -> i32 {
// All byte values of latin1 align with
// the values of U+0000 - U+00FF making this code
// equivalent to both java hash implementations
Expand Down
5 changes: 2 additions & 3 deletions pumpkin-inventory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ version.workspace = true
edition.workspace = true

[dependencies]
# For items
pumpkin-protocol = { path = "../pumpkin-protocol" }

pumpkin-world = { path = "../pumpkin-world" }
pumpkin-registry = {path = "../pumpkin-registry"}
pumpkin-macros = { path = "../pumpkin-macros" }
pumpkin-core = { path = "../pumpkin-core" }

log.workspace = true
rayon.workspace = true
itertools.workspace = true
crossbeam.workspace = true
tokio.workspace = true
thiserror.workspace = true

Expand Down
20 changes: 10 additions & 10 deletions pumpkin-inventory/src/container_click.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::InventoryError;
use pumpkin_protocol::server::play::SlotActionType;
use pumpkin_world::item::ItemStack;

pub struct Click {
Expand All @@ -7,31 +8,30 @@ pub struct Click {
}

impl Click {
pub fn new(mode: u8, button: i8, slot: i16) -> Result<Self, InventoryError> {
pub fn new(mode: SlotActionType, button: i8, slot: i16) -> Result<Self, InventoryError> {
match mode {
0 => Self::new_normal_click(button, slot),
SlotActionType::Pickup => Self::new_normal_click(button, slot),
// Both buttons do the same here, so we omit it
1 => Self::new_shift_click(slot),
2 => Self::new_key_click(button, slot),
3 => Ok(Self {
SlotActionType::QuickMove => Self::new_shift_click(slot),
SlotActionType::Swap => Self::new_key_click(button, slot),
SlotActionType::Clone => Ok(Self {
click_type: ClickType::CreativePickItem,
slot: Slot::Normal(slot.try_into().or(Err(InventoryError::InvalidSlot))?),
}),
4 => Self::new_drop_item(button),
5 => Self::new_drag_item(button, slot),
6 => Ok(Self {
SlotActionType::Throw => Self::new_drop_item(button),
SlotActionType::QuickCraft => Self::new_drag_item(button, slot),
SlotActionType::PickupAll => Ok(Self {
click_type: ClickType::DoubleClick,
slot: Slot::Normal(slot.try_into().or(Err(InventoryError::InvalidSlot))?),
}),
_ => Err(InventoryError::InvalidPacket),
}
}

fn new_normal_click(button: i8, slot: i16) -> Result<Self, InventoryError> {
let slot = match slot {
-999 => Slot::OutsideInventory,
_ => {
let slot = slot.try_into().or(Err(InventoryError::InvalidSlot))?;
let slot = slot.try_into().unwrap_or(0);
Slot::Normal(slot)
}
};
Expand Down
5 changes: 2 additions & 3 deletions pumpkin-inventory/src/crafting.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use itertools::Itertools;
use pumpkin_registry::{
flatten_3x3, get_tag_values, IngredientSlot, IngredientType, RecipeResult, TagCategory, RECIPES,
};
Expand Down Expand Up @@ -76,13 +75,13 @@ fn shapeless_crafting_match(
input: [[Option<ItemStack>; 3]; 3],
pattern: &[[[Option<IngredientSlot>; 3]; 3]],
) -> bool {
let mut pattern = pattern
let mut pattern: Vec<IngredientSlot> = pattern
.iter()
.flatten()
.flatten()
.flatten()
.cloned()
.collect_vec();
.collect();
for item in input.into_iter().flatten().flatten() {
if let Some(index) = pattern.iter().enumerate().find_map(|(i, recipe_item)| {
if ingredient_slot_check(recipe_item, item) {
Expand Down
5 changes: 2 additions & 3 deletions pumpkin-inventory/src/drag_handler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::container_click::MouseDragType;
use crate::{Container, InventoryError};
use itertools::Itertools;
use num_traits::Euclid;
use pumpkin_world::item::ItemStack;
use std::collections::HashMap;
Expand Down Expand Up @@ -73,10 +72,10 @@ impl DragHandler {
Err(InventoryError::MultiplePlayersDragging)?
}
let mut slots = container.all_slots();
let slots_cloned = slots
let slots_cloned: Vec<Option<ItemStack>> = slots
.iter()
.map(|stack| stack.map(|item| item.to_owned()))
.collect_vec();
.collect();
let Some(carried_item) = maybe_carried_item else {
return Ok(());
};
Expand Down
1 change: 0 additions & 1 deletion pumpkin-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ proc-macro = true
[dependencies]
serde.workspace = true
serde_json.workspace = true
itertools.workspace = true

proc-macro2 = "1.0"
quote = "1.0"
Expand Down
8 changes: 7 additions & 1 deletion pumpkin-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ name = "pumpkin-protocol"
version.workspace = true
edition.workspace = true

[features]
default = ["packets", "query"]
packets = ["serverbound", "clientbound"]
serverbound = []
clientbound = []
query = []

[dependencies]
pumpkin-nbt = { path = "../pumpkin-nbt" }
pumpkin-config = { path = "../pumpkin-config" }
Expand All @@ -13,7 +20,6 @@ pumpkin-core = { path = "../pumpkin-core" }
uuid.workspace = true
serde.workspace = true
thiserror.workspace = true
itertools.workspace = true
log.workspace = true
tokio.workspace = true
num-traits.workspace = true
Expand Down
Loading

0 comments on commit aad44d8

Please sign in to comment.