Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions steel-registry/build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mod painting_variants;
mod pig_sound_variants;
mod pig_variants;
mod poi_types;
mod recipe_property_sets;
mod recipes;
mod sound_events;
mod sound_types;
Expand Down Expand Up @@ -106,6 +107,7 @@ const MENU_TYPES: &str = "menu_types";
const TIMELINES: &str = "timelines";
const TIMELINE_TAGS: &str = "timeline_tags";
const ZOMBIE_NAUTILUS_VARIANTS: &str = "zombie_nautilus_variants";
const RECIPE_PROPERTY_SETS: &str = "recipe_property_sets";
const RECIPES: &str = "recipes";
const VANILLA_ENTITIES: &str = "entities";
const ENTITY_DATA: &str = "entity_data";
Expand Down Expand Up @@ -176,6 +178,7 @@ pub fn main() {
(timelines::build(), TIMELINES),
(timeline_tags::build(), TIMELINE_TAGS),
(zombie_nautilus_variants::build(), ZOMBIE_NAUTILUS_VARIANTS),
(recipe_property_sets::build(), RECIPE_PROPERTY_SETS),
(recipes::build(), RECIPES),
(entities::build(), VANILLA_ENTITIES),
(entity_data::build(), ENTITY_DATA),
Expand Down
52 changes: 52 additions & 0 deletions steel-registry/build/recipe_property_sets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::{collections::BTreeMap, fs};

use heck::ToSnakeCase;
use proc_macro2::{Ident, Span, TokenStream};
use quote::quote;

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

let recipe_property_sets_json = fs::read_to_string("build_assets/recipe_property_sets.json")
.expect("Failed to read recipe_property_sets.json");
let recipe_property_sets_entries: BTreeMap<String, Vec<String>> =
serde_json::from_str(&recipe_property_sets_json)
.expect("Failed to parse recipe_property_sets.json");

let mut statics = TokenStream::new();
let mut registrations = TokenStream::new();

recipe_property_sets_entries
.iter()
.for_each(|(ident, list)| {
let key = Ident::new(&ident.to_snake_case().to_uppercase(), Span::call_site());
let items = list.iter().map(|it| {
let ident = Ident::new(
it.strip_prefix("minecraft:").unwrap_or(it),
Span::call_site(),
);
quote! { &ITEMS.#ident }
});

statics.extend(quote! {
pub static #key: RecipePropertySet = RecipePropertySet {
key: Identifier::vanilla_static(#ident),
items: OnceLock::new()
};
});
registrations
.extend(quote! { registry.register_with_items(&#key, vec![#(#items),*]); registry.register(&#key); });
});

quote! {
use steel_utils::Identifier;
use crate::{items::ItemRef, recipe::{RecipePropertySet, RecipePropertySetRegistry}, vanilla_items::ITEMS};
use std::sync::OnceLock;

#statics

pub fn register_recipe_property_sets(registry: &mut RecipePropertySetRegistry) {
#registrations
}
}
}
Loading
Loading