Skip to content

Commit

Permalink
Merge branch 'plugins' of https://github.com/vyPal/Pumpkin into plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
vyPal committed Jan 10, 2025
2 parents 920c2d2 + 96d0562 commit 788ea0c
Show file tree
Hide file tree
Showing 265 changed files with 1,090 additions and 711 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ Temporary Items

## Java/Gradle Stuff
.gradle
**/build/
!src/**/build/
.kotlin

Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
resolver = "2"
members = [
"pumpkin-config",
"pumpkin-core",
"pumpkin-util",
"pumpkin-entity",
"pumpkin-inventory",
"pumpkin-macros/",
"pumpkin-protocol/",
"pumpkin-registry/",
"pumpkin-world",
"pumpkin/",
"pumpkin/", "pumpkin-data",
]

[workspace.package]
Expand Down
1 change: 1 addition & 0 deletions assets/chunk_status.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["empty","structure_starts","structure_references","biomes","noise","surface","carvers","features","initialize_light","light","spawn","full"]
1 change: 1 addition & 0 deletions assets/noise_parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"aquifer_barrier":{"first_octave":-3,"amplitudes":[1.0]},"aquifer_fluid_level_floodedness":{"first_octave":-7,"amplitudes":[1.0]},"aquifer_fluid_level_spread":{"first_octave":-5,"amplitudes":[1.0]},"aquifer_lava":{"first_octave":-1,"amplitudes":[1.0]},"badlands_pillar":{"first_octave":-2,"amplitudes":[1.0,1.0,1.0,1.0]},"badlands_pillar_roof":{"first_octave":-8,"amplitudes":[1.0]},"badlands_surface":{"first_octave":-6,"amplitudes":[1.0,1.0,1.0]},"calcite":{"first_octave":-9,"amplitudes":[1.0,1.0,1.0,1.0]},"cave_cheese":{"first_octave":-8,"amplitudes":[0.5,1.0,2.0,1.0,2.0,1.0,0.0,2.0,0.0]},"cave_entrance":{"first_octave":-7,"amplitudes":[0.4,0.5,1.0]},"cave_layer":{"first_octave":-8,"amplitudes":[1.0]},"clay_bands_offset":{"first_octave":-8,"amplitudes":[1.0]},"continentalness":{"first_octave":-9,"amplitudes":[1.0,1.0,2.0,2.0,2.0,1.0,1.0,1.0,1.0]},"continentalness_large":{"first_octave":-11,"amplitudes":[1.0,1.0,2.0,2.0,2.0,1.0,1.0,1.0,1.0]},"erosion":{"first_octave":-9,"amplitudes":[1.0,1.0,0.0,1.0,1.0]},"erosion_large":{"first_octave":-11,"amplitudes":[1.0,1.0,0.0,1.0,1.0]},"gravel":{"first_octave":-8,"amplitudes":[1.0,1.0,1.0,1.0]},"gravel_layer":{"first_octave":-8,"amplitudes":[1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.013333333333333334]},"ice":{"first_octave":-4,"amplitudes":[1.0,1.0,1.0,1.0]},"iceberg_pillar":{"first_octave":-6,"amplitudes":[1.0,1.0,1.0,1.0]},"iceberg_pillar_roof":{"first_octave":-3,"amplitudes":[1.0]},"iceberg_surface":{"first_octave":-6,"amplitudes":[1.0,1.0,1.0]},"jagged":{"first_octave":-16,"amplitudes":[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0]},"nether_state_selector":{"first_octave":-4,"amplitudes":[1.0]},"nether_wart":{"first_octave":-3,"amplitudes":[1.0,0.0,0.0,0.9]},"netherrack":{"first_octave":-3,"amplitudes":[1.0,0.0,0.0,0.35]},"noodle":{"first_octave":-8,"amplitudes":[1.0]},"noodle_ridge_a":{"first_octave":-7,"amplitudes":[1.0]},"noodle_ridge_b":{"first_octave":-7,"amplitudes":[1.0]},"noodle_thickness":{"first_octave":-8,"amplitudes":[1.0]},"offset":{"first_octave":-3,"amplitudes":[1.0,1.0,1.0,0.0]},"ore_gap":{"first_octave":-5,"amplitudes":[1.0]},"ore_vein_a":{"first_octave":-7,"amplitudes":[1.0]},"ore_vein_b":{"first_octave":-7,"amplitudes":[1.0]},"ore_veininess":{"first_octave":-8,"amplitudes":[1.0]},"packed_ice":{"first_octave":-7,"amplitudes":[1.0,1.0,1.0,1.0]},"patch":{"first_octave":-5,"amplitudes":[1.0,0.0,0.0,0.0,0.0,0.013333333333333334]},"pillar":{"first_octave":-7,"amplitudes":[1.0,1.0]},"pillar_rareness":{"first_octave":-8,"amplitudes":[1.0]},"pillar_thickness":{"first_octave":-8,"amplitudes":[1.0]},"powder_snow":{"first_octave":-6,"amplitudes":[1.0,1.0,1.0,1.0]},"ridge":{"first_octave":-7,"amplitudes":[1.0,2.0,1.0,0.0,0.0,0.0]},"soul_sand_layer":{"first_octave":-8,"amplitudes":[1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.013333333333333334]},"spaghetti_2d":{"first_octave":-7,"amplitudes":[1.0]},"spaghetti_2d_elevation":{"first_octave":-8,"amplitudes":[1.0]},"spaghetti_2d_modulator":{"first_octave":-11,"amplitudes":[1.0]},"spaghetti_2d_thickness":{"first_octave":-11,"amplitudes":[1.0]},"spaghetti_3d_1":{"first_octave":-7,"amplitudes":[1.0]},"spaghetti_3d_2":{"first_octave":-7,"amplitudes":[1.0]},"spaghetti_3d_rarity":{"first_octave":-11,"amplitudes":[1.0]},"spaghetti_3d_thickness":{"first_octave":-8,"amplitudes":[1.0]},"spaghetti_roughness":{"first_octave":-5,"amplitudes":[1.0]},"spaghetti_roughness_modulator":{"first_octave":-8,"amplitudes":[1.0]},"surface":{"first_octave":-6,"amplitudes":[1.0,1.0,1.0]},"surface_secondary":{"first_octave":-6,"amplitudes":[1.0,1.0,0.0,1.0]},"surface_swamp":{"first_octave":-2,"amplitudes":[1.0]},"temperature":{"first_octave":-10,"amplitudes":[1.5,0.0,1.0,0.0,0.0,0.0]},"temperature_large":{"first_octave":-12,"amplitudes":[1.5,0.0,1.0,0.0,0.0,0.0]},"vegetation":{"first_octave":-8,"amplitudes":[1.0,1.0,0.0,0.0,0.0,0.0]},"vegetation_large":{"first_octave":-10,"amplitudes":[1.0,1.0,0.0,0.0,0.0,0.0]}}
2 changes: 1 addition & 1 deletion pumpkin-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version.workspace = true
edition.workspace = true

