remove: pumpkin-registry
it is gone for good, i made the new registry be parsed from compile time in pumpkin-nbt and even parse the nbt code at compile time as well, And like expected this gives a massive speedup in first time parsing and also decreased bin size
This commit is contained in:
parent
db486d5572
commit
ff1f3a0fbd
69
Cargo.lock
generated
69
Cargo.lock
generated
@ -379,9 +379,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.7.6"
|
||||
version = "0.7.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
||||
checksum = "c3e64b0cc0439b12df2fa678eae89a1c56a529fd067a9115f7827f1fffd22b32"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
@ -1522,9 +1522,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.83"
|
||||
version = "0.3.85"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8"
|
||||
checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"wasm-bindgen",
|
||||
@ -2110,7 +2110,6 @@ dependencies = [
|
||||
"pumpkin-macros",
|
||||
"pumpkin-nbt",
|
||||
"pumpkin-protocol",
|
||||
"pumpkin-registry",
|
||||
"pumpkin-util",
|
||||
"pumpkin-world",
|
||||
"rand",
|
||||
@ -2159,6 +2158,7 @@ version = "0.1.0-dev+1.21.11"
|
||||
dependencies = [
|
||||
"crc-fast",
|
||||
"heck",
|
||||
"indexmap",
|
||||
"phf",
|
||||
"proc-macro2",
|
||||
"pumpkin-nbt",
|
||||
@ -2229,17 +2229,6 @@ dependencies = [
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pumpkin-registry"
|
||||
version = "0.1.0-dev+1.21.11"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"pumpkin-protocol",
|
||||
"pumpkin-util",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pumpkin-util"
|
||||
version = "0.1.0-dev+1.21.11"
|
||||
@ -2323,7 +2312,7 @@ checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.10.0-rc.6"
|
||||
source = "git+https://github.com/rust-random/rand#da2211b80e7217403b2bd8305a98ae7bc61c1146"
|
||||
source = "git+https://github.com/rust-random/rand#f356bbae5817f382b19ac5741b549c4d2cd49b50"
|
||||
dependencies = [
|
||||
"chacha20",
|
||||
"getrandom 0.4.0-rc.0",
|
||||
@ -2948,9 +2937,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.44"
|
||||
version = "0.3.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d"
|
||||
checksum = "f9e442fc33d7fdb45aa9bfeb312c095964abdf596f7567261062b2a7107aaabd"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"itoa",
|
||||
@ -2958,22 +2947,22 @@ dependencies = [
|
||||
"num-conv",
|
||||
"num_threads",
|
||||
"powerfmt",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"time-core",
|
||||
"time-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.6"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b"
|
||||
checksum = "8b36ee98fd31ec7426d599183e8fe26932a8dc1fb76ddb6214d05493377d34ca"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.24"
|
||||
version = "0.2.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3"
|
||||
checksum = "71e552d1249bf61ac2a52db88179fd0673def1e1ad8243a00d9ec9ed71fee3dd"
|
||||
dependencies = [
|
||||
"num-conv",
|
||||
"time-core",
|
||||
@ -3133,9 +3122,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tower"
|
||||
version = "0.5.2"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9"
|
||||
checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
@ -3377,18 +3366,18 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
||||
|
||||
[[package]]
|
||||
name = "wasip2"
|
||||
version = "1.0.1+wasi-0.2.4"
|
||||
version = "1.0.2+wasi-0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7"
|
||||
checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5"
|
||||
dependencies = [
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.106"
|
||||
version = "0.2.108"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd"
|
||||
checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@ -3399,9 +3388,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.106"
|
||||
version = "0.2.108"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3"
|
||||
checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@ -3409,9 +3398,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.106"
|
||||
version = "0.2.108"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40"
|
||||
checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
@ -3422,9 +3411,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.106"
|
||||
version = "0.2.108"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4"
|
||||
checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
@ -3648,9 +3637,9 @@ checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.46.0"
|
||||
version = "0.51.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
|
||||
checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"
|
||||
|
||||
[[package]]
|
||||
name = "writeable"
|
||||
@ -3763,6 +3752,6 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.13"
|
||||
version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac93432f5b761b22864c774aac244fa5c0fd877678a4c37ebf6cf42208f9c9ec"
|
||||
checksum = "bd8f3f50b848df28f887acb68e41201b5aea6bc8a8dacc00fb40635ff9a72fea"
|
||||
|
||||
@ -7,7 +7,6 @@ members = [
|
||||
"pumpkin-inventory",
|
||||
"pumpkin-macros/",
|
||||
"pumpkin-protocol/",
|
||||
"pumpkin-registry/",
|
||||
"pumpkin-world",
|
||||
"pumpkin/",
|
||||
"pumpkin-data",
|
||||
@ -88,7 +87,6 @@ pumpkin-inventory = { path = "pumpkin-inventory" }
|
||||
pumpkin-macros = { path = "pumpkin-macros" }
|
||||
pumpkin-nbt = { path = "pumpkin-nbt" }
|
||||
pumpkin-protocol = { path = "pumpkin-protocol" }
|
||||
pumpkin-registry = { path = "pumpkin-registry" }
|
||||
pumpkin-util = { path = "pumpkin-util" }
|
||||
pumpkin-world = { path = "pumpkin-world" }
|
||||
quote = "1.0"
|
||||
|
||||
@ -56,7 +56,6 @@
|
||||
./pumpkin-macros
|
||||
./pumpkin-nbt
|
||||
./pumpkin-protocol
|
||||
./pumpkin-registry
|
||||
./pumpkin-util
|
||||
./pumpkin-world
|
||||
];
|
||||
|
||||
@ -13,6 +13,8 @@ serde.workspace = true
|
||||
crc-fast.workspace = true
|
||||
|
||||
[build-dependencies]
|
||||
indexmap = { workspace = true, features = ["serde"] }
|
||||
|
||||
pumpkin-util.workspace = true
|
||||
pumpkin-nbt.workspace = true
|
||||
|
||||
|
||||
@ -39,6 +39,7 @@ mod potion;
|
||||
mod potion_brewing;
|
||||
mod recipe_remainder;
|
||||
mod recipes;
|
||||
mod registry;
|
||||
mod scoreboard_slot;
|
||||
mod screen;
|
||||
mod sound;
|
||||
@ -67,6 +68,7 @@ pub fn main() {
|
||||
(chunk_status::build, "chunk_status.rs"),
|
||||
(game_event::build, "game_event.rs"),
|
||||
(game_rules::build, "game_rules.rs"),
|
||||
(registry::build, "registry.rs"),
|
||||
(dimension::build, "dimension.rs"),
|
||||
(sound_category::build, "sound_category.rs"),
|
||||
(entity_pose::build, "entity_pose.rs"),
|
||||
|
||||
149
pumpkin-data/build/registry.rs
Normal file
149
pumpkin-data/build/registry.rs
Normal file
@ -0,0 +1,149 @@
|
||||
use indexmap::IndexMap;
|
||||
use proc_macro2::{Literal, TokenStream};
|
||||
use quote::quote;
|
||||
use serde_json::Value;
|
||||
use std::fs;
|
||||
|
||||
pub(crate) fn build() -> TokenStream {
|
||||
println!("cargo:rerun-if-changed=../assets/synced_registries.json");
|
||||
|
||||
let json_str = fs::read_to_string("../assets/synced_registries.json")
|
||||
.expect("Failed to read synced_registries.json");
|
||||
let mut data: IndexMap<String, IndexMap<String, Value>> =
|
||||
serde_json::from_str(&json_str).expect("Failed to parse synced_registries.json");
|
||||
|
||||
let chat_type = if data.contains_key("minecraft:chat_type") {
|
||||
data.get_mut("minecraft:chat_type")
|
||||
} else {
|
||||
data.get_mut("chat_type")
|
||||
};
|
||||
|
||||
if let Some(chat_type) = chat_type {
|
||||
chat_type.insert(
|
||||
"raw".to_string(),
|
||||
serde_json::json!({
|
||||
"chat": {
|
||||
"translation_key": "%s",
|
||||
"parameters": ["content"],
|
||||
"style": null
|
||||
},
|
||||
"narration": {
|
||||
"translation_key": "%s says %s",
|
||||
"parameters": ["sender", "content"],
|
||||
"style": null
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
let registries_tokens = data.iter().map(|(reg_name, entries)| {
|
||||
let entry_tokens = entries.iter().map(|(entry_name, entry_data)| {
|
||||
let mut nbt_bytes = Vec::new();
|
||||
pumpkin_nbt::serializer::to_bytes_unnamed(entry_data, &mut nbt_bytes)
|
||||
.expect("Failed to serialize NBT at build time");
|
||||
|
||||
let nbt_literal = Literal::byte_string(&nbt_bytes);
|
||||
|
||||
quote! {
|
||||
StaticRegistryEntry {
|
||||
name: #entry_name,
|
||||
nbt_bytes: #nbt_literal,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
quote! {
|
||||
StaticRegistry {
|
||||
registry_id: #reg_name,
|
||||
entries: &[#(#entry_tokens),*],
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let jukebox_entries = data
|
||||
.get("minecraft:jukebox_song")
|
||||
.or_else(|| data.get("jukebox_song"));
|
||||
|
||||
let jukebox_index_arms = jukebox_entries
|
||||
.map(|entries| {
|
||||
entries
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, (name, _))| {
|
||||
quote! { #name => Some(#index), }
|
||||
})
|
||||
.collect::<TokenStream>()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
quote! {
|
||||
use pumpkin_util::resource_location::ResourceLocation;
|
||||
|
||||
pub struct StaticRegistryEntry {
|
||||
pub name: &'static str,
|
||||
pub nbt_bytes: &'static [u8],
|
||||
}
|
||||
|
||||
pub struct StaticRegistry {
|
||||
pub registry_id: &'static str,
|
||||
pub entries: &'static [StaticRegistryEntry],
|
||||
}
|
||||
|
||||
pub static SYNCED_REGISTRIES: &[StaticRegistry] = &[
|
||||
#(#registries_tokens),*
|
||||
];
|
||||
|
||||
pub struct RegistryEntryData {
|
||||
pub entry_id: ResourceLocation,
|
||||
pub data: Option<Box<[u8]>>,
|
||||
}
|
||||
|
||||
pub struct Registry {
|
||||
pub registry_id: ResourceLocation,
|
||||
pub registry_entries: Vec<RegistryEntryData>,
|
||||
}
|
||||
|
||||
pub struct SyncedRegistry;
|
||||
|
||||
impl SyncedRegistry {
|
||||
pub fn get_jukebox_song_index(song_key: &str) -> Option<usize> {
|
||||
match song_key {
|
||||
#jukebox_index_arms
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Registry {
|
||||
pub fn get_synced() -> Vec<Self> {
|
||||
SYNCED_REGISTRIES.iter().map(|static_reg| {
|
||||
let registry_id = if static_reg.registry_id.contains(':') {
|
||||
ResourceLocation::from(static_reg.registry_id)
|
||||
} else {
|
||||
ResourceLocation::vanilla(static_reg.registry_id)
|
||||
};
|
||||
|
||||
let registry_entries = static_reg.entries.iter().map(|entry| {
|
||||
let entry_id = if entry.name.contains(':') {
|
||||
ResourceLocation::from(entry.name)
|
||||
} else {
|
||||
ResourceLocation::vanilla(entry.name)
|
||||
};
|
||||
|
||||
let data = Some(entry.nbt_bytes.to_vec().into_boxed_slice());
|
||||
|
||||
RegistryEntryData {
|
||||
entry_id,
|
||||
data,
|
||||
}
|
||||
}).collect();
|
||||
|
||||
Self {
|
||||
registry_id,
|
||||
registry_entries,
|
||||
}
|
||||
}).collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,10 @@ pub mod item;
|
||||
#[path = "generated/packet.rs"]
|
||||
pub mod packet;
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[path = "generated/registry.rs"]
|
||||
pub mod registry;
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[path = "generated/screen.rs"]
|
||||
pub mod screen;
|
||||
|
||||
@ -29,6 +29,10 @@ pub struct RegistryEntry {
|
||||
|
||||
// TODO: No unwraps
|
||||
impl RegistryEntry {
|
||||
pub fn new(entry_id: ResourceLocation, data: Option<Box<[u8]>>) -> Self {
|
||||
Self { entry_id, data }
|
||||
}
|
||||
|
||||
pub fn from_nbt(name: &str, nbt: &impl Serialize) -> Self {
|
||||
let mut data_buf = Vec::new();
|
||||
pumpkin_nbt::serializer::to_bytes_unnamed(nbt, &mut data_buf).unwrap();
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
[package]
|
||||
name = "pumpkin-registry"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[dependencies]
|
||||
pumpkin-protocol.workspace = true
|
||||
pumpkin-util.workspace = true
|
||||
|
||||
indexmap = { workspace = true, features = ["serde"] }
|
||||
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
@ -1,8 +0,0 @@
|
||||
use pumpkin_util::resource_location::ResourceLocation;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct BannerPattern {
|
||||
asset_id: ResourceLocation,
|
||||
translation_key: String,
|
||||
}
|
||||
@ -1,70 +0,0 @@
|
||||
use pumpkin_protocol::codec::var_int::VarInt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Biome {
|
||||
has_precipitation: bool,
|
||||
temperature: f32,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
temperature_modifier: Option<String>,
|
||||
downfall: f32,
|
||||
effects: BiomeEffects,
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct BiomeEffects {
|
||||
fog_color: i32,
|
||||
water_color: i32,
|
||||
water_fog_color: i32,
|
||||
sky_color: i32,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
foliage_color: Option<i32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
grass_color: Option<i32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
grass_color_modifier: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
particle: Option<Particle>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
ambient_sound: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
mood_sound: Option<MoodSound>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
additions_sound: Option<AdditionsSound>,
|
||||
// #[serde(skip_serializing_if = "Option::is_none")]
|
||||
// music: Option<Vec<DataPool<Music>>>,
|
||||
music_volume: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct Particle {
|
||||
options: ParticleOptions,
|
||||
probability: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct ParticleOptions {
|
||||
r#type: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
value: Option<VarInt>,
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct MoodSound {
|
||||
sound: String,
|
||||
tick_delay: i32,
|
||||
block_search_extent: i32,
|
||||
offset: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct AdditionsSound {
|
||||
sound: String,
|
||||
tick_chance: f64,
|
||||
}
|
||||
|
||||
// #[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
// struct Music {
|
||||
// sound: String,
|
||||
// min_delay: i32,
|
||||
// max_delay: i32,
|
||||
// replace_current_music: bool,
|
||||
// }
|
||||
@ -1,6 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct CatVariant {
|
||||
asset_id: String,
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
use pumpkin_util::text::style::Style;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ChatType {
|
||||
pub chat: Decoration,
|
||||
pub narration: Decoration,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Decoration {
|
||||
pub translation_key: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub style: Option<Style>,
|
||||
pub parameters: Vec<String>,
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ChickenVariant {
|
||||
asset_id: String,
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct CowVariant {
|
||||
asset_id: String,
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DamageType {
|
||||
exhaustion: f32,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
death_message_type: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
effects: Option<String>,
|
||||
message_id: String,
|
||||
scaling: String,
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Enchantment {
|
||||
// TODO: Add things :D
|
||||
description: Description,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Description {
|
||||
translate: String,
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct FrogVariant {
|
||||
asset_id: String,
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Instrument {
|
||||
sound_event: String,
|
||||
use_duration: f32,
|
||||
range: f32,
|
||||
// description: TextComponent<'static>,
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct JukeboxSong {
|
||||
sound_event: String,
|
||||
description: Description,
|
||||
length_in_seconds: f32,
|
||||
comparator_output: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct Description {
|
||||
translate: String,
|
||||
}
|
||||
@ -1,108 +0,0 @@
|
||||
use std::sync::LazyLock;
|
||||
|
||||
mod jukebox_song;
|
||||
|
||||
use indexmap::IndexMap;
|
||||
use pumpkin_protocol::java::client::config::RegistryEntry;
|
||||
use pumpkin_util::include_json_static;
|
||||
use pumpkin_util::resource_location::ResourceLocation;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::jukebox_song::JukeboxSong;
|
||||
|
||||
pub static SYNCED_REGISTRIES: LazyLock<SyncedRegistry> =
|
||||
LazyLock::new(|| include_json_static!("../../assets/synced_registries.json", SyncedRegistry));
|
||||
|
||||
pub struct Registry {
|
||||
pub registry_id: ResourceLocation,
|
||||
pub registry_entries: Vec<RegistryEntry>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct SyncedRegistry {
|
||||
#[serde(flatten)]
|
||||
pub registries: IndexMap<String, IndexMap<String, Value>>,
|
||||
}
|
||||
|
||||
// Probably not optimal
|
||||
impl SyncedRegistry {
|
||||
pub fn get_jukebox_song(&self, song_key: &str) -> Option<JukeboxSong> {
|
||||
let jukebox_registry = self
|
||||
.registries
|
||||
.get("minecraft:jukebox_song")
|
||||
.or_else(|| self.registries.get("jukebox_song"))?;
|
||||
let song_value = jukebox_registry.get(song_key)?;
|
||||
|
||||
serde_json::from_value(song_value.clone()).ok()
|
||||
}
|
||||
|
||||
pub fn get_jukebox_song_index(&self, song_key: &str) -> Option<usize> {
|
||||
let jukebox_registry = self
|
||||
.registries
|
||||
.get("minecraft:jukebox_song")
|
||||
.or_else(|| self.registries.get("jukebox_song"))?;
|
||||
jukebox_registry.get_index_of(song_key)
|
||||
}
|
||||
}
|
||||
|
||||
impl Registry {
|
||||
pub fn get_synced() -> Vec<Self> {
|
||||
let mut synced_registries = Vec::new();
|
||||
|
||||
for (registry_key, entries) in &SYNCED_REGISTRIES.registries {
|
||||
let registry_id = if registry_key.contains(':') {
|
||||
ResourceLocation::from(registry_key)
|
||||
} else {
|
||||
ResourceLocation::vanilla(registry_key)
|
||||
};
|
||||
|
||||
let mut registry_entries: Vec<RegistryEntry> = entries
|
||||
.iter()
|
||||
.map(|(entry_name, entry_data)| RegistryEntry::from_nbt(entry_name, entry_data))
|
||||
.collect();
|
||||
|
||||
// 3. Special Handling: Chat Type "raw" injection
|
||||
// We check if this specific loop iteration is for "chat_type"
|
||||
if registry_id.path == "chat_type" {
|
||||
registry_entries.push(RegistryEntry::from_nbt_custom(
|
||||
"raw",
|
||||
&Self::get_raw_chat_type_struct(),
|
||||
));
|
||||
}
|
||||
|
||||
synced_registries.push(Registry {
|
||||
registry_id,
|
||||
registry_entries,
|
||||
});
|
||||
}
|
||||
|
||||
// let jukebox_entries = SYNCED_REGISTRIES
|
||||
// .jukebox_song
|
||||
// .keys()
|
||||
// .map(|name| RegistryEntry::none(name))
|
||||
// .collect();
|
||||
|
||||
// synced_registries.push(Registry {
|
||||
// registry_id: ResourceLocation::vanilla("jukebox_song"),
|
||||
// registry_entries: jukebox_entries,
|
||||
// });
|
||||
|
||||
synced_registries
|
||||
}
|
||||
|
||||
fn get_raw_chat_type_struct() -> impl Serialize {
|
||||
serde_json::json!({
|
||||
"chat": {
|
||||
"translation_key": "%s",
|
||||
"parameters": ["content"],
|
||||
"style": null
|
||||
},
|
||||
"narration": {
|
||||
"translation_key": "%s says %s",
|
||||
"parameters": ["sender", "content"],
|
||||
"style": null
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
use pumpkin_util::resource_location::ResourceLocation;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Painting {
|
||||
asset_id: ResourceLocation,
|
||||
// #[serde(skip_serializing_if = "Option::is_none")]
|
||||
// title: Option<TextComponent<'static>>,
|
||||
// #[serde(skip_serializing_if = "Option::is_none")]
|
||||
// author: Option<TextComponent<'static>>,
|
||||
height: i32,
|
||||
width: i32,
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct PigVariant {
|
||||
asset_id: String,
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TrimMaterial {
|
||||
asset_name: String,
|
||||
// description: TextComponent<'static>,
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
use pumpkin_util::resource_location::ResourceLocation;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TrimPattern {
|
||||
asset_id: ResourceLocation,
|
||||
// description: TextComponent<'static>,
|
||||
decal: bool,
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WolfVariant {
|
||||
assets: WolfAssetInfo,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WolfAssetInfo {
|
||||
wild: String,
|
||||
tame: String,
|
||||
angry: String,
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WolfSoundVariant {
|
||||
hurt_sound: String,
|
||||
pant_sound: String,
|
||||
whine_sound: String,
|
||||
ambient_sound: String,
|
||||
death_sound: String,
|
||||
growl_sound: String,
|
||||
}
|
||||
@ -24,7 +24,6 @@ pumpkin-inventory.workspace = true
|
||||
pumpkin-world.workspace = true
|
||||
pumpkin-data.workspace = true
|
||||
pumpkin-protocol.workspace = true
|
||||
pumpkin-registry.workspace = true
|
||||
pumpkin-macros.workspace = true
|
||||
|
||||
log.workspace = true
|
||||
|
||||
@ -4,13 +4,13 @@ use crate::block::registry::BlockActionResult;
|
||||
use crate::block::{BlockBehaviour, BlockFuture, BrokenArgs, UseWithItemArgs};
|
||||
use crate::world::World;
|
||||
use pumpkin_data::data_component_impl::JukeboxPlayableImpl;
|
||||
use pumpkin_data::registry::SyncedRegistry;
|
||||
use pumpkin_data::world::WorldEvent;
|
||||
use pumpkin_data::{
|
||||
Block,
|
||||
block_properties::{BlockProperties, JukeboxLikeProperties},
|
||||
};
|
||||
use pumpkin_macros::pumpkin_block;
|
||||
use pumpkin_registry::SYNCED_REGISTRIES;
|
||||
use pumpkin_util::math::position::BlockPos;
|
||||
use pumpkin_world::world::BlockFlags;
|
||||
|
||||
@ -73,7 +73,7 @@ impl BlockBehaviour for JukeboxBlock {
|
||||
return BlockActionResult::Pass;
|
||||
};
|
||||
|
||||
let Some(jukebox_song) = SYNCED_REGISTRIES.get_jukebox_song_index(song) else {
|
||||
let Some(jukebox_song) = SyncedRegistry::get_jukebox_song_index(song) else {
|
||||
log::error!("Jukebox playable song not registered!");
|
||||
return BlockActionResult::Pass;
|
||||
};
|
||||
|
||||
@ -9,7 +9,7 @@ use core::str;
|
||||
use pumpkin_protocol::{
|
||||
ConnectionState,
|
||||
java::{
|
||||
client::config::{CFinishConfig, CRegistryData, CUpdateTags},
|
||||
client::config::{CFinishConfig, CRegistryData, CUpdateTags, RegistryEntry},
|
||||
server::config::{
|
||||
ResourcePackResponseResult, SClientInformationConfig, SConfigCookieResponse,
|
||||
SConfigResourcePack, SKnownPacks, SPluginMessage,
|
||||
@ -152,10 +152,12 @@ impl JavaClient {
|
||||
pub async fn handle_known_packs(&self, server: &Server, _config_acknowledged: SKnownPacks) {
|
||||
log::debug!("Handling known packs");
|
||||
for registry in &server.cached_registry {
|
||||
self.send_packet_now(&CRegistryData::new(
|
||||
®istry.registry_id,
|
||||
®istry.registry_entries,
|
||||
))
|
||||
let entries: Vec<RegistryEntry> = registry
|
||||
.registry_entries
|
||||
.iter()
|
||||
.map(|r| RegistryEntry::new(r.entry_id.clone(), r.data.clone()))
|
||||
.collect();
|
||||
self.send_packet_now(&CRegistryData::new(®istry.registry_id, &entries))
|
||||
.await;
|
||||
}
|
||||
self.send_packet_now(&CUpdateTags::new(&[
|
||||
|
||||
@ -14,6 +14,7 @@ use connection_cache::{CachedBranding, CachedStatus};
|
||||
use key_store::KeyStore;
|
||||
use pumpkin_config::{AdvancedConfiguration, BasicConfiguration};
|
||||
use pumpkin_data::dimension::Dimension;
|
||||
use pumpkin_data::registry::Registry;
|
||||
use pumpkin_world::dimension::into_level;
|
||||
|
||||
use crate::command::CommandSender;
|
||||
@ -21,7 +22,6 @@ use pumpkin_macros::send_cancellable;
|
||||
use pumpkin_protocol::java::client::login::CEncryptionRequest;
|
||||
use pumpkin_protocol::java::client::play::CChangeDifficulty;
|
||||
use pumpkin_protocol::{ClientPacket, java::client::config::CPluginMessage};
|
||||
use pumpkin_registry::Registry;
|
||||
use pumpkin_util::Difficulty;
|
||||
use pumpkin_util::math::vector3::Vector3;
|
||||
use pumpkin_util::text::TextComponent;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user