Skip to content

Commit

Permalink
Merge branch 'master' into feat/schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
DataM0del authored Dec 26, 2024
2 parents 76c4c03 + d833582 commit 17c8ecf
Show file tree
Hide file tree
Showing 167 changed files with 1,748 additions and 1,132 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
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ members = [ "generate-schemas",
version = "0.1.0"
edition = "2021"

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

[profile.dev]
opt-level = 1
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM rust:1-alpine3.20 AS builder
FROM rust:1-alpine3.21 AS builder
ARG GIT_VERSION=Docker
ENV GIT_VERSION=$GIT_VERSION
ENV RUSTFLAGS="-C target-feature=-crt-static -C target-cpu=native"
ENV RUSTFLAGS="-C target-feature=-crt-static"
RUN apk add --no-cache musl-dev

WORKDIR /pumpkin
Expand All @@ -16,7 +16,7 @@ RUN --mount=type=cache,sharing=private,target=/pumpkin/target \
# strip debug symbols from binary
RUN strip pumpkin.release

FROM alpine:3.20
FROM alpine:3.21

# Identifying information for registries like ghcr.io
LABEL org.opencontainers.image.source=https://github.com/Snowiiii/Pumpkin
Expand Down
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 @@ -7,8 +7,9 @@ use schemars::JsonSchema;
use serde::{de::DeserializeOwned, Deserialize, Serialize};

use std::{
fs,
env, fs,
net::{Ipv4Addr, SocketAddr},
num::NonZeroU8,
path::Path,
sync::LazyLock,
};
Expand Down Expand Up @@ -37,6 +38,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 @@ -74,9 +77,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 @@ -106,8 +109,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 @@ -128,26 +131,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 @@ -179,9 +188,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: 1 addition & 1 deletion pumpkin-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use schemars::JsonSchema;

use serde::{Deserialize, Serialize};

#[derive(PartialEq, Serialize, Deserialize)]
#[derive(PartialEq, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub enum Difficulty {
Peaceful,
Expand Down
3 changes: 2 additions & 1 deletion pumpkin-inventory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ 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" }
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
8 changes: 6 additions & 2 deletions pumpkin-inventory/src/drag_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ impl DragHandler {
let changing_slots =
drag.possibly_changing_slots(&slots_cloned, carried_item.item_id);
let amount_of_slots = changing_slots.clone().count();
let (amount_per_slot, remainder) =
(carried_item.item_count as usize).div_rem_euclid(&amount_of_slots);
let (amount_per_slot, remainder) = if amount_of_slots == 0 {
// TODO: please work lol
(1, 0)
} else {
(carried_item.item_count as usize).div_rem_euclid(&amount_of_slots)
};
let mut item_in_each_slot = *carried_item;
item_in_each_slot.item_count = amount_per_slot as u8;
changing_slots.for_each(|slot| *slots[slot] = Some(item_in_each_slot));
Expand Down
7 changes: 7 additions & 0 deletions 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 Down
24 changes: 12 additions & 12 deletions pumpkin-protocol/src/bytebuf/deserializer.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::fmt::Display;

use super::{ByteBuf, ReadingError};
use bytes::Bytes;
use bytes::Buf;
use serde::de::{self, DeserializeSeed, SeqAccess};

pub struct Deserializer<'a> {
inner: &'a mut Bytes,
pub struct Deserializer<'a, B: Buf> {
inner: &'a mut B,
}

impl de::Error for ReadingError {
Expand All @@ -14,13 +14,13 @@ impl de::Error for ReadingError {
}
}

impl<'a> Deserializer<'a> {
pub fn new(buf: &'a mut Bytes) -> Self {
impl<'a, B: Buf> Deserializer<'a, B> {
pub fn new(buf: &'a mut B) -> Self {
Self { inner: buf }
}
}

impl<'de> de::Deserializer<'de> for Deserializer<'_> {
impl<'de, B: Buf> de::Deserializer<'de> for Deserializer<'_, B> {
type Error = ReadingError;

fn deserialize_any<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
Expand Down Expand Up @@ -184,11 +184,11 @@ impl<'de> de::Deserializer<'de> for Deserializer<'_> {
where
V: de::Visitor<'de>,
{
struct Access<'a, 'b> {
deserializer: &'a mut Deserializer<'b>,
struct Access<'a, 'b, B: Buf> {
deserializer: &'a mut Deserializer<'b, B>,
}

impl<'de, 'a, 'b: 'a> SeqAccess<'de> for Access<'a, 'b> {
impl<'de, 'a, 'b: 'a, B: Buf> SeqAccess<'de> for Access<'a, 'b, B> {
type Error = ReadingError;

fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
Expand Down Expand Up @@ -216,12 +216,12 @@ impl<'de> de::Deserializer<'de> for Deserializer<'_> {
where
V: de::Visitor<'de>,
{
struct Access<'a, 'b> {
deserializer: &'a mut Deserializer<'b>,
struct Access<'a, 'b, B: Buf> {
deserializer: &'a mut Deserializer<'b, B>,
len: usize,
}

impl<'de, 'a, 'b: 'a> SeqAccess<'de> for Access<'a, 'b> {
impl<'de, 'a, 'b: 'a, B: Buf> SeqAccess<'de> for Access<'a, 'b, B> {
type Error = ReadingError;

fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
Expand Down
Loading

0 comments on commit 17c8ecf

Please sign in to comment.