diff --git a/azalea-registry/azalea-registry-macros/src/lib.rs b/azalea-registry/azalea-registry-macros/src/lib.rs index d72f24cf..0dbeb494 100755 --- a/azalea-registry/azalea-registry-macros/src/lib.rs +++ b/azalea-registry/azalea-registry-macros/src/lib.rs @@ -5,7 +5,7 @@ use syn::{ parse::{Parse, ParseStream, Result}, parse_macro_input, punctuated::Punctuated, - Ident, LitStr, Token, + Attribute, Ident, LitStr, Token, }; struct RegistryItem { @@ -16,6 +16,7 @@ struct RegistryItem { struct Registry { name: Ident, items: Vec, + attributes: Vec, } impl Parse for RegistryItem { @@ -30,12 +31,16 @@ impl Parse for RegistryItem { impl Parse for Registry { fn parse(input: ParseStream) -> Result { - // Block, { + // enum Block { // Air => "minecraft:air", // Stone => "minecraft:stone" // } + + // this also includes docs + let attributes = input.call(Attribute::parse_outer).unwrap_or_default(); + + input.parse::()?; let name = input.parse()?; - let _ = input.parse::()?; let content; braced!(content in input); let items: Punctuated = @@ -44,6 +49,7 @@ impl Parse for Registry { Ok(Registry { name, items: items.into_iter().collect(), + attributes, }) } } @@ -66,7 +72,9 @@ pub fn registry(input: TokenStream) -> TokenStream { #name = #protocol_id, }); } + let attributes = input.attributes; generated.extend(quote! { + #(#attributes)* #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, azalea_buf::McBuf)] #[repr(u32)] pub enum #name { diff --git a/azalea-registry/src/lib.rs b/azalea-registry/src/lib.rs index 96c9ea26..075226b2 100755 --- a/azalea-registry/src/lib.rs +++ b/azalea-registry/src/lib.rs @@ -1,6 +1,9 @@ #![doc = include_str!("../README.md")] -// This file is automatically generated in codegen/lib/code/registry.py +// The contents of the macros below are generated in +// codegen/lib/code/registry.py, though the rest of the file isn't +// auto-generated (so you can add doc comments to the registry enums if you +// want) use azalea_buf::{BufReadError, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable}; use azalea_registry_macros::registry; @@ -39,7 +42,9 @@ impl McBufWritable for OptionalRegistry { } } -registry!(Activity, { +registry! { +/// The AI code that's currently being executed for the entity. +enum Activity { Core => "minecraft:core", Idle => "minecraft:idle", Work => "minecraft:work", @@ -66,9 +71,11 @@ registry!(Activity, { Roar => "minecraft:roar", Emerge => "minecraft:emerge", Dig => "minecraft:dig", -}); +} +} -registry!(Attribute, { +registry! { +enum Attribute { GenericMaxHealth => "minecraft:generic.max_health", GenericFollowRange => "minecraft:generic.follow_range", GenericKnockbackResistance => "minecraft:generic.knockback_resistance", @@ -82,9 +89,11 @@ registry!(Attribute, { GenericLuck => "minecraft:generic.luck", ZombieSpawnReinforcements => "minecraft:zombie.spawn_reinforcements", HorseJumpStrength => "minecraft:horse.jump_strength", -}); +} +} -registry!(BannerPattern, { +registry! { +enum BannerPattern { Base => "minecraft:base", SquareBottomLeft => "minecraft:square_bottom_left", SquareBottomRight => "minecraft:square_bottom_right", @@ -126,9 +135,16 @@ registry!(BannerPattern, { Flower => "minecraft:flower", Mojang => "minecraft:mojang", Piglin => "minecraft:piglin", -}); +} +} -registry!(Block, { +registry! { +/// An enum of every type of block in the game. To represent a block *state*, +/// use [`azalea_block::BlockState`] or the [`azalea_block::Block`] trait. +/// +/// [`azalea_block::BlockState`]: https://docs.rs/azalea-block/latest/azalea_block/struct.BlockState.html +/// [`azalea_block::Block`]: https://docs.rs/azalea-block/latest/azalea_block/trait.Block.html +enum Block { Air => "minecraft:air", Stone => "minecraft:stone", Granite => "minecraft:granite", @@ -1101,9 +1117,14 @@ registry!(Block, { PearlescentFroglight => "minecraft:pearlescent_froglight", Frogspawn => "minecraft:frogspawn", ReinforcedDeepslate => "minecraft:reinforced_deepslate", -}); +} +} -registry!(BlockEntityKind, { +registry! { +/// An enum that contains every type of block entity. A block entity is a block +/// that contains data that can't be represented as just a block state, like +/// how chests store items. +enum BlockEntityKind { Furnace => "minecraft:furnace", Chest => "minecraft:chest", TrappedChest => "minecraft:trapped_chest", @@ -1142,9 +1163,11 @@ registry!(BlockEntityKind, { SculkCatalyst => "minecraft:sculk_catalyst", SculkShrieker => "minecraft:sculk_shrieker", ChiseledBookshelf => "minecraft:chiseled_bookshelf", -}); +} +} -registry!(BlockPredicateKind, { +registry! { +enum BlockPredicateKind { MatchingBlocks => "minecraft:matching_blocks", MatchingBlockTag => "minecraft:matching_block_tag", MatchingFluids => "minecraft:matching_fluids", @@ -1157,9 +1180,11 @@ registry!(BlockPredicateKind, { AllOf => "minecraft:all_of", Not => "minecraft:not", True => "minecraft:true", -}); +} +} -registry!(CatVariant, { +registry! { +enum CatVariant { Tabby => "minecraft:tabby", Black => "minecraft:black", Red => "minecraft:red", @@ -1171,9 +1196,11 @@ registry!(CatVariant, { White => "minecraft:white", Jellie => "minecraft:jellie", AllBlack => "minecraft:all_black", -}); +} +} -registry!(ChunkStatus, { +registry! { +enum ChunkStatus { Empty => "minecraft:empty", StructureStarts => "minecraft:structure_starts", StructureReferences => "minecraft:structure_references", @@ -1187,9 +1214,11 @@ registry!(ChunkStatus, { Spawn => "minecraft:spawn", Heightmaps => "minecraft:heightmaps", Full => "minecraft:full", -}); +} +} -registry!(CommandArgumentKind, { +registry! { +enum CommandArgumentKind { Bool => "brigadier:bool", Float => "brigadier:float", Double => "brigadier:double", @@ -1238,9 +1267,11 @@ registry!(CommandArgumentKind, { TemplateMirror => "minecraft:template_mirror", TemplateRotation => "minecraft:template_rotation", Uuid => "minecraft:uuid", -}); +} +} -registry!(CustomStat, { +registry! { +enum CustomStat { LeaveGame => "minecraft:leave_game", PlayTime => "minecraft:play_time", TotalWorldTime => "minecraft:total_world_time", @@ -1316,9 +1347,11 @@ registry!(CustomStat, { InteractWithGrindstone => "minecraft:interact_with_grindstone", TargetHit => "minecraft:target_hit", InteractWithSmithingTable => "minecraft:interact_with_smithing_table", -}); +} +} -registry!(Enchantment, { +registry! { +enum Enchantment { Protection => "minecraft:protection", FireProtection => "minecraft:fire_protection", FeatherFalling => "minecraft:feather_falling", @@ -1358,9 +1391,12 @@ registry!(Enchantment, { Piercing => "minecraft:piercing", Mending => "minecraft:mending", VanishingCurse => "minecraft:vanishing_curse", -}); +} +} -registry!(EntityKind, { +registry! { +/// An enum that contains every type of entity. +enum EntityKind { Allay => "minecraft:allay", AreaEffectCloud => "minecraft:area_effect_cloud", ArmorStand => "minecraft:armor_stand", @@ -1480,30 +1516,38 @@ registry!(EntityKind, { ZombifiedPiglin => "minecraft:zombified_piglin", Player => "minecraft:player", FishingBobber => "minecraft:fishing_bobber", -}); +} +} -registry!(FloatProviderKind, { +registry! { +enum FloatProviderKind { Constant => "minecraft:constant", Uniform => "minecraft:uniform", ClampedNormal => "minecraft:clamped_normal", Trapezoid => "minecraft:trapezoid", -}); +} +} -registry!(Fluid, { +registry! { +enum Fluid { Empty => "minecraft:empty", FlowingWater => "minecraft:flowing_water", Water => "minecraft:water", FlowingLava => "minecraft:flowing_lava", Lava => "minecraft:lava", -}); +} +} -registry!(FrogVariant, { +registry! { +enum FrogVariant { Temperate => "minecraft:temperate", Warm => "minecraft:warm", Cold => "minecraft:cold", -}); +} +} -registry!(GameEvent, { +registry! { +enum GameEvent { BlockActivate => "minecraft:block_activate", BlockAttach => "minecraft:block_attach", BlockChange => "minecraft:block_change", @@ -1550,18 +1594,22 @@ registry!(GameEvent, { Step => "minecraft:step", Swim => "minecraft:swim", Teleport => "minecraft:teleport", -}); +} +} -registry!(HeightProviderKind, { +registry! { +enum HeightProviderKind { Constant => "minecraft:constant", Uniform => "minecraft:uniform", BiasedToBottom => "minecraft:biased_to_bottom", VeryBiasedToBottom => "minecraft:very_biased_to_bottom", Trapezoid => "minecraft:trapezoid", WeightedList => "minecraft:weighted_list", -}); +} +} -registry!(Instrument, { +registry! { +enum Instrument { PonderGoatHorn => "minecraft:ponder_goat_horn", SingGoatHorn => "minecraft:sing_goat_horn", SeekGoatHorn => "minecraft:seek_goat_horn", @@ -1570,18 +1618,22 @@ registry!(Instrument, { CallGoatHorn => "minecraft:call_goat_horn", YearnGoatHorn => "minecraft:yearn_goat_horn", DreamGoatHorn => "minecraft:dream_goat_horn", -}); +} +} -registry!(IntProviderKind, { +registry! { +enum IntProviderKind { Constant => "minecraft:constant", Uniform => "minecraft:uniform", BiasedToBottom => "minecraft:biased_to_bottom", Clamped => "minecraft:clamped", WeightedList => "minecraft:weighted_list", ClampedNormal => "minecraft:clamped_normal", -}); +} +} -registry!(Item, { +registry! { +enum Item { Air => "minecraft:air", Stone => "minecraft:stone", Granite => "minecraft:granite", @@ -2768,9 +2820,11 @@ registry!(Item, { PearlescentFroglight => "minecraft:pearlescent_froglight", Frogspawn => "minecraft:frogspawn", EchoShard => "minecraft:echo_shard", -}); +} +} -registry!(LootConditionKind, { +registry! { +enum LootConditionKind { Inverted => "minecraft:inverted", Alternative => "minecraft:alternative", RandomChance => "minecraft:random_chance", @@ -2788,9 +2842,11 @@ registry!(LootConditionKind, { Reference => "minecraft:reference", TimeCheck => "minecraft:time_check", ValueCheck => "minecraft:value_check", -}); +} +} -registry!(LootFunctionKind, { +registry! { +enum LootFunctionKind { SetCount => "minecraft:set_count", EnchantWithLevels => "minecraft:enchant_with_levels", EnchantRandomly => "minecraft:enchant_randomly", @@ -2816,21 +2872,27 @@ registry!(LootFunctionKind, { SetBannerPattern => "minecraft:set_banner_pattern", SetPotion => "minecraft:set_potion", SetInstrument => "minecraft:set_instrument", -}); +} +} -registry!(LootNbtProviderKind, { +registry! { +enum LootNbtProviderKind { Storage => "minecraft:storage", Context => "minecraft:context", -}); +} +} -registry!(LootNumberProviderKind, { +registry! { +enum LootNumberProviderKind { Constant => "minecraft:constant", Uniform => "minecraft:uniform", Binomial => "minecraft:binomial", Score => "minecraft:score", -}); +} +} -registry!(LootPoolEntryKind, { +registry! { +enum LootPoolEntryKind { Empty => "minecraft:empty", Item => "minecraft:item", LootTable => "minecraft:loot_table", @@ -2839,14 +2901,18 @@ registry!(LootPoolEntryKind, { Alternatives => "minecraft:alternatives", Sequence => "minecraft:sequence", Group => "minecraft:group", -}); +} +} -registry!(LootScoreProviderKind, { +registry! { +enum LootScoreProviderKind { Fixed => "minecraft:fixed", Context => "minecraft:context", -}); +} +} -registry!(MemoryModuleKind, { +registry! { +enum MemoryModuleKind { Dummy => "minecraft:dummy", Home => "minecraft:home", JobSite => "minecraft:job_site", @@ -2940,9 +3006,11 @@ registry!(MemoryModuleKind, { LikedNoteblock => "minecraft:liked_noteblock", LikedNoteblockCooldownTicks => "minecraft:liked_noteblock_cooldown_ticks", ItemPickupCooldownTicks => "minecraft:item_pickup_cooldown_ticks", -}); +} +} -registry!(Menu, { +registry! { +enum Menu { Generic9x1 => "minecraft:generic_9x1", Generic9x2 => "minecraft:generic_9x2", Generic9x3 => "minecraft:generic_9x3", @@ -2967,9 +3035,11 @@ registry!(Menu, { Smoker => "minecraft:smoker", CartographyTable => "minecraft:cartography_table", Stonecutter => "minecraft:stonecutter", -}); +} +} -registry!(MobEffect, { +registry! { +enum MobEffect { Speed => "minecraft:speed", Slowness => "minecraft:slowness", Haste => "minecraft:haste", @@ -3003,9 +3073,11 @@ registry!(MobEffect, { BadOmen => "minecraft:bad_omen", HeroOfTheVillage => "minecraft:hero_of_the_village", Darkness => "minecraft:darkness", -}); +} +} -registry!(PaintingVariant, { +registry! { +enum PaintingVariant { Kebab => "minecraft:kebab", Aztec => "minecraft:aztec", Alban => "minecraft:alban", @@ -3036,9 +3108,11 @@ registry!(PaintingVariant, { Water => "minecraft:water", Fire => "minecraft:fire", DonkeyKong => "minecraft:donkey_kong", -}); +} +} -registry!(ParticleKind, { +registry! { +enum ParticleKind { AmbientEntityEffect => "minecraft:ambient_entity_effect", AngryVillager => "minecraft:angry_villager", Block => "minecraft:block", @@ -3132,9 +3206,11 @@ registry!(ParticleKind, { ElectricSpark => "minecraft:electric_spark", Scrape => "minecraft:scrape", Shriek => "minecraft:shriek", -}); +} +} -registry!(PointOfInterestKind, { +registry! { +enum PointOfInterestKind { Armorer => "minecraft:armorer", Butcher => "minecraft:butcher", Cartographer => "minecraft:cartographer", @@ -3155,20 +3231,26 @@ registry!(PointOfInterestKind, { NetherPortal => "minecraft:nether_portal", Lodestone => "minecraft:lodestone", LightningRod => "minecraft:lightning_rod", -}); +} +} -registry!(PosRuleTest, { +registry! { +enum PosRuleTest { AlwaysTrue => "minecraft:always_true", LinearPos => "minecraft:linear_pos", AxisAlignedLinearPos => "minecraft:axis_aligned_linear_pos", -}); +} +} -registry!(PositionSourceKind, { +registry! { +enum PositionSourceKind { Block => "minecraft:block", Entity => "minecraft:entity", -}); +} +} -registry!(Potion, { +registry! { +enum Potion { Empty => "minecraft:empty", Water => "minecraft:water", Mundane => "minecraft:mundane", @@ -3212,9 +3294,11 @@ registry!(Potion, { Luck => "minecraft:luck", SlowFalling => "minecraft:slow_falling", LongSlowFalling => "minecraft:long_slow_falling", -}); +} +} -registry!(RecipeSerializer, { +registry! { +enum RecipeSerializer { CraftingShaped => "minecraft:crafting_shaped", CraftingShapeless => "minecraft:crafting_shapeless", CraftingSpecialArmordye => "minecraft:crafting_special_armordye", @@ -3236,9 +3320,11 @@ registry!(RecipeSerializer, { CampfireCooking => "minecraft:campfire_cooking", Stonecutting => "minecraft:stonecutting", Smithing => "minecraft:smithing", -}); +} +} -registry!(RecipeKind, { +registry! { +enum RecipeKind { Crafting => "minecraft:crafting", Smelting => "minecraft:smelting", Blasting => "minecraft:blasting", @@ -3246,25 +3332,31 @@ registry!(RecipeKind, { CampfireCooking => "minecraft:campfire_cooking", Stonecutting => "minecraft:stonecutting", Smithing => "minecraft:smithing", -}); +} +} -registry!(RuleTest, { +registry! { +enum RuleTest { AlwaysTrue => "minecraft:always_true", BlockMatch => "minecraft:block_match", BlockstateMatch => "minecraft:blockstate_match", TagMatch => "minecraft:tag_match", RandomBlockMatch => "minecraft:random_block_match", RandomBlockstateMatch => "minecraft:random_blockstate_match", -}); +} +} -registry!(Schedule, { +registry! { +enum Schedule { Empty => "minecraft:empty", Simple => "minecraft:simple", VillagerBaby => "minecraft:villager_baby", VillagerDefault => "minecraft:villager_default", -}); +} +} -registry!(SensorKind, { +registry! { +enum SensorKind { Dummy => "minecraft:dummy", NearestItems => "minecraft:nearest_items", NearestLivingEntities => "minecraft:nearest_living_entities", @@ -3287,9 +3379,11 @@ registry!(SensorKind, { FrogAttackables => "minecraft:frog_attackables", IsInWater => "minecraft:is_in_water", WardenEntitySensor => "minecraft:warden_entity_sensor", -}); +} +} -registry!(SoundEvent, { +registry! { +enum SoundEvent { EntityAllayAmbientWithItem => "minecraft:entity.allay.ambient_with_item", EntityAllayAmbientWithoutItem => "minecraft:entity.allay.ambient_without_item", EntityAllayDeath => "minecraft:entity.allay.death", @@ -4682,9 +4776,11 @@ registry!(SoundEvent, { EntityZombieVillagerDeath => "minecraft:entity.zombie_villager.death", EntityZombieVillagerHurt => "minecraft:entity.zombie_villager.hurt", EntityZombieVillagerStep => "minecraft:entity.zombie_villager.step", -}); +} +} -registry!(StatKind, { +registry! { +enum StatKind { Mined => "minecraft:mined", Crafted => "minecraft:crafted", Used => "minecraft:used", @@ -4694,9 +4790,11 @@ registry!(StatKind, { Killed => "minecraft:killed", KilledBy => "minecraft:killed_by", Custom => "minecraft:custom", -}); +} +} -registry!(VillagerProfession, { +registry! { +enum VillagerProfession { None => "minecraft:none", Armorer => "minecraft:armorer", Butcher => "minecraft:butcher", @@ -4712,9 +4810,11 @@ registry!(VillagerProfession, { Shepherd => "minecraft:shepherd", Toolsmith => "minecraft:toolsmith", Weaponsmith => "minecraft:weaponsmith", -}); +} +} -registry!(VillagerKind, { +registry! { +enum VillagerKind { Desert => "minecraft:desert", Jungle => "minecraft:jungle", Plains => "minecraft:plains", @@ -4722,16 +4822,20 @@ registry!(VillagerKind, { Snow => "minecraft:snow", Swamp => "minecraft:swamp", Taiga => "minecraft:taiga", -}); +} +} -registry!(WorldgenBiomeSource, { +registry! { +enum WorldgenBiomeSource { Fixed => "minecraft:fixed", MultiNoise => "minecraft:multi_noise", Checkerboard => "minecraft:checkerboard", TheEnd => "minecraft:the_end", -}); +} +} -registry!(WorldgenBlockStateProviderKind, { +registry! { +enum WorldgenBlockStateProviderKind { SimpleStateProvider => "minecraft:simple_state_provider", WeightedStateProvider => "minecraft:weighted_state_provider", NoiseThresholdProvider => "minecraft:noise_threshold_provider", @@ -4739,21 +4843,27 @@ registry!(WorldgenBlockStateProviderKind, { DualNoiseProvider => "minecraft:dual_noise_provider", RotatedBlockProvider => "minecraft:rotated_block_provider", RandomizedIntStateProvider => "minecraft:randomized_int_state_provider", -}); +} +} -registry!(WorldgenCarver, { +registry! { +enum WorldgenCarver { Cave => "minecraft:cave", NetherCave => "minecraft:nether_cave", Canyon => "minecraft:canyon", -}); +} +} -registry!(WorldgenChunkGenerator, { +registry! { +enum WorldgenChunkGenerator { Noise => "minecraft:noise", Flat => "minecraft:flat", Debug => "minecraft:debug", -}); +} +} -registry!(WorldgenDensityFunctionKind, { +registry! { +enum WorldgenDensityFunctionKind { BlendAlpha => "minecraft:blend_alpha", BlendOffset => "minecraft:blend_offset", Beardifier => "minecraft:beardifier", @@ -4786,9 +4896,11 @@ registry!(WorldgenDensityFunctionKind, { Spline => "minecraft:spline", Constant => "minecraft:constant", YClampedGradient => "minecraft:y_clamped_gradient", -}); +} +} -registry!(WorldgenFeature, { +registry! { +enum WorldgenFeature { NoOp => "minecraft:no_op", Tree => "minecraft:tree", Flower => "minecraft:flower", @@ -4850,14 +4962,18 @@ registry!(WorldgenFeature, { LargeDripstone => "minecraft:large_dripstone", PointedDripstone => "minecraft:pointed_dripstone", SculkPatch => "minecraft:sculk_patch", -}); +} +} -registry!(WorldgenFeatureSizeKind, { +registry! { +enum WorldgenFeatureSizeKind { TwoLayersFeatureSize => "minecraft:two_layers_feature_size", ThreeLayersFeatureSize => "minecraft:three_layers_feature_size", -}); +} +} -registry!(WorldgenFoliagePlacerKind, { +registry! { +enum WorldgenFoliagePlacerKind { BlobFoliagePlacer => "minecraft:blob_foliage_placer", SpruceFoliagePlacer => "minecraft:spruce_foliage_placer", PineFoliagePlacer => "minecraft:pine_foliage_placer", @@ -4868,9 +4984,11 @@ registry!(WorldgenFoliagePlacerKind, { MegaPineFoliagePlacer => "minecraft:mega_pine_foliage_placer", DarkOakFoliagePlacer => "minecraft:dark_oak_foliage_placer", RandomSpreadFoliagePlacer => "minecraft:random_spread_foliage_placer", -}); +} +} -registry!(WorldgenMaterialCondition, { +registry! { +enum WorldgenMaterialCondition { Biome => "minecraft:biome", NoiseThreshold => "minecraft:noise_threshold", VerticalGradient => "minecraft:vertical_gradient", @@ -4882,16 +5000,20 @@ registry!(WorldgenMaterialCondition, { Hole => "minecraft:hole", AbovePreliminarySurface => "minecraft:above_preliminary_surface", StoneDepth => "minecraft:stone_depth", -}); +} +} -registry!(WorldgenMaterialRule, { +registry! { +enum WorldgenMaterialRule { Bandlands => "minecraft:bandlands", Block => "minecraft:block", Sequence => "minecraft:sequence", Condition => "minecraft:condition", -}); +} +} -registry!(WorldgenPlacementModifierKind, { +registry! { +enum WorldgenPlacementModifierKind { BlockPredicateFilter => "minecraft:block_predicate_filter", RarityFilter => "minecraft:rarity_filter", SurfaceRelativeThresholdFilter => "minecraft:surface_relative_threshold_filter", @@ -4907,13 +5029,17 @@ registry!(WorldgenPlacementModifierKind, { InSquare => "minecraft:in_square", RandomOffset => "minecraft:random_offset", CarvingMask => "minecraft:carving_mask", -}); +} +} -registry!(WorldgenRootPlacerKind, { +registry! { +enum WorldgenRootPlacerKind { MangroveRootPlacer => "minecraft:mangrove_root_placer", -}); +} +} -registry!(WorldgenStructurePiece, { +registry! { +enum WorldgenStructurePiece { Mscorridor => "minecraft:mscorridor", Mscrossing => "minecraft:mscrossing", Msroom => "minecraft:msroom", @@ -4970,22 +5096,28 @@ registry!(WorldgenStructurePiece, { Shipwreck => "minecraft:shipwreck", Nefos => "minecraft:nefos", Jigsaw => "minecraft:jigsaw", -}); +} +} -registry!(WorldgenStructurePlacement, { +registry! { +enum WorldgenStructurePlacement { RandomSpread => "minecraft:random_spread", ConcentricRings => "minecraft:concentric_rings", -}); +} +} -registry!(WorldgenStructurePoolElement, { +registry! { +enum WorldgenStructurePoolElement { SinglePoolElement => "minecraft:single_pool_element", ListPoolElement => "minecraft:list_pool_element", FeaturePoolElement => "minecraft:feature_pool_element", EmptyPoolElement => "minecraft:empty_pool_element", LegacySinglePoolElement => "minecraft:legacy_single_pool_element", -}); +} +} -registry!(WorldgenStructureProcessor, { +registry! { +enum WorldgenStructureProcessor { BlockIgnore => "minecraft:block_ignore", BlockRot => "minecraft:block_rot", Gravity => "minecraft:gravity", @@ -4996,9 +5128,11 @@ registry!(WorldgenStructureProcessor, { BlackstoneReplace => "minecraft:blackstone_replace", LavaSubmergedBlock => "minecraft:lava_submerged_block", ProtectedBlocks => "minecraft:protected_blocks", -}); +} +} -registry!(WorldgenStructureKind, { +registry! { +enum WorldgenStructureKind { BuriedTreasure => "minecraft:buried_treasure", DesertPyramid => "minecraft:desert_pyramid", EndCity => "minecraft:end_city", @@ -5015,18 +5149,22 @@ registry!(WorldgenStructureKind, { Stronghold => "minecraft:stronghold", SwampHut => "minecraft:swamp_hut", WoodlandMansion => "minecraft:woodland_mansion", -}); +} +} -registry!(WorldgenTreeDecoratorKind, { +registry! { +enum WorldgenTreeDecoratorKind { TrunkVine => "minecraft:trunk_vine", LeaveVine => "minecraft:leave_vine", Cocoa => "minecraft:cocoa", Beehive => "minecraft:beehive", AlterGround => "minecraft:alter_ground", AttachedToLeaves => "minecraft:attached_to_leaves", -}); +} +} -registry!(WorldgenTrunkPlacerKind, { +registry! { +enum WorldgenTrunkPlacerKind { StraightTrunkPlacer => "minecraft:straight_trunk_placer", ForkingTrunkPlacer => "minecraft:forking_trunk_placer", GiantTrunkPlacer => "minecraft:giant_trunk_placer", @@ -5035,4 +5173,5 @@ registry!(WorldgenTrunkPlacerKind, { FancyTrunkPlacer => "minecraft:fancy_trunk_placer", BendingTrunkPlacer => "minecraft:bending_trunk_placer", UpwardsBranchingTrunkPlacer => "minecraft:upwards_branching_trunk_placer", -}); +} +} diff --git a/codegen/lib/code/registry.py b/codegen/lib/code/registry.py index 1e9d9f43..a67b5e4d 100755 --- a/codegen/lib/code/registry.py +++ b/codegen/lib/code/registry.py @@ -7,49 +7,8 @@ REGISTRIES_DIR = get_dir_location('../azalea-registry/src/lib.rs') def generate_registries(registries: dict): - code = [] - - code.append('''#![doc = include_str!("../README.md")] - -// This file is automatically generated in codegen/lib/code/registry.py - -use azalea_buf::{BufReadError, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable}; -use azalea_registry_macros::registry; -use std::io::{Cursor, Write}; - -pub trait Registry -where - Self: Sized, -{ - fn from_u32(value: u32) -> Option; - fn to_u32(&self) -> u32; -} - -/// A registry that might not be present. This is transmitted as a single -/// varint in the protocol. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct OptionalRegistry(Option); - -impl McBufReadable for OptionalRegistry { - fn read_from(buf: &mut Cursor<&[u8]>) -> Result { - Ok(OptionalRegistry(match u32::var_read_from(buf)? { - 0 => None, - value => Some( - T::from_u32(value - 1) - .ok_or(BufReadError::UnexpectedEnumVariant { id: value as i32 })?, - ), - })) - } -} -impl McBufWritable for OptionalRegistry { - fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { - match &self.0 { - None => 0u32.var_write_into(buf), - Some(value) => (value.to_u32() + 1).var_write_into(buf), - } - } -} -''') + with open(REGISTRIES_DIR, 'r') as f: + code = f.read().split('\n') for registry_name, registry in registries.items(): # registry!(Block, { @@ -64,15 +23,35 @@ impl McBufWritable for OptionalRegistry { registry_struct_name = to_camel_case(registry_name.split(':')[1]) - code.append(f'registry!({registry_struct_name}, {{') + registry_code = [] + registry_code.append(f'enum {registry_struct_name} {{') registry_entries = sorted( registry['entries'].items(), key=lambda x: x[1]['protocol_id']) for variant_name, _variant in registry_entries: variant_struct_name = to_camel_case( variant_name.split(':')[1]) - code.append(f'\t{variant_struct_name} => "{variant_name}",') - code.append('});') - code.append('') + registry_code.append(f'\t{variant_struct_name} => "{variant_name}",') + registry_code.append('}') + + # when we find a "registry! {" line, find the next line that starts + # with "enum " and replace that until we find a line that's "}" + found = False + in_registry_macro = False + for i, line in enumerate(list(code)): + if not in_registry_macro and line == "registry! {": + in_registry_macro = True + elif in_registry_macro and line == registry_code[0]: + # found it, now delete until we get to "}" + while code[i] != '}': + code.pop(i) + code[i] = '\n'.join(registry_code) + found = True + break + if not found: + code.append('registry! {') + code.append('\n'.join(registry_code)) + code.append('}') + code.append('') with open(REGISTRIES_DIR, 'w') as f: f.write('\n'.join(code))