mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
parse Biome enum at compile time
This commit is contained in:
1
assets/biome.json
Normal file
1
assets/biome.json
Normal file
@@ -0,0 +1 @@
|
||||
["badlands","bamboo_jungle","basalt_deltas","beach","birch_forest","cherry_grove","cold_ocean","crimson_forest","dark_forest","deep_cold_ocean","deep_dark","deep_frozen_ocean","deep_lukewarm_ocean","deep_ocean","desert","dripstone_caves","end_barrens","end_highlands","end_midlands","eroded_badlands","flower_forest","forest","frozen_ocean","frozen_peaks","frozen_river","grove","ice_spikes","jagged_peaks","jungle","lukewarm_ocean","lush_caves","mangrove_swamp","meadow","mushroom_fields","nether_wastes","ocean","old_growth_birch_forest","old_growth_pine_taiga","old_growth_spruce_taiga","pale_garden","plains","river","savanna","savanna_plateau","small_end_islands","snowy_beach","snowy_plains","snowy_slopes","snowy_taiga","soul_sand_valley","sparse_jungle","stony_peaks","stony_shore","sunflower_plains","swamp","taiga","the_end","the_void","warm_ocean","warped_forest","windswept_forest","windswept_gravelly_hills","windswept_hills","windswept_savanna","wooded_badlands"]
|
||||
20
pumpkin-data/build/biome.rs
Normal file
20
pumpkin-data/build/biome.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
|
||||
use crate::array_to_tokenstream;
|
||||
|
||||
pub(crate) fn build() -> TokenStream {
|
||||
println!("cargo:rerun-if-changed=assets/biome.json");
|
||||
|
||||
let biomes: Vec<String> = serde_json::from_str(include_str!("../../assets/biome.json"))
|
||||
.expect("Failed to parse entity_pose.json");
|
||||
let variants = array_to_tokenstream(biomes);
|
||||
|
||||
quote! {
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(u8)]
|
||||
pub enum Biome {
|
||||
#variants
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ use heck::ToPascalCase;
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use syn::Ident;
|
||||
|
||||
mod biome;
|
||||
mod chunk_status;
|
||||
mod entity_pose;
|
||||
mod entity_type;
|
||||
@@ -31,6 +32,7 @@ pub fn main() {
|
||||
write_generated_file(world_event::build(), "world_event.rs");
|
||||
write_generated_file(entity_type::build(), "entity_type.rs");
|
||||
write_generated_file(noise_parmeter::build(), "noise_parmeter.rs");
|
||||
write_generated_file(biome::build(), "biome.rs");
|
||||
}
|
||||
|
||||
pub fn array_to_tokenstream(array: Vec<String>) -> TokenStream {
|
||||
|
||||
@@ -6,10 +6,9 @@ use crate::array_to_tokenstream;
|
||||
pub(crate) fn build() -> TokenStream {
|
||||
println!("cargo:rerun-if-changed=assets/entity_pose.json");
|
||||
|
||||
let sound_categories: Vec<String> =
|
||||
serde_json::from_str(include_str!("../../assets/entity_pose.json"))
|
||||
.expect("Failed to parse entity_pose.json");
|
||||
let variants = array_to_tokenstream(sound_categories);
|
||||
let poses: Vec<String> = serde_json::from_str(include_str!("../../assets/entity_pose.json"))
|
||||
.expect("Failed to parse entity_pose.json");
|
||||
let variants = array_to_tokenstream(poses);
|
||||
|
||||
quote! {
|
||||
#[derive(Clone, Copy)]
|
||||
|
||||
@@ -21,7 +21,7 @@ pub(crate) fn build() -> TokenStream {
|
||||
let mut variants = TokenStream::new();
|
||||
|
||||
for (name, paremter) in json.iter() {
|
||||
let raw_name = name;
|
||||
let raw_name = format!("minecraft:{name}");
|
||||
let name = ident(name.to_uppercase());
|
||||
let first_octave = paremter.first_octave;
|
||||
let amplitudes = &paremter.amplitudes;
|
||||
|
||||
@@ -16,6 +16,7 @@ pub mod sound {
|
||||
}
|
||||
|
||||
pub mod chunk {
|
||||
include!(concat!(env!("OUT_DIR"), "/biome.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/noise_parmeter.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/chunk_status.rs"));
|
||||
}
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// TODO make this work with the protocol
|
||||
// Send by the registry
|
||||
#[derive(Serialize, Deserialize, Clone, Copy)]
|
||||
#[non_exhaustive]
|
||||
pub enum Biome {
|
||||
Plains,
|
||||
SnowyTiga,
|
||||
// TODO list all Biomes
|
||||
}
|
||||
use pumpkin_data::chunk::Biome;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[enum_dispatch(BiomeSupplierImpl)]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use noise::Perlin;
|
||||
use pumpkin_data::chunk::Biome;
|
||||
use pumpkin_util::math::vector2::Vector2;
|
||||
use pumpkin_util::math::vector3::Vector3;
|
||||
|
||||
use crate::biome::Biome;
|
||||
use crate::block::block_state::BlockState;
|
||||
use crate::chunk::{ChunkData, Subchunks};
|
||||
use crate::coordinates::{BlockCoordinates, ChunkRelativeBlockCoordinates, XZBlockCoordinates};
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use noise::Perlin;
|
||||
use pumpkin_data::chunk::Biome;
|
||||
use pumpkin_macros::block_state;
|
||||
use pumpkin_util::math::vector2::Vector2;
|
||||
use rand::Rng;
|
||||
|
||||
use crate::{
|
||||
biome::Biome,
|
||||
chunk::Subchunks,
|
||||
coordinates::{BlockCoordinates, ChunkRelativeBlockCoordinates, XZBlockCoordinates},
|
||||
generation::{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use pumpkin_data::chunk::Biome;
|
||||
use pumpkin_util::math::vector2::Vector2;
|
||||
|
||||
use crate::{
|
||||
biome::Biome,
|
||||
block::block_state::BlockState,
|
||||
coordinates::XZBlockCoordinates,
|
||||
generation::{
|
||||
|
||||
@@ -5,10 +5,10 @@ use std::{
|
||||
|
||||
use dashmap::{DashMap, Entry};
|
||||
use num_traits::Zero;
|
||||
use pumpkin_data::chunk::Biome;
|
||||
use pumpkin_util::math::{vector2::Vector2, vector3::Vector3};
|
||||
|
||||
use crate::{
|
||||
biome::Biome,
|
||||
block::block_state::BlockState,
|
||||
chunk::{ChunkData, Subchunks},
|
||||
coordinates::{
|
||||
|
||||
Reference in New Issue
Block a user