[dependencies]
pumpkin-core = { path = "../pumpkin-core" }
pumpkin-util = { path = "../pumpkin-util" }
serde.workspace = true
log.workspace = true
uuid.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-config/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pumpkin_core::PermissionLvl;
use pumpkin_util::PermissionLvl;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
Expand Down
6 changes: 3 additions & 3 deletions pumpkin-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use log::warn;
use logging::LoggingConfig;
use pumpkin_core::{Difficulty, GameMode, PermissionLvl};
use pumpkin_util::{Difficulty, GameMode, PermissionLvl};
use serde::{de::DeserializeOwned, Deserialize, Serialize};

use std::{
Expand Down Expand Up @@ -137,7 +137,7 @@ trait LoadConfiguration {

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",
"Couldn't parse config at {:?}. Reason: {}. This is is probably caused by an Config update, Just delete the old Config and start Pumpkin again",
&path,
err.message()
)
Expand All @@ -147,7 +147,7 @@ trait LoadConfiguration {

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",
"Couldn't write default config to {:?}. Reason: {}. This is is probably caused by an Config update, Just delete the old Config and start Pumpkin again",
&path, err
);
}
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-config/src/networking/auth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pumpkin_core::ProfileAction;
use pumpkin_util::ProfileAction;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-config/src/op.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pumpkin_core::permission::PermissionLvl;
use pumpkin_util::permission::PermissionLvl;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

Expand Down
17 changes: 17 additions & 0 deletions pumpkin-data/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "pumpkin-data"
version.workspace = true
edition.workspace = true
build = "build/build.rs"

[dependencies]
serde.workspace = true

[build-dependencies]
serde.workspace = true
serde_json.workspace = true

heck = "0.5.0"
proc-macro2 = "1.0"
quote = "1.0"
syn = "2.0"
39 changes: 39 additions & 0 deletions pumpkin-data/build/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use std::{env, fs, path::Path, process::Command};

use proc_macro2::{Span, TokenStream};
use syn::Ident;

mod chunk_status;
mod packet;
mod particle;
mod screen;
mod sound;

pub fn main() {
write_generated_file(packet::build(), "packet.rs");
write_generated_file(screen::build(), "screen.rs");
write_generated_file(particle::build(), "particle.rs");
write_generated_file(sound::build(), "sound.rs");
write_generated_file(chunk_status::build(), "chunk_status.rs");
}

pub fn write_generated_file(content: TokenStream, out_file: &str) {
let out_dir = env::var_os("OUT_DIR").expect("failed to get OUT_DIR env var");
let path = Path::new(&out_dir).join(out_file);
let code = content.to_string();

fs::write(&path, code).expect("Faile to write to fs");

// Try to format the output for debugging purposes.
// Doesn't matter if rustfmt is unavailable.
let _ = Command::new("rustfmt").arg(path).output();
}

pub fn ident<I: AsRef<str>>(s: I) -> Ident {
let s = s.as_ref().trim();

// Parse the ident from a str. If the string is a Rust keyword, stick an
// underscore in front.
syn::parse_str::<Ident>(s)
.unwrap_or_else(|_| Ident::new(format!("_{s}").as_str(), Span::call_site()))
}
31 changes: 31 additions & 0 deletions pumpkin-data/build/chunk_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use heck::ToPascalCase;
use proc_macro2::TokenStream;
use quote::quote;

use crate::ident;

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

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

for status in chunk_status.iter() {
let full_name = format!("minecraft:{status}");
let name = ident(status.to_pascal_case());
variants.extend([quote! {
#[serde(rename = #full_name)]
#name,
}]);
}
quote! {
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub enum ChunkStatus {
#variants
}
}
}
50 changes: 50 additions & 0 deletions pumpkin-data/build/packet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use std::collections::HashMap;

use proc_macro2::TokenStream;
use quote::quote;
use serde::Deserialize;

use crate::ident;

#[derive(Deserialize)]
pub struct Packets {
serverbound: HashMap<String, Vec<String>>,
clientbound: HashMap<String, Vec<String>>,
}

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

let packets: Packets = serde_json::from_str(include_str!("../../assets/packets.json"))
.expect("Failed to parse packets.json");
let serverbound_consts = parse_packets(packets.serverbound);
let clientbound_consts = parse_packets(packets.clientbound);

quote!(
pub mod serverbound {
#serverbound_consts
}

pub mod clientbound {
#clientbound_consts
}
)
}

pub(crate) fn parse_packets(packets: HashMap<String, Vec<String>>) -> proc_macro2::TokenStream {
let mut consts = TokenStream::new();

for packet in packets {
let phase = packet.0;

for (id, packet_name) in packet.1.iter().enumerate() {
let packet_id = id as i32;
let name = format!("{phase}_{packet_name}").to_uppercase();
let name = ident(name);
consts.extend([quote! {
pub const #name: i32 = #packet_id;
}]);
}
}
consts
}
29 changes: 29 additions & 0 deletions pumpkin-data/build/particle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use heck::ToPascalCase;
use proc_macro2::TokenStream;
use quote::quote;

use crate::ident;

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

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

for (id, particle) in particle.iter().enumerate() {
let id = id as u8;
let name = ident(particle.to_pascal_case());

variants.extend([quote! {
#name = #id,
}]);
}
quote! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u8)]
pub enum Particle {
#variants
}
}
}
29 changes: 29 additions & 0 deletions pumpkin-data/build/screen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use heck::ToPascalCase;
use proc_macro2::TokenStream;
use quote::quote;

use crate::ident;

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

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

for (id, screen) in screens.iter().enumerate() {
let id = id as u8;
let name = ident(screen.to_pascal_case());

variants.extend([quote! {
#name = #id,
}]);
}
quote! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u8)]
pub enum WindowType {
#variants
}
}
}
29 changes: 29 additions & 0 deletions pumpkin-data/build/sound.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use heck::ToPascalCase;
use proc_macro2::TokenStream;
use quote::quote;

use crate::ident;

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

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

for (id, sound) in sound.iter().enumerate() {
let id = id as u16;
let name = ident(sound.to_pascal_case());

variants.extend([quote! {
#name = #id,
}]);
}
quote! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u16)]
pub enum Sound {
#variants
}
}
}
19 changes: 19 additions & 0 deletions pumpkin-data/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pub mod packet {
include!(concat!(env!("OUT_DIR"), "/packet.rs"));
}

pub mod screen {
include!(concat!(env!("OUT_DIR"), "/screen.rs"));
}

pub mod particle {
include!(concat!(env!("OUT_DIR"), "/particle.rs"));
}

pub mod sound {
include!(concat!(env!("OUT_DIR"), "/sound.rs"));
}

pub mod chunk_status {
include!(concat!(env!("OUT_DIR"), "/chunk_status.rs"));
}
4 changes: 2 additions & 2 deletions pumpkin-inventory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ edition.workspace = true

[dependencies]
pumpkin-protocol = { path = "../pumpkin-protocol" }
pumpkin-data = { path = "../pumpkin-data" }

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

log.workspace = true
rayon.workspace = true
Expand Down
Loading

0 comments on commit 788ea0c

Please sign in to comment.