diff --git a/.gitignore b/.gitignore index fd779e233..d3e1c5622 100644 --- a/.gitignore +++ b/.gitignore @@ -126,6 +126,7 @@ run/ *perf.data* *flamegraph.svg *dhat* +*bench_root_tmp* # Nix (direnv and result) diff --git a/pumpkin-data/build/biome.rs b/pumpkin-data/build/biome.rs index 0d85c72b1..06e3cf66d 100644 --- a/pumpkin-data/build/biome.rs +++ b/pumpkin-data/build/biome.rs @@ -7,7 +7,7 @@ use serde::Deserialize; use syn::LitInt; #[derive(Deserialize)] -struct Biome { +pub struct Biome { has_precipitation: bool, temperature: f32, downfall: f32, @@ -16,7 +16,7 @@ struct Biome { features: Vec>, creature_spawn_probability: Option, spawners: SpawnGroups, - id: u8, + pub id: u8, } #[derive(Deserialize, PartialEq, Eq, Hash)] diff --git a/pumpkin-data/build/block.rs b/pumpkin-data/build/block.rs index eb5a5bf49..92ff02503 100644 --- a/pumpkin-data/build/block.rs +++ b/pumpkin-data/build/block.rs @@ -26,6 +26,18 @@ fn fill_array(array: Vec<(u16, T)>) -> Vec) -> Vec { + let max_index = array.iter().map(|(_, _, index)| index).max().unwrap(); + let mut ret = vec![quote! { Missed State }; (max_index + 1) as usize]; + + for (block, index, state_id) in array { + let index_lit = LitInt::new(&index.to_string(), Span::call_site()); + ret[state_id as usize] = quote! { &Self::#block.states[#index_lit] }; + } + + ret +} + fn const_block_name_from_block_name(block: &str) -> String { block.to_shouty_snake_case() } @@ -654,6 +666,7 @@ pub(crate) fn build() -> TokenStream { let mut block_from_name = TokenStream::new(); let mut raw_id_from_state_id = TokenStream::new(); let mut block_from_item_id = TokenStream::new(); + let mut state_from_state_id = TokenStream::new(); let mut random_tick_states = Vec::new(); let mut block_properties_from_state_and_block_id = TokenStream::new(); let mut block_properties_from_props_and_name = TokenStream::new(); @@ -778,6 +791,7 @@ pub(crate) fn build() -> TokenStream { let mut raw_id_from_state_id_array = vec![]; let mut type_from_raw_id_array = vec![]; + let mut state_from_state_id_array = Vec::<(Ident, usize, u16)>::new(); // block index state_id //let mut file = fs::File::create("../debug/debug.txt").unwrap(); @@ -834,6 +848,10 @@ pub(crate) fn build() -> TokenStream { raw_id_from_state_id_array.push((state.id, id_lit.clone())); } + for (index, state) in block.states.iter().enumerate() { + state_from_state_id_array.push((const_ident.clone(), index, state.id)); + } + if !existing_item_ids.contains(&item_id) { block_from_item_id.extend(quote! { #item_id => Some(&Self::#const_ident), @@ -875,6 +893,15 @@ pub(crate) fn build() -> TokenStream { #type_lit, }); } + let state_from_state_id_array = fill_state_array(state_from_state_id_array); + let max_state_id_2 = state_from_state_id_array.len(); + for token in state_from_state_id_array { + state_from_state_id.extend(quote! { + #token, + }); + } + + assert_eq!(max_state_id, max_state_id_2); quote! { use crate::{BlockState, Block, CollisionShape, blocks::Flammable}; @@ -955,15 +982,16 @@ pub(crate) fn build() -> TokenStream { #[doc = r" Get a block state from a state id."] #[doc = r" If you need access to the block use `BlockState::from_id_with_block` instead."] + #[inline] pub fn from_id(id: u16) -> &'static Self { - let state: &Self = Block::from_state_id(id).states.iter().find(|state| state.id == id).unwrap(); - state + Block::STATE_FROM_STATE_ID[id as usize] } #[doc = r" Get a block state from a state id and the corresponding block."] - pub fn from_id_with_block(id: u16) -> (&'static Block, &'static BlockState) { + #[inline] + pub fn from_id_with_block(id: u16) -> (&'static Block, &'static Self) { let block = Block::from_state_id(id); - let state: &Self = block.states.iter().find(|state| state.id == id).unwrap(); + let state: &Self = Block::STATE_FROM_STATE_ID[id as usize]; (block, state) } @@ -989,7 +1017,12 @@ pub(crate) fn build() -> TokenStream { #type_from_raw_id_items ]; + const STATE_FROM_STATE_ID: [&'static BlockState; #max_state_id] = [ + #state_from_state_id + ]; + #[doc = r" Try to parse a block from a resource location string."] + #[inline] pub fn from_registry_key(name: &str) -> Option<&'static Self> { Self::BLOCK_FROM_NAME_MAP.get(name) } @@ -1001,6 +1034,7 @@ pub(crate) fn build() -> TokenStream { } #[doc = r" Get a block from a raw block id."] + #[inline] pub const fn from_id(id: u16) -> &'static Self { if id as usize >= Self::RAW_ID_FROM_STATE_ID.len() { &Self::AIR @@ -1010,6 +1044,7 @@ pub(crate) fn build() -> TokenStream { } #[doc = r" Get a block from a state id."] + #[inline] pub const fn from_state_id(id: u16) -> &'static Self { if id as usize >= Self::RAW_ID_FROM_STATE_ID.len() { return &Self::AIR; diff --git a/pumpkin-data/build/fluid.rs b/pumpkin-data/build/fluid.rs index 1c53a619a..7d0a3f631 100644 --- a/pumpkin-data/build/fluid.rs +++ b/pumpkin-data/build/fluid.rs @@ -316,9 +316,9 @@ struct Property { } #[derive(Deserialize, Clone)] -struct Fluid { - name: String, - id: u16, +pub struct Fluid { + pub name: String, + pub id: u16, properties: Vec, default_state_index: u16, states: Vec, @@ -595,7 +595,7 @@ pub(crate) fn build() -> TokenStream { quote! { use std::hash::{Hash, Hasher}; - use crate::tag::{Tagable, RegistryKey}; + use crate::tag::{Taggable, RegistryKey}; use pumpkin_util::resource_location::{FromResourceLocation, ResourceLocation, ToResourceLocation}; #[derive(Clone, Debug)] @@ -791,7 +791,7 @@ pub(crate) fn build() -> TokenStream { } } - impl Tagable for Fluid { + impl Taggable for Fluid { #[inline] fn tag_key() -> RegistryKey { RegistryKey::Fluid @@ -801,6 +801,11 @@ pub(crate) fn build() -> TokenStream { fn registry_key(&self) -> &str { self.name } + + #[inline] + fn registry_id(&self) -> u16 { + self.id + } } // Added FluidLevel enum and required constants diff --git a/pumpkin-data/build/item.rs b/pumpkin-data/build/item.rs index a136a130a..61c03e9fd 100644 --- a/pumpkin-data/build/item.rs +++ b/pumpkin-data/build/item.rs @@ -262,7 +262,7 @@ pub(crate) fn build() -> TokenStream { quote! { use std::hash::{Hash, Hasher}; use pumpkin_util::text::TextComponent; - use crate::tag::{Tagable, RegistryKey}; + use crate::tag::{Taggable, RegistryKey}; #[derive(Clone, Debug)] pub struct Item { @@ -359,7 +359,7 @@ pub(crate) fn build() -> TokenStream { } } - impl Tagable for Item { + impl Taggable for Item { #[inline] fn tag_key() -> RegistryKey { RegistryKey::Item @@ -369,6 +369,11 @@ pub(crate) fn build() -> TokenStream { fn registry_key(&self) -> &str { self.registry_key } + + #[inline] + fn registry_id(&self) -> u16 { + self.id + } } } } diff --git a/pumpkin-data/build/recipes.rs b/pumpkin-data/build/recipes.rs index 99825062f..9cb094a1f 100644 --- a/pumpkin-data/build/recipes.rs +++ b/pumpkin-data/build/recipes.rs @@ -374,7 +374,7 @@ pub(crate) fn build() -> TokenStream { } quote! { - use crate::tag::Tagable; + use crate::tag::Taggable; use crate::item::Item; #[derive(Clone, Debug)] diff --git a/pumpkin-data/build/tag.rs b/pumpkin-data/build/tag.rs index 61cbef8f6..7d92cf3eb 100644 --- a/pumpkin-data/build/tag.rs +++ b/pumpkin-data/build/tag.rs @@ -1,5 +1,9 @@ use std::{collections::HashMap, fs}; +use crate::biome::Biome; +use crate::block::BlockAssets; +use crate::fluid::Fluid; +use crate::item::Item; use heck::ToPascalCase; use proc_macro2::TokenStream; use quote::{ToTokens, format_ident, quote}; @@ -29,10 +33,33 @@ impl ToTokens for EnumCreator { } pub(crate) fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/tags.json"); + println!("cargo:rerun-if-changed=../assets/blocks.json"); + println!("cargo:rerun-if-changed=../assets/items.json"); + println!("cargo:rerun-if-changed=../assets/biome.json"); + println!("cargo:rerun-if-changed=../assets/fluids.json"); let tags: HashMap>> = serde_json::from_str(&fs::read_to_string("../assets/tags.json").unwrap()) .expect("Failed to parse tags.json"); + + let blocks_assets: BlockAssets = + serde_json::from_str(&fs::read_to_string("../assets/blocks.json").unwrap()) + .expect("Failed to parse blocks.json"); + + let items: HashMap = + serde_json::from_str(&fs::read_to_string("../assets/items.json").unwrap()) + .expect("Failed to parse items.json"); + + let biomes: HashMap = + serde_json::from_str(&fs::read_to_string("../assets/biome.json").unwrap()) + .expect("Failed to parse biome.json"); + + let fluids: Vec = + match serde_json::from_str(&fs::read_to_string("../assets/fluids.json").unwrap()) { + Ok(fluids) => fluids, + Err(e) => panic!("Failed to parse fluids.json: {e}"), + }; + let registry_key_enum = EnumCreator { name: "RegistryKey".to_string(), value: tags.keys().map(|key| key.to_string()).collect(), @@ -41,7 +68,8 @@ pub(crate) fn build() -> TokenStream { // Generate tag arrays for each registry key let mut tag_dicts = Vec::new(); - let mut match_arms = Vec::new(); + let mut match_arms_value = Vec::new(); + let mut match_arms_id = Vec::new(); let mut match_arms_tags_all = Vec::new(); let mut tag_identifiers = Vec::new(); @@ -57,27 +85,73 @@ pub(crate) fn build() -> TokenStream { tag_values.push((tag_name.clone(), values.clone())); } + tag_values.sort(); + // Generate the static array of tag values let tag_array_entries = tag_values .iter() .map(|(tag_name, values)| { let tag_values_array = values.iter().map(|v| quote! { #v }).collect::>(); + let tag_id_array = match key { + t if t == "worldgen/biome" => values.iter().map(|v| { + let id = biomes.get(v).unwrap().id as u16; + quote! { #id } + }).collect::>(), + t if t == "fluid" => values.iter().map(|v| { + let id = fluids.iter().find(|i| { &i.name == v }).unwrap().id; + quote! { #id } + }).collect::>(), + t if t == "item" => values.iter().map(|v| { + let id = items.get(v).unwrap().id; + quote! { #id } + }).collect::>(), + t if t == "block" => values.iter().map(|v| { + let id = blocks_assets.blocks.iter().find(|i| { &i.name == v }).unwrap().id; + quote! { #id } + }).collect::>(), + &_ => Vec::new(), + }; + let mapped_name = format_ident!("{}", tag_name.replace(":", "_").replace("/", "_").to_uppercase()); quote! { - #tag_name => &[#(#tag_values_array),*] + pub const #mapped_name: Tag = (&[#(#tag_values_array),*], &[#(#tag_id_array),*]); + } + }) + .collect::>(); + let tag_array_entries_map = tag_values + .iter() + .map(|(tag_name, _values)| { + let mapped_name = format_ident!( + "{}", + tag_name.replace(":", "_").replace("/", "_").to_uppercase() + ); + quote! { + #tag_name => &#key_pascal::#mapped_name } }) .collect::>(); // Add the static array declaration tag_dicts.push(quote! { - static #dict_name: phf::Map<&str, &[&str]> = phf::phf_map! { - #(#tag_array_entries),* + #[allow(non_snake_case)] + pub mod #key_pascal { + use crate::tag::Tag; + + #(#tag_array_entries)* + } + static #dict_name: phf::Map<&str, &'static Tag> = phf::phf_map! { + #(#tag_array_entries_map),* }; }); // Add match arm for this registry key - match_arms.push(quote! { + match_arms_value.push(quote! { RegistryKey::#key_pascal => { - #dict_name.get(tag).copied() + #dict_name.get(tag).map(|i| i.0) + } + }); + + match_arms_id.push(quote! { + RegistryKey::#key_pascal => { + #dict_name.get(tag).map(|i| i.1 ) } }); @@ -106,29 +180,42 @@ pub(crate) fn build() -> TokenStream { } } + pub type Tag = (&'static [&'static str], &'static [u16]); + #(#tag_dicts)* pub fn get_tag_values(tag_category: RegistryKey, tag: &str) -> Option<&'static [&'static str]> { match tag_category { - #(#match_arms),* + #(#match_arms_value),* } } - pub fn get_registry_key_tags(tag_category: &RegistryKey) -> &phf::Map<&'static str, &'static [&'static str]> { + pub fn get_tag_ids(tag_category: RegistryKey, tag: &str) -> Option<&'static [u16]> { + match tag_category { + #(#match_arms_id),* + } + } + + pub fn get_registry_key_tags(tag_category: &RegistryKey) -> &phf::Map<&'static str, &'static Tag> { match tag_category { #(#match_arms_tags_all),* } } - pub trait Tagable { + pub trait Taggable { fn tag_key() -> RegistryKey; fn registry_key(&self) -> &str; + fn registry_id(&self) -> u16; /// Returns `None` if the tag does not exist. fn is_tagged_with(&self, tag: &str) -> Option { let tag = tag.strip_prefix("#").unwrap_or(tag); - let items = get_tag_values(Self::tag_key(), tag)?; - Some(items.iter().any(|elem| *elem == self.registry_key())) + let items = get_tag_ids(Self::tag_key(), tag)?; + Some(items.contains(&self.registry_id())) + } + + fn is_tagged_with_by_tag(&self, tag: &'static Tag) -> bool { + tag.1.contains(&self.registry_id()) } fn get_tag_values(tag: &str) -> Option<&'static [&'static str]> { diff --git a/pumpkin-data/src/blocks.rs b/pumpkin-data/src/blocks.rs index c90cd7229..410b5e158 100644 --- a/pumpkin-data/src/blocks.rs +++ b/pumpkin-data/src/blocks.rs @@ -1,6 +1,6 @@ use crate::{ BlockState, BlockStateRef, - tag::{RegistryKey, Tagable}, + tag::{RegistryKey, Taggable}, }; use pumpkin_util::{ loot_table::LootTable, @@ -41,7 +41,7 @@ impl Hash for Block { } } -impl Tagable for Block { +impl Taggable for Block { #[inline] fn tag_key() -> RegistryKey { RegistryKey::Block @@ -51,6 +51,11 @@ impl Tagable for Block { fn registry_key(&self) -> &str { self.name } + + #[inline] + fn registry_id(&self) -> u16 { + self.id + } } impl ToResourceLocation for &'static Block { diff --git a/pumpkin-inventory/src/crafting/crafting_screen_handler.rs b/pumpkin-inventory/src/crafting/crafting_screen_handler.rs index 124047f8b..8af13fb82 100644 --- a/pumpkin-inventory/src/crafting/crafting_screen_handler.rs +++ b/pumpkin-inventory/src/crafting/crafting_screen_handler.rs @@ -13,7 +13,8 @@ use async_trait::async_trait; use crossbeam_utils::atomic::AtomicCell; use pumpkin_data::recipes::{CraftingRecipeTypes, RECIPES_CRAFTING, RecipeResultStruct}; use pumpkin_data::screen::WindowType; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag; +use pumpkin_data::tag::Taggable; use pumpkin_world::inventory::Inventory; use pumpkin_world::item::ItemStack; use tokio::sync::Mutex; @@ -215,8 +216,7 @@ async fn recipe_matches<'a>( if slot.is_empty() || !slot .item - .is_tagged_with("#minecraft:decorated_pot_ingredients") - .unwrap() + .is_tagged_with_by_tag(&tag::Item::MINECRAFT_DECORATED_POT_INGREDIENTS) { return None; } diff --git a/pumpkin-protocol/src/java/client/config/update_tags.rs b/pumpkin-protocol/src/java/client/config/update_tags.rs index 586661f86..93dc34741 100644 --- a/pumpkin-protocol/src/java/client/config/update_tags.rs +++ b/pumpkin-protocol/src/java/client/config/update_tags.rs @@ -38,7 +38,7 @@ impl ClientPacket for CUpdateTags<'_> { for (key, values) in values.entries() { // This is technically a `ResourceLocation` but same thing p.write_string_bounded(key, u16::MAX as usize)?; - p.write_list(values, |p, string_id| { + p.write_list(values.0, |p, string_id| { let id = match registry_key { RegistryKey::Block => Block::from_name(string_id).unwrap().id as i32, RegistryKey::Fluid => Fluid::ident_to_fluid_id(string_id).unwrap() as i32, diff --git a/pumpkin-world/src/block/entities/hopper.rs b/pumpkin-world/src/block/entities/hopper.rs index 848eb4b3c..a383eb3c9 100644 --- a/pumpkin-world/src/block/entities/hopper.rs +++ b/pumpkin-world/src/block/entities/hopper.rs @@ -6,7 +6,7 @@ use crate::world::SimpleWorld; use async_trait::async_trait; use pumpkin_data::Block; use pumpkin_data::block_properties::{BlockProperties, HopperFacing, HopperLikeProperties}; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; use pumpkin_nbt::tag::NbtTag; use pumpkin_util::math::position::BlockPos; use pumpkin_util::math::vector3::Vector3; diff --git a/pumpkin-world/src/generation/block_predicate.rs b/pumpkin-world/src/generation/block_predicate.rs index c28363421..5e4a2a6cf 100644 --- a/pumpkin-world/src/generation/block_predicate.rs +++ b/pumpkin-world/src/generation/block_predicate.rs @@ -1,5 +1,5 @@ use itertools::Itertools; -use pumpkin_data::{Block, BlockDirection, BlockState, tag::Tagable}; +use pumpkin_data::{Block, BlockDirection, BlockState, tag::Taggable}; use pumpkin_util::math::{position::BlockPos, vector3::Vector3}; use serde::Deserialize; diff --git a/pumpkin-world/src/generation/feature/features/bamboo.rs b/pumpkin-world/src/generation/feature/features/bamboo.rs index cb386a525..19d2847f1 100644 --- a/pumpkin-world/src/generation/feature/features/bamboo.rs +++ b/pumpkin-world/src/generation/feature/features/bamboo.rs @@ -1,7 +1,8 @@ use pumpkin_data::{ Block, BlockDirection, BlockState, block_properties::{BambooLeaves, BambooLikeProperties, BlockProperties, Integer0To1}, - tag::Tagable, + tag, + tag::Taggable, }; use pumpkin_util::{ math::{position::BlockPos, vector2::Vector2}, @@ -42,7 +43,10 @@ impl BambooFeature { z, ); let block = chunk.get_block_state(&block_below.0); - if !block.to_block().is_tagged_with("minecraft:dirt").unwrap() { + if !block + .to_block() + .is_tagged_with_by_tag(&tag::Block::MINECRAFT_DIRT) + { continue; } chunk.set_block_state(&block_below.0, Block::PODZOL.default_state); diff --git a/pumpkin-world/src/generation/feature/features/coral/mod.rs b/pumpkin-world/src/generation/feature/features/coral/mod.rs index 6df1fe7cb..95a90a5a4 100644 --- a/pumpkin-world/src/generation/feature/features/coral/mod.rs +++ b/pumpkin-world/src/generation/feature/features/coral/mod.rs @@ -1,7 +1,8 @@ use pumpkin_data::{ Block, BlockDirection, BlockState, block_properties::{BlockProperties, EnumVariants, Integer1To4, SeaPickleLikeProperties}, - tag::{RegistryKey, Tagable, get_tag_values}, + tag, + tag::{RegistryKey, Taggable, get_tag_values}, }; use pumpkin_util::{ math::position::BlockPos, @@ -26,7 +27,7 @@ impl CoralFeature { let block = chunk.get_block_state(&pos.0).to_block(); let above_block = chunk.get_block_state(&pos.up().0).to_block(); - if block != &Block::WATER && !block.is_tagged_with("minecraft:corals").unwrap() + if block != &Block::WATER && !block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_CORALS) || above_block != &Block::WATER { return false; diff --git a/pumpkin-world/src/generation/feature/features/drip_stone/mod.rs b/pumpkin-world/src/generation/feature/features/drip_stone/mod.rs index acba9c352..a9f7991b4 100644 --- a/pumpkin-world/src/generation/feature/features/drip_stone/mod.rs +++ b/pumpkin-world/src/generation/feature/features/drip_stone/mod.rs @@ -1,4 +1,5 @@ -use pumpkin_data::{Block, tag::Tagable}; +use pumpkin_data::tag; +use pumpkin_data::{Block, tag::Taggable}; use pumpkin_util::math::position::BlockPos; use crate::ProtoChunk; @@ -9,17 +10,12 @@ pub mod small; pub(super) fn can_replace(block: &Block) -> bool { block == &Block::DRIPSTONE_BLOCK - || block - .is_tagged_with("minecraft:dripstone_replaceable_blocks") - .unwrap() + || block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_DRIPSTONE_REPLACEABLE_BLOCKS) } pub(super) fn gen_dripstone(chunk: &mut ProtoChunk, pos: BlockPos) -> bool { let block = chunk.get_block_state(&pos.0).to_block(); - if block - .is_tagged_with("minecraft:dripstone_replaceable_blocks") - .unwrap() - { + if block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_DRIPSTONE_REPLACEABLE_BLOCKS) { chunk.set_block_state(&pos.0, Block::DRIPSTONE_BLOCK.default_state); return true; } diff --git a/pumpkin-world/src/generation/feature/features/nether_forest_vegetation.rs b/pumpkin-world/src/generation/feature/features/nether_forest_vegetation.rs index 4ef21b2c3..c369d4169 100644 --- a/pumpkin-world/src/generation/feature/features/nether_forest_vegetation.rs +++ b/pumpkin-world/src/generation/feature/features/nether_forest_vegetation.rs @@ -1,4 +1,4 @@ -use pumpkin_data::{Block, BlockDirection, tag::Tagable}; +use pumpkin_data::{Block, BlockDirection, tag, tag::Taggable}; use pumpkin_util::{ math::position::BlockPos, random::{RandomGenerator, RandomImpl}, @@ -32,7 +32,10 @@ impl NetherForestVegetationFeature { ) -> bool { let state = chunk.get_block_state(&pos.down().0); - if !state.to_block().is_tagged_with("minecraft:nylium").unwrap() { + if !state + .to_block() + .is_tagged_with_by_tag(&tag::Block::MINECRAFT_NYLIUM) + { return false; } let mut result = false; diff --git a/pumpkin-world/src/generation/feature/features/tree/mod.rs b/pumpkin-world/src/generation/feature/features/tree/mod.rs index 8f0848343..8902244e6 100644 --- a/pumpkin-world/src/generation/feature/features/tree/mod.rs +++ b/pumpkin-world/src/generation/feature/features/tree/mod.rs @@ -2,7 +2,8 @@ use std::sync::Arc; use decorator::TreeDecorator; use foliage::FoliagePlacer; -use pumpkin_data::{Block, BlockState, tag::Tagable}; +use pumpkin_data::tag; +use pumpkin_data::{Block, BlockState, tag::Taggable}; use pumpkin_util::{math::position::BlockPos, random::RandomGenerator}; use serde::Deserialize; use trunk::TrunkPlacer; @@ -59,18 +60,15 @@ impl TreeFeature { } pub fn can_replace_or_log(state: &BlockState, block: &Block) -> bool { - Self::can_replace(state, block) || block.is_tagged_with("minecraft:logs").unwrap() + Self::can_replace(state, block) || block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_LOGS) } pub fn is_air_or_leaves(state: &BlockState, block: &Block) -> bool { - state.is_air() || block.is_tagged_with("minecraft:leaves").unwrap() + state.is_air() || block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_LEAVES) } pub fn can_replace(state: &BlockState, block: &Block) -> bool { - state.is_air() - || block - .is_tagged_with("minecraft:replaceable_by_trees") - .unwrap() + state.is_air() || block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_REPLACEABLE_BY_TREES) } #[expect(clippy::too_many_arguments)] diff --git a/pumpkin-world/src/generation/feature/features/tree/trunk/mod.rs b/pumpkin-world/src/generation/feature/features/tree/trunk/mod.rs index 699a7a4c3..ce07e5125 100644 --- a/pumpkin-world/src/generation/feature/features/tree/trunk/mod.rs +++ b/pumpkin-world/src/generation/feature/features/tree/trunk/mod.rs @@ -1,7 +1,8 @@ use std::sync::Arc; use fancy::FancyTrunkPlacer; -use pumpkin_data::{Block, BlockState, tag::Tagable}; +use pumpkin_data::tag; +use pumpkin_data::{Block, BlockState, tag::Taggable}; use pumpkin_util::{ math::position::BlockPos, random::{RandomGenerator, RandomImpl}, @@ -56,7 +57,7 @@ impl TrunkPlacer { ) { let block = chunk.get_block_state(&pos.0).to_block(); if force_dirt - || !(block.is_tagged_with("minecraft:dirt").unwrap() + || !(block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_DIRT) && block != &Block::GRASS_BLOCK && block != &Block::MYCELIUM) { diff --git a/pumpkin-world/src/generation/proto_chunk.rs b/pumpkin-world/src/generation/proto_chunk.rs index 026af72ef..f36842b5a 100644 --- a/pumpkin-world/src/generation/proto_chunk.rs +++ b/pumpkin-world/src/generation/proto_chunk.rs @@ -1,8 +1,9 @@ use std::sync::Arc; use async_trait::async_trait; +use pumpkin_data::tag; use pumpkin_data::{ - Block, BlockState, block_properties::blocks_movement, chunk::Biome, tag::Tagable, + Block, BlockState, block_properties::blocks_movement, chunk::Biome, tag::Taggable, }; use pumpkin_util::{ HeightMap, @@ -376,7 +377,7 @@ impl<'a> ProtoChunk<'a> { if blocks_movement(block_state) || block_state.is_liquid() { self.maybe_update_motion_blocking_height_map(pos); let block = Block::from_state_id(block_state.id); - if !block.is_tagged_with("minecraft:leaves").unwrap() { + if !block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_LEAVES) { { self.maybe_update_motion_blocking_no_leaves_height_map(pos); } diff --git a/pumpkin-world/src/generation/rule/tag_match.rs b/pumpkin-world/src/generation/rule/tag_match.rs index b45f57e08..018f3ca9f 100644 --- a/pumpkin-world/src/generation/rule/tag_match.rs +++ b/pumpkin-world/src/generation/rule/tag_match.rs @@ -1,4 +1,4 @@ -use pumpkin_data::{Block, BlockState, tag::Tagable}; +use pumpkin_data::{Block, BlockState, tag::Taggable}; use serde::Deserialize; #[derive(Deserialize)] diff --git a/pumpkin-world/src/generation/rule_test.rs b/pumpkin-world/src/generation/rule_test.rs index 0c29583eb..9d0331e50 100644 --- a/pumpkin-world/src/generation/rule_test.rs +++ b/pumpkin-world/src/generation/rule_test.rs @@ -1,4 +1,4 @@ -use pumpkin_data::{Block, tag::Tagable}; +use pumpkin_data::{Block, tag::Taggable}; use serde::Deserialize; /// Rule tests are used in structure or features generation to check if a block state matches some condition. diff --git a/pumpkin-world/src/item/categories.rs b/pumpkin-world/src/item/categories.rs index c67b4c82f..9ee75f33e 100644 --- a/pumpkin-world/src/item/categories.rs +++ b/pumpkin-world/src/item/categories.rs @@ -1,4 +1,4 @@ -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; use crate::item::ItemStack; diff --git a/pumpkin/src/block/blocks/bamboo.rs b/pumpkin/src/block/blocks/bamboo.rs index 9f79b14db..fa2b796bc 100644 --- a/pumpkin/src/block/blocks/bamboo.rs +++ b/pumpkin/src/block/blocks/bamboo.rs @@ -1,5 +1,6 @@ use async_trait::async_trait; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag; +use pumpkin_data::tag::Taggable; use pumpkin_macros::pumpkin_block; use crate::block::pumpkin_block::{CanPlaceAtArgs, PumpkinBlock}; @@ -11,8 +12,6 @@ pub struct BambooBlock; impl PumpkinBlock for BambooBlock { async fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { let block_below = args.block_accessor.get_block(&args.position.down()).await; - block_below - .is_tagged_with("minecraft:bamboo_plantable_on") - .unwrap() + block_below.is_tagged_with_by_tag(&tag::Block::MINECRAFT_BAMBOO_PLANTABLE_ON) } } diff --git a/pumpkin/src/block/blocks/cactus.rs b/pumpkin/src/block/blocks/cactus.rs index 4175723e3..77edcc7df 100644 --- a/pumpkin/src/block/blocks/cactus.rs +++ b/pumpkin/src/block/blocks/cactus.rs @@ -3,8 +3,8 @@ use pumpkin_data::block_properties::{ BlockProperties, CactusLikeProperties, EnumVariants, Integer0To15, }; use pumpkin_data::damage::DamageType; -use pumpkin_data::tag::Tagable; -use pumpkin_data::{Block, BlockDirection}; +use pumpkin_data::tag::Taggable; +use pumpkin_data::{Block, BlockDirection, tag}; use pumpkin_macros::pumpkin_block; use pumpkin_util::math::position::BlockPos; use pumpkin_world::BlockStateId; @@ -103,6 +103,6 @@ async fn can_place_at(world: &dyn BlockAccessor, block_pos: &BlockPos) -> bool { } let block = world.get_block(&block_pos.down()).await; // TODO: use tags - (block == &Block::CACTUS || block.is_tagged_with("minecraft:sand").unwrap()) + (block == &Block::CACTUS || block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_SAND)) && !world.get_block_state(&block_pos.up()).await.is_liquid() } diff --git a/pumpkin/src/block/blocks/chiseled_bookshelf.rs b/pumpkin/src/block/blocks/chiseled_bookshelf.rs index 185084332..fc9775ec6 100644 --- a/pumpkin/src/block/blocks/chiseled_bookshelf.rs +++ b/pumpkin/src/block/blocks/chiseled_bookshelf.rs @@ -5,7 +5,8 @@ use pumpkin_data::{ block_properties::{BlockProperties, ChiseledBookshelfLikeProperties, HorizontalFacing}, item::Item, sound::{Sound, SoundCategory}, - tag::Tagable, + tag, + tag::Taggable, }; use pumpkin_inventory::screen_handler::InventoryPlayer; use pumpkin_macros::pumpkin_block; @@ -81,8 +82,7 @@ impl PumpkinBlock for ChiseledBookshelfBlock { .lock() .await .get_item() - .is_tagged_with("minecraft:bookshelf_books") - .unwrap_or(false) + .is_tagged_with_by_tag(&tag::Item::MINECRAFT_BOOKSHELF_BOOKS) { return BlockActionResult::PassToDefaultBlockAction; } diff --git a/pumpkin/src/block/blocks/doors.rs b/pumpkin/src/block/blocks/doors.rs index 6f425bb3a..ed5b773e5 100644 --- a/pumpkin/src/block/blocks/doors.rs +++ b/pumpkin/src/block/blocks/doors.rs @@ -1,5 +1,4 @@ use async_trait::async_trait; -use pumpkin_data::Block; use pumpkin_data::BlockDirection; use pumpkin_data::HorizontalFacingExt; use pumpkin_data::block_properties::Axis; @@ -10,8 +9,9 @@ use pumpkin_data::block_properties::HorizontalFacing; use pumpkin_data::sound::Sound; use pumpkin_data::sound::SoundCategory; use pumpkin_data::tag::RegistryKey; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; use pumpkin_data::tag::get_tag_values; +use pumpkin_data::{Block, tag}; use pumpkin_macros::pumpkin_block_from_tag; use pumpkin_util::math::position::BlockPos; use pumpkin_world::BlockStateId; @@ -86,14 +86,14 @@ fn can_open_door(block: &Block) -> bool { // Todo: The sounds should be from BlockSetType fn get_sound(block: &Block, open: bool) -> Sound { if open { - if block.is_tagged_with("minecraft:wooden_doors").unwrap() { + if block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_WOODEN_DOORS) { Sound::BlockWoodenDoorOpen } else if block == &Block::IRON_DOOR { Sound::BlockIronDoorOpen } else { Sound::BlockCopperDoorOpen } - } else if block.is_tagged_with("minecraft:wooden_doors").unwrap() { + } else if block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_WOODEN_DOORS) { Sound::BlockWoodenDoorClose } else if block == &Block::IRON_DOOR { Sound::BlockIronDoorClose @@ -125,15 +125,13 @@ async fn get_hinge( let has_left_door = world .get_block(&left_pos) .await - .is_tagged_with("minecraft:doors") - .unwrap() + .is_tagged_with_by_tag(&tag::Block::MINECRAFT_DOORS) && DoorProperties::from_state_id(left_state.id, left_block).half == DoubleBlockHalf::Lower; let has_right_door = world .get_block(&right_pos) .await - .is_tagged_with("minecraft:doors") - .unwrap() + .is_tagged_with_by_tag(&tag::Block::MINECRAFT_DOORS) && DoorProperties::from_state_id(right_state.id, right_block).half == DoubleBlockHalf::Lower; diff --git a/pumpkin/src/block/blocks/fence_gates.rs b/pumpkin/src/block/blocks/fence_gates.rs index 21d4631be..6e39cb7dd 100644 --- a/pumpkin/src/block/blocks/fence_gates.rs +++ b/pumpkin/src/block/blocks/fence_gates.rs @@ -6,8 +6,9 @@ use crate::block::pumpkin_block::OnPlaceArgs; use crate::entity::player::Player; use async_trait::async_trait; use pumpkin_data::block_properties::BlockProperties; +use pumpkin_data::tag; use pumpkin_data::tag::RegistryKey; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; use pumpkin_data::tag::get_tag_values; use pumpkin_macros::pumpkin_block_from_tag; use pumpkin_util::math::position::BlockPos; @@ -97,8 +98,8 @@ async fn is_in_wall(args: &GetStateForNeighborUpdateArgs<'_>) -> FenceGateProper let neighbor_right = args.world.get_block(&side_offset_right).await; let neighbor_left = args.world.get_block(&side_offset_left).await; - fence_props.in_wall = neighbor_left.is_tagged_with("minecraft:walls").unwrap() - || neighbor_right.is_tagged_with("minecraft:walls").unwrap(); + fence_props.in_wall = neighbor_left.is_tagged_with_by_tag(&tag::Block::MINECRAFT_WALLS) + || neighbor_right.is_tagged_with_by_tag(&tag::Block::MINECRAFT_WALLS); } fence_props diff --git a/pumpkin/src/block/blocks/fences.rs b/pumpkin/src/block/blocks/fences.rs index 933651c14..396e2eb82 100644 --- a/pumpkin/src/block/blocks/fences.rs +++ b/pumpkin/src/block/blocks/fences.rs @@ -1,13 +1,13 @@ use crate::block::pumpkin_block::GetStateForNeighborUpdateArgs; use crate::block::pumpkin_block::OnPlaceArgs; use async_trait::async_trait; -use pumpkin_data::Block; use pumpkin_data::BlockDirection; use pumpkin_data::BlockState; use pumpkin_data::block_properties::BlockProperties; use pumpkin_data::tag::RegistryKey; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; use pumpkin_data::tag::get_tag_values; +use pumpkin_data::{Block, tag}; use pumpkin_util::math::position::BlockPos; use pumpkin_world::BlockStateId; @@ -78,7 +78,7 @@ fn connects_to(from: &Block, to: &Block, to_state: &BlockState, direction: Block return true; } - if to.is_tagged_with("c:fence_gates").unwrap() { + if to.is_tagged_with_by_tag(&tag::Block::C_FENCE_GATES) { let fence_gate_props = FenceGateProperties::from_state_id(to_state.id, to); if BlockDirection::from_cardinal_direction(fence_gate_props.facing).to_axis() == direction.rotate_clockwise().to_axis() @@ -87,5 +87,5 @@ fn connects_to(from: &Block, to: &Block, to_state: &BlockState, direction: Block } } - *from != Block::NETHER_BRICK_FENCE && to.is_tagged_with("c:fences/wooden").unwrap() + *from != Block::NETHER_BRICK_FENCE && to.is_tagged_with_by_tag(&tag::Block::C_FENCES_WOODEN) } diff --git a/pumpkin/src/block/blocks/fire/mod.rs b/pumpkin/src/block/blocks/fire/mod.rs index 82044b580..75f446ccd 100644 --- a/pumpkin/src/block/blocks/fire/mod.rs +++ b/pumpkin/src/block/blocks/fire/mod.rs @@ -1,8 +1,8 @@ use std::sync::Arc; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; use pumpkin_data::world::WorldEvent; -use pumpkin_data::{Block, BlockDirection}; +use pumpkin_data::{Block, BlockDirection, tag}; use pumpkin_registry::VanillaDimensionType; use pumpkin_util::math::position::BlockPos; use pumpkin_util::random::RandomGenerator; @@ -41,7 +41,7 @@ impl FireBlockBase { pub async fn is_soul_fire(world: &Arc, block_pos: &BlockPos) -> bool { let block = world.get_block(&block_pos.down()).await; - block.is_tagged_with("minecraft:soul_fire_base_blocks") == Some(true) + block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_SOUL_FIRE_BASE_BLOCKS) } pub async fn can_place_at(world: &Arc, block_pos: &BlockPos) -> bool { diff --git a/pumpkin/src/block/blocks/fire/soul_fire.rs b/pumpkin/src/block/blocks/fire/soul_fire.rs index 0919c3479..f79ab45ad 100644 --- a/pumpkin/src/block/blocks/fire/soul_fire.rs +++ b/pumpkin/src/block/blocks/fire/soul_fire.rs @@ -1,6 +1,6 @@ use async_trait::async_trait; -use pumpkin_data::Block; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; +use pumpkin_data::{Block, tag}; use pumpkin_macros::pumpkin_block; use pumpkin_world::BlockStateId; @@ -16,9 +16,7 @@ pub struct SoulFireBlock; impl SoulFireBlock { #[must_use] pub fn is_soul_base(block: &Block) -> bool { - block - .is_tagged_with("minecraft:soul_fire_base_blocks") - .unwrap() + block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_SOUL_FIRE_BASE_BLOCKS) } } diff --git a/pumpkin/src/block/blocks/glass_panes.rs b/pumpkin/src/block/blocks/glass_panes.rs index 1ac445ee0..3dc99a611 100644 --- a/pumpkin/src/block/blocks/glass_panes.rs +++ b/pumpkin/src/block/blocks/glass_panes.rs @@ -1,12 +1,12 @@ use crate::block::pumpkin_block::GetStateForNeighborUpdateArgs; use crate::block::pumpkin_block::OnPlaceArgs; use async_trait::async_trait; -use pumpkin_data::Block; use pumpkin_data::BlockDirection; use pumpkin_data::block_properties::BlockProperties; use pumpkin_data::tag::RegistryKey; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; use pumpkin_data::tag::get_tag_values; +use pumpkin_data::{Block, tag}; use pumpkin_util::math::position::BlockPos; use pumpkin_world::BlockStateId; @@ -56,9 +56,9 @@ pub async fn compute_pane_state( let connected = other_block == block || other_block_state.is_side_solid(direction.opposite()) - || other_block.is_tagged_with("c:glass_panes").unwrap() + || other_block.is_tagged_with_by_tag(&tag::Block::C_GLASS_PANES) || other_block == &Block::IRON_BARS - || other_block.is_tagged_with("minecraft:walls").unwrap(); + || other_block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_WALLS); match direction { BlockDirection::North => pane_props.north = connected, diff --git a/pumpkin/src/block/blocks/iron_bars.rs b/pumpkin/src/block/blocks/iron_bars.rs index 87b823668..ce7eda0ab 100644 --- a/pumpkin/src/block/blocks/iron_bars.rs +++ b/pumpkin/src/block/blocks/iron_bars.rs @@ -1,10 +1,10 @@ use crate::block::pumpkin_block::GetStateForNeighborUpdateArgs; use crate::block::pumpkin_block::OnPlaceArgs; use async_trait::async_trait; -use pumpkin_data::Block; use pumpkin_data::BlockDirection; use pumpkin_data::block_properties::BlockProperties; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; +use pumpkin_data::{Block, tag}; use pumpkin_macros::pumpkin_block; use pumpkin_util::math::position::BlockPos; use pumpkin_world::BlockStateId; @@ -47,8 +47,8 @@ pub async fn compute_bars_state( let connected = other_block == block || other_block_state.is_side_solid(direction.opposite()) - || other_block.is_tagged_with("c:glass_panes").unwrap() - || other_block.is_tagged_with("minecraft:walls").unwrap(); + || other_block.is_tagged_with_by_tag(&tag::Block::C_GLASS_PANES) + || other_block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_WALLS); match direction { BlockDirection::North => bars_props.north = connected, diff --git a/pumpkin/src/block/blocks/plant/dry_vegetation.rs b/pumpkin/src/block/blocks/plant/dry_vegetation.rs index de273976a..33ee24a8e 100644 --- a/pumpkin/src/block/blocks/plant/dry_vegetation.rs +++ b/pumpkin/src/block/blocks/plant/dry_vegetation.rs @@ -1,5 +1,6 @@ use async_trait::async_trait; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag; +use pumpkin_data::tag::Taggable; use crate::block::pumpkin_block::{BlockMetadata, CanPlaceAtArgs, PumpkinBlock}; @@ -19,8 +20,6 @@ impl BlockMetadata for DryVegetationBlock { impl PumpkinBlock for DryVegetationBlock { async fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { let block_below = args.block_accessor.get_block(&args.position.down()).await; - block_below - .is_tagged_with("minecraft:dry_vegetation_may_place_on") - .unwrap() + block_below.is_tagged_with_by_tag(&tag::Block::MINECRAFT_DRY_VEGETATION_MAY_PLACE_ON) } } diff --git a/pumpkin/src/block/blocks/plant/flowerbed.rs b/pumpkin/src/block/blocks/plant/flowerbed.rs index 3824c31cb..80da2e3aa 100644 --- a/pumpkin/src/block/blocks/plant/flowerbed.rs +++ b/pumpkin/src/block/blocks/plant/flowerbed.rs @@ -1,6 +1,6 @@ use async_trait::async_trait; -use pumpkin_data::Block; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; +use pumpkin_data::{Block, tag}; use pumpkin_world::BlockStateId; use crate::block::blocks::plant::PlantBlockBase; @@ -30,7 +30,8 @@ impl BlockMetadata for FlowerbedBlock { impl PumpkinBlock for FlowerbedBlock { async fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { let block_below = args.block_accessor.get_block(&args.position.down()).await; - block_below.is_tagged_with("minecraft:dirt").unwrap() || block_below == &Block::FARMLAND + block_below.is_tagged_with_by_tag(&tag::Block::MINECRAFT_DIRT) + || block_below == &Block::FARMLAND } async fn can_update_at(&self, args: CanUpdateAtArgs<'_>) -> bool { diff --git a/pumpkin/src/block/blocks/plant/mod.rs b/pumpkin/src/block/blocks/plant/mod.rs index 8fccec03a..4b7fa34c7 100644 --- a/pumpkin/src/block/blocks/plant/mod.rs +++ b/pumpkin/src/block/blocks/plant/mod.rs @@ -1,4 +1,4 @@ -use pumpkin_data::{Block, tag::Tagable}; +use pumpkin_data::{Block, tag, tag::Taggable}; use pumpkin_util::math::position::BlockPos; use pumpkin_world::{BlockStateId, world::BlockAccessor}; @@ -22,7 +22,7 @@ pub mod tall_plant; trait PlantBlockBase { async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { let block = block_accessor.get_block(pos).await; - block.is_tagged_with("minecraft:dirt").unwrap() || block == &Block::FARMLAND + block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_DIRT) || block == &Block::FARMLAND } async fn get_state_for_neighbor_update( diff --git a/pumpkin/src/block/blocks/plant/mushroom_plant.rs b/pumpkin/src/block/blocks/plant/mushroom_plant.rs index d8332783f..4803b1441 100644 --- a/pumpkin/src/block/blocks/plant/mushroom_plant.rs +++ b/pumpkin/src/block/blocks/plant/mushroom_plant.rs @@ -1,5 +1,6 @@ use async_trait::async_trait; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag; +use pumpkin_data::tag::Taggable; use crate::block::pumpkin_block::{BlockMetadata, CanPlaceAtArgs, PumpkinBlock}; @@ -19,10 +20,7 @@ impl BlockMetadata for MushroomPlantBlock { impl PumpkinBlock for MushroomPlantBlock { async fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { let block_below = args.block_accessor.get_block(&args.position.down()).await; - if block_below - .is_tagged_with("minecraft:mushroom_grow_block") - .unwrap() - { + if block_below.is_tagged_with_by_tag(&tag::Block::MINECRAFT_MUSHROOM_GROW_BLOCK) { return true; } // TODO: Check light level and isOpaqueFullCube diff --git a/pumpkin/src/block/blocks/plant/nether_wart.rs b/pumpkin/src/block/blocks/plant/nether_wart.rs index 6685f444f..eb244df03 100644 --- a/pumpkin/src/block/blocks/plant/nether_wart.rs +++ b/pumpkin/src/block/blocks/plant/nether_wart.rs @@ -1,5 +1,5 @@ use async_trait::async_trait; -use pumpkin_data::tag::Tagable; +use pumpkin_data::Block; use pumpkin_macros::pumpkin_block; use pumpkin_util::math::position::BlockPos; use pumpkin_world::BlockStateId; @@ -34,6 +34,6 @@ impl PumpkinBlock for NetherWartBlock { impl PlantBlockBase for NetherWartBlock { async fn can_plant_on_top(&self, block_accessor: &dyn BlockAccessor, pos: &BlockPos) -> bool { let block = block_accessor.get_block(pos).await; - block.is_tagged_with("minecraft:soul_sand").unwrap() + block == &Block::SOUL_SAND } } diff --git a/pumpkin/src/block/blocks/plant/roots.rs b/pumpkin/src/block/blocks/plant/roots.rs index 809184a37..0bd06220d 100644 --- a/pumpkin/src/block/blocks/plant/roots.rs +++ b/pumpkin/src/block/blocks/plant/roots.rs @@ -1,6 +1,6 @@ use async_trait::async_trait; -use pumpkin_data::Block; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; +use pumpkin_data::{Block, tag}; use crate::block::pumpkin_block::{BlockMetadata, CanPlaceAtArgs, PumpkinBlock}; @@ -20,9 +20,9 @@ impl BlockMetadata for RootsBlock { impl PumpkinBlock for RootsBlock { async fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { let block_below = args.block_accessor.get_block(&args.position.down()).await; - block_below.is_tagged_with("minecraft:nylium").unwrap() + block_below.is_tagged_with_by_tag(&tag::Block::MINECRAFT_NYLIUM) || block_below == &Block::SOUL_SOIL - || block_below.is_tagged_with("minecraft:dirt").unwrap() + || block_below.is_tagged_with_by_tag(&tag::Block::MINECRAFT_DIRT) || block_below == &Block::FARMLAND } } diff --git a/pumpkin/src/block/blocks/plant/sea_pickles.rs b/pumpkin/src/block/blocks/plant/sea_pickles.rs index c3f761fa2..423be23c6 100644 --- a/pumpkin/src/block/blocks/plant/sea_pickles.rs +++ b/pumpkin/src/block/blocks/plant/sea_pickles.rs @@ -10,8 +10,8 @@ use async_trait::async_trait; use pumpkin_data::block_properties::{BlockProperties, Integer1To4}; use pumpkin_data::entity::EntityPose; use pumpkin_data::item::Item; -use pumpkin_data::tag::Tagable; -use pumpkin_data::{Block, BlockDirection}; +use pumpkin_data::tag::Taggable; +use pumpkin_data::{Block, BlockDirection, tag}; use pumpkin_macros::pumpkin_block; use pumpkin_util::math::position::BlockPos; use pumpkin_world::BlockStateId; @@ -32,8 +32,7 @@ impl PumpkinBlock for SeaPickleBlock { .world .get_block(&args.position.down()) .await - .is_tagged_with("minecraft:coral_blocks") - .unwrap() + .is_tagged_with_by_tag(&tag::Block::MINECRAFT_CORAL_BLOCKS) || !SeaPickleProperties::from_state_id( args.world.get_block_state_id(args.position).await, args.block, @@ -64,8 +63,7 @@ impl PumpkinBlock for SeaPickleBlock { .world .get_block(&lv.down()) .await - .is_tagged_with("minecraft:coral_blocks") - .unwrap() + .is_tagged_with_by_tag(&tag::Block::MINECRAFT_CORAL_BLOCKS) { continue; } diff --git a/pumpkin/src/block/blocks/plant/short_plant.rs b/pumpkin/src/block/blocks/plant/short_plant.rs index 2e5311336..da313a573 100644 --- a/pumpkin/src/block/blocks/plant/short_plant.rs +++ b/pumpkin/src/block/blocks/plant/short_plant.rs @@ -1,6 +1,6 @@ use async_trait::async_trait; -use pumpkin_data::Block; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; +use pumpkin_data::{Block, tag}; use crate::block::pumpkin_block::{BlockMetadata, CanPlaceAtArgs, PumpkinBlock}; @@ -20,6 +20,7 @@ impl BlockMetadata for ShortPlantBlock { impl PumpkinBlock for ShortPlantBlock { async fn can_place_at(&self, args: CanPlaceAtArgs<'_>) -> bool { let block_below = args.block_accessor.get_block(&args.position.down()).await; - block_below.is_tagged_with("minecraft:dirt").unwrap() || block_below == &Block::FARMLAND + block_below.is_tagged_with_by_tag(&tag::Block::MINECRAFT_DIRT) + || block_below == &Block::FARMLAND } } diff --git a/pumpkin/src/block/blocks/plant/tall_plant.rs b/pumpkin/src/block/blocks/plant/tall_plant.rs index 7347964ab..a3d534107 100644 --- a/pumpkin/src/block/blocks/plant/tall_plant.rs +++ b/pumpkin/src/block/blocks/plant/tall_plant.rs @@ -1,6 +1,6 @@ use async_trait::async_trait; -use pumpkin_data::Block; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; +use pumpkin_data::{Block, tag}; use crate::block::pumpkin_block::{BlockMetadata, CanPlaceAtArgs, PumpkinBlock}; @@ -47,6 +47,7 @@ impl PumpkinBlock for TallPlantBlock { } } let block_below = args.block_accessor.get_block(&args.position.down()).await; - block_below.is_tagged_with("minecraft:dirt").unwrap() || block_below == &Block::FARMLAND + block_below.is_tagged_with_by_tag(&tag::Block::MINECRAFT_DIRT) + || block_below == &Block::FARMLAND } } diff --git a/pumpkin/src/block/blocks/redstone/rails/mod.rs b/pumpkin/src/block/blocks/redstone/rails/mod.rs index 620498114..a978a3ed5 100644 --- a/pumpkin/src/block/blocks/redstone/rails/mod.rs +++ b/pumpkin/src/block/blocks/redstone/rails/mod.rs @@ -1,11 +1,11 @@ -use pumpkin_data::Block; use pumpkin_data::block_properties::BlockProperties; use pumpkin_data::block_properties::HorizontalFacing; use pumpkin_data::block_properties::PoweredRailLikeProperties; use pumpkin_data::block_properties::RailLikeProperties; use pumpkin_data::block_properties::RailShape; use pumpkin_data::block_properties::StraightRailShape; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; +use pumpkin_data::{Block, tag}; use pumpkin_util::math::position::BlockPos; use pumpkin_world::BlockStateId; @@ -28,7 +28,7 @@ struct Rail { impl Rail { async fn find_with_elevation(world: &World, position: BlockPos) -> Option { let (block, block_state) = world.get_block_and_state_id(&position).await; - if block.is_tagged_with("#minecraft:rails").unwrap() { + if block.is_tagged_with_by_tag(&tag::Item::MINECRAFT_RAILS) { let properties = RailProperties::new(block_state, block); return Some(Self { block, @@ -40,7 +40,7 @@ impl Rail { let pos = position.up(); let (block, block_state) = world.get_block_and_state_id(&pos).await; - if block.is_tagged_with("#minecraft:rails").unwrap() { + if block.is_tagged_with_by_tag(&tag::Item::MINECRAFT_RAILS) { let properties = RailProperties::new(block_state, block); return Some(Self { block, @@ -52,7 +52,7 @@ impl Rail { let pos = position.down(); let (block, block_state) = world.get_block_and_state_id(&pos).await; - if block.is_tagged_with("#minecraft:rails").unwrap() { + if block.is_tagged_with_by_tag(&tag::Item::MINECRAFT_RAILS) { let properties = RailProperties::new(block_state, block); return Some(Self { block, diff --git a/pumpkin/src/block/blocks/stairs.rs b/pumpkin/src/block/blocks/stairs.rs index c18cc8898..8ae67a0da 100644 --- a/pumpkin/src/block/blocks/stairs.rs +++ b/pumpkin/src/block/blocks/stairs.rs @@ -1,12 +1,12 @@ use async_trait::async_trait; -use pumpkin_data::BlockDirection; use pumpkin_data::block_properties::BlockHalf; use pumpkin_data::block_properties::BlockProperties; use pumpkin_data::block_properties::HorizontalFacing; use pumpkin_data::block_properties::StairShape; use pumpkin_data::tag::RegistryKey; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; use pumpkin_data::tag::get_tag_values; +use pumpkin_data::{BlockDirection, tag}; use pumpkin_macros::pumpkin_block_from_tag; use pumpkin_util::math::position::BlockPos; use pumpkin_world::BlockStateId; @@ -142,7 +142,6 @@ async fn get_stair_properties_if_exists( ) -> Option { let (block, block_state) = world.get_block_and_state_id(block_pos).await; block - .is_tagged_with("#minecraft:stairs") - .unwrap() + .is_tagged_with_by_tag(&tag::Block::MINECRAFT_STAIRS) .then(|| StairsProperties::from_state_id(block_state, block)) } diff --git a/pumpkin/src/block/blocks/sugar_cane.rs b/pumpkin/src/block/blocks/sugar_cane.rs index 8e85c235a..4856788ea 100644 --- a/pumpkin/src/block/blocks/sugar_cane.rs +++ b/pumpkin/src/block/blocks/sugar_cane.rs @@ -1,9 +1,10 @@ use async_trait::async_trait; use pumpkin_data::block_properties::HorizontalFacing; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; use pumpkin_data::{ Block, block_properties::{BlockProperties, CactusLikeProperties, EnumVariants, Integer0To15}, + tag, }; use pumpkin_macros::pumpkin_block; use pumpkin_util::math::position::BlockPos; @@ -91,8 +92,8 @@ async fn can_place_at(block_accessor: &dyn BlockAccessor, block_pos: &BlockPos) return true; } - if block_below.is_tagged_with("minecraft:dirt").unwrap() - || block_below.is_tagged_with("minecraft:sand").unwrap() + if block_below.is_tagged_with_by_tag(&tag::Block::MINECRAFT_DIRT) + || block_below.is_tagged_with_by_tag(&tag::Block::MINECRAFT_SAND) { for direction in HorizontalFacing::all() { let block = block_accessor diff --git a/pumpkin/src/block/blocks/trapdoor.rs b/pumpkin/src/block/blocks/trapdoor.rs index 9df3d59e1..6b1d4b8cc 100644 --- a/pumpkin/src/block/blocks/trapdoor.rs +++ b/pumpkin/src/block/blocks/trapdoor.rs @@ -4,11 +4,11 @@ use crate::block::registry::BlockActionResult; use crate::entity::player::Player; use crate::world::World; use async_trait::async_trait; -use pumpkin_data::Block; use pumpkin_data::BlockDirection; use pumpkin_data::block_properties::{BlockHalf, BlockProperties}; use pumpkin_data::sound::{Sound, SoundCategory}; -use pumpkin_data::tag::{RegistryKey, Tagable, get_tag_values}; +use pumpkin_data::tag::{RegistryKey, Taggable, get_tag_values}; +use pumpkin_data::{Block, tag}; use pumpkin_macros::pumpkin_block_from_tag; use pumpkin_util::math::position::BlockPos; use pumpkin_world::BlockStateId; @@ -50,14 +50,14 @@ fn can_open_trapdoor(block: &Block) -> bool { // Todo: The sounds should be from BlockSetType fn get_sound(block: &Block, open: bool) -> Sound { if open { - if block.is_tagged_with("minecraft:wooden_trapdoors").unwrap() { + if block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_WOODEN_TRAPDOORS) { Sound::BlockWoodenTrapdoorOpen } else if block == &Block::IRON_TRAPDOOR { Sound::BlockIronTrapdoorOpen } else { Sound::BlockCopperTrapdoorOpen } - } else if block.is_tagged_with("minecraft:wooden_trapdoors").unwrap() { + } else if block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_WOODEN_TRAPDOORS) { Sound::BlockWoodenTrapdoorClose } else if block == &Block::IRON_TRAPDOOR { Sound::BlockIronTrapdoorClose diff --git a/pumpkin/src/block/blocks/walls.rs b/pumpkin/src/block/blocks/walls.rs index 2dc0f07ee..d9cf98c68 100644 --- a/pumpkin/src/block/blocks/walls.rs +++ b/pumpkin/src/block/blocks/walls.rs @@ -1,7 +1,6 @@ use crate::block::pumpkin_block::GetStateForNeighborUpdateArgs; use crate::block::pumpkin_block::OnPlaceArgs; use async_trait::async_trait; -use pumpkin_data::Block; use pumpkin_data::BlockDirection; use pumpkin_data::BlockState; use pumpkin_data::block_properties::BlockProperties; @@ -11,8 +10,9 @@ use pumpkin_data::block_properties::NorthWallShape; use pumpkin_data::block_properties::SouthWallShape; use pumpkin_data::block_properties::WestWallShape; use pumpkin_data::tag::RegistryKey; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; use pumpkin_data::tag::get_tag_values; +use pumpkin_data::{Block, tag}; use pumpkin_macros::pumpkin_block_from_tag; use pumpkin_util::math::position::BlockPos; use pumpkin_world::BlockStateId; @@ -61,7 +61,7 @@ pub async fn compute_wall_state( let shape = if connected { let raise = if block_above_state.is_full_cube() { true - } else if block_above.is_tagged_with("minecraft:walls").unwrap() { + } else if block_above.is_tagged_with_by_tag(&tag::Block::MINECRAFT_WALLS) { let other_props = WallProperties::from_state_id(block_above_state.id, block_above); match direction { HorizontalFacing::North => other_props.north != NorthWallShape::None, @@ -69,8 +69,8 @@ pub async fn compute_wall_state( HorizontalFacing::East => other_props.east != EastWallShape::None, HorizontalFacing::West => other_props.west != WestWallShape::None, } - } else if block_above.is_tagged_with("c:glass_panes").unwrap() - || block_above.is_tagged_with("minecraft:fences").unwrap() + } else if block_above.is_tagged_with_by_tag(&tag::Block::C_GLASS_PANES) + || block_above.is_tagged_with_by_tag(&tag::Block::MINECRAFT_FENCES) || block_above == &Block::IRON_BARS { let other_props = @@ -81,7 +81,7 @@ pub async fn compute_wall_state( HorizontalFacing::East => other_props.east, HorizontalFacing::West => other_props.west, } - } else if block_above.is_tagged_with("minecraft:fence_gates").unwrap() { + } else if block_above.is_tagged_with_by_tag(&tag::Block::MINECRAFT_FENCE_GATES) { let other_props = FenceGateProperties::from_state_id(block_above_state.id, block_above); // gate is perp to connected direction @@ -124,10 +124,10 @@ pub async fn compute_wall_state( wall_props.up = if !(cross || connected_north_south || connected_east_west) { true - } else if block_above.is_tagged_with("minecraft:walls").unwrap() { + } else if block_above.is_tagged_with_by_tag(&tag::Block::MINECRAFT_WALLS) { let other_props = WallProperties::from_state_id(block_above_state.id, block_above); other_props.up - } else if block_above.is_tagged_with("minecraft:fence_gates").unwrap() { + } else if block_above.is_tagged_with_by_tag(&tag::Block::MINECRAFT_FENCE_GATES) { let other_props = FenceGateProperties::from_state_id(block_above_state.id, block_above); if other_props.open { false @@ -154,12 +154,12 @@ fn is_connected( || other_block_state.is_side_solid(BlockDirection::from_cardinal_direction( direction.opposite(), )) - || other_block.is_tagged_with("minecraft:walls").unwrap() + || other_block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_WALLS) || other_block == &Block::IRON_BARS - || other_block.is_tagged_with("c:glass_panes").unwrap(); + || other_block.is_tagged_with_by_tag(&tag::Block::C_GLASS_PANES); // fence gates do not pass is_side_solid check - if !connected && other_block.is_tagged_with("minecraft:fence_gates").unwrap() { + if !connected && other_block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_FENCE_GATES) { let fence_props = FenceGateProperties::from_state_id(other_block_state.id, other_block); if fence_props.facing == direction.rotate_clockwise() || fence_props.facing == direction.rotate_counter_clockwise() diff --git a/pumpkin/src/command/args/block.rs b/pumpkin/src/command/args/block.rs index a06083552..69afdaee5 100644 --- a/pumpkin/src/command/args/block.rs +++ b/pumpkin/src/command/args/block.rs @@ -1,6 +1,6 @@ use async_trait::async_trait; use pumpkin_data::Block; -use pumpkin_data::tag::{RegistryKey, get_tag_values}; +use pumpkin_data::tag::{RegistryKey, get_tag_ids}; use pumpkin_protocol::java::client::play::{ArgumentType, CommandSuggestion, SuggestionProviders}; use pumpkin_util::text::TextComponent; @@ -134,52 +134,43 @@ impl<'a> FindArg<'a> for BlockPredicateArgumentConsumer { fn find_arg(args: &'a super::ConsumedArgs, name: &str) -> Result { match args.get(name) { - Some(Arg::BlockPredicate(name)) => { - name.strip_prefix("#").map_or_else( - || { - Block::from_name(name).map_or_else( - || { - if name.starts_with("minecraft:") { - Err(CommandError::CommandFailed(Box::new( - TextComponent::translate( - "argument.block.id.invalid", - [TextComponent::text((*name).to_string())], - ), - ))) - } else { - Err(CommandError::CommandFailed(Box::new( - TextComponent::translate( - "argument.block.id.invalid", - [TextComponent::text("minecraft:".to_string() + *name)], - ), - ))) - } - }, - |block| Ok(Some(BlockPredicate::Block(block.id))), - ) - }, - |tag| { - get_tag_values(RegistryKey::Block, tag).map_or_else( - || { + Some(Arg::BlockPredicate(name)) => name.strip_prefix("#").map_or_else( + || { + Block::from_name(name).map_or_else( + || { + if name.starts_with("minecraft:") { Err(CommandError::CommandFailed(Box::new( TextComponent::translate( - "arguments.block.tag.unknown", - [TextComponent::text((*tag).to_string())], + "argument.block.id.invalid", + [TextComponent::text((*name).to_string())], ), ))) - }, - |blocks| { - let mut block_ids = Vec::with_capacity(blocks.len()); - // TODO it will be slow to check name str, we should make a tag list of ids - for block_name in blocks { - block_ids.push(Block::from_name(block_name).unwrap().id); - } - Ok(Some(BlockPredicate::Tag(block_ids))) - }, - ) - }, - ) - } + } else { + Err(CommandError::CommandFailed(Box::new( + TextComponent::translate( + "argument.block.id.invalid", + [TextComponent::text("minecraft:".to_string() + *name)], + ), + ))) + } + }, + |block| Ok(Some(BlockPredicate::Block(block.id))), + ) + }, + |tag| { + get_tag_ids(RegistryKey::Block, tag).map_or_else( + || { + Err(CommandError::CommandFailed(Box::new( + TextComponent::translate( + "arguments.block.tag.unknown", + [TextComponent::text((*tag).to_string())], + ), + ))) + }, + |blocks| Ok(Some(BlockPredicate::Tag(blocks.to_vec()))), + ) + }, + ), _ => Ok(None), } } diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index e5bd1971e..dcece2031 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -23,8 +23,8 @@ use pumpkin_data::entity::{EffectType, EntityPose, EntityStatus, EntityType}; use pumpkin_data::item::Operation; use pumpkin_data::particle::Particle; use pumpkin_data::sound::{Sound, SoundCategory}; -use pumpkin_data::tag::Tagable; -use pumpkin_data::{Block, BlockState}; +use pumpkin_data::tag::Taggable; +use pumpkin_data::{Block, BlockState, tag}; use pumpkin_inventory::equipment_slot::EquipmentSlot; use pumpkin_inventory::player::{ player_inventory::PlayerInventory, player_screen_handler::PlayerScreenHandler, @@ -551,7 +551,7 @@ impl Player { let block = self.world().await.get_block(&respawn_point.position).await; if respawn_point.dimension == VanillaDimensionType::Overworld - && block.is_tagged_with("#minecraft:beds").unwrap() + && block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_BEDS) { // TODO: calculate respawn position Some((respawn_point.position.to_f64(), respawn_point.yaw)) diff --git a/pumpkin/src/item/items/axe.rs b/pumpkin/src/item/items/axe.rs index 31b933948..872618565 100644 --- a/pumpkin/src/item/items/axe.rs +++ b/pumpkin/src/item/items/axe.rs @@ -2,12 +2,12 @@ use crate::entity::player::Player; use crate::item::pumpkin_item::{ItemMetadata, PumpkinItem}; use crate::server::Server; use async_trait::async_trait; -use pumpkin_data::Block; use pumpkin_data::BlockDirection; use pumpkin_data::block_properties::BlockProperties; use pumpkin_data::block_properties::{OakDoorLikeProperties, PaleOakWoodLikeProperties}; use pumpkin_data::item::Item; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; +use pumpkin_data::{Block, tag}; use pumpkin_util::math::position::BlockPos; use pumpkin_world::world::BlockFlags; @@ -15,15 +15,7 @@ pub struct AxeItem; impl ItemMetadata for AxeItem { fn ids() -> Box<[u16]> { - Item::get_tag_values("#minecraft:axes") - .unwrap() - .iter() - .map(|key| { - Item::from_registry_key(key) - .expect("We just got this key from the registry") - .id - }) - .collect() + tag::Item::MINECRAFT_AXES.1.to_vec().into_boxed_slice() } } @@ -46,8 +38,8 @@ impl PumpkinItem for AxeItem { // If there is a strip equivalent. if replacement_block != 0 { - let new_block = Block::from_id(replacement_block); - let new_state_id = if block.is_tagged_with("#minecraft:logs") == Some(true) { + let new_block = &Block::from_id(replacement_block); + let new_state_id = if block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_LOGS) { let log_information = world.get_block_state_id(&location).await; let log_props = PaleOakWoodLikeProperties::from_state_id(log_information, block); // create new properties for the new log. @@ -61,7 +53,7 @@ impl PumpkinItem for AxeItem { new_log_properties.to_state_id(new_block) } // Let's check if It's a door - else if block.is_tagged_with("#minecraft:doors") == Some(true) { + else if block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_DOORS) { // get block state of the old log. let door_information = world.get_block_state_id(&location).await; // get the log properties diff --git a/pumpkin/src/item/items/hoe.rs b/pumpkin/src/item/items/hoe.rs index b1022e9cd..8a54805f0 100644 --- a/pumpkin/src/item/items/hoe.rs +++ b/pumpkin/src/item/items/hoe.rs @@ -4,11 +4,10 @@ use crate::entity::player::Player; use crate::item::pumpkin_item::{ItemMetadata, PumpkinItem}; use crate::server::Server; use async_trait::async_trait; -use pumpkin_data::Block; use pumpkin_data::BlockDirection; use pumpkin_data::entity::EntityType; use pumpkin_data::item::Item; -use pumpkin_data::tag::Tagable; +use pumpkin_data::{Block, tag}; use pumpkin_util::math::position::BlockPos; use pumpkin_world::item::ItemStack; use pumpkin_world::world::BlockFlags; @@ -19,16 +18,7 @@ pub struct HoeItem; impl ItemMetadata for HoeItem { fn ids() -> Box<[u16]> { - Item::get_tag_values("#minecraft:hoes") - .expect("This is a valid vanilla tag") - .iter() - .map(|key| { - Item::from_registry_key(key) - .expect("We just got this key from the registry") - .id - }) - .collect::>() - .into_boxed_slice() + tag::Item::MINECRAFT_HOES.1.to_vec().into_boxed_slice() } } diff --git a/pumpkin/src/item/items/honeycomb.rs b/pumpkin/src/item/items/honeycomb.rs index 9640e723e..abb6bed13 100644 --- a/pumpkin/src/item/items/honeycomb.rs +++ b/pumpkin/src/item/items/honeycomb.rs @@ -2,12 +2,12 @@ use crate::entity::player::Player; use crate::item::pumpkin_item::{ItemMetadata, PumpkinItem}; use crate::server::Server; use async_trait::async_trait; -use pumpkin_data::Block; use pumpkin_data::BlockDirection; use pumpkin_data::block_properties::BlockProperties; use pumpkin_data::block_properties::OakDoorLikeProperties; use pumpkin_data::item::Item; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; +use pumpkin_data::{Block, tag}; use pumpkin_util::math::position::BlockPos; use pumpkin_world::world::BlockFlags; @@ -41,8 +41,8 @@ impl PumpkinItem for HoneyCombItem { // create new properties for the new log. let new_block = &Block::from_id(replacement_block.unwrap()); - let new_state_id = if block.is_tagged_with("#minecraft:doors").is_some() - && block.is_tagged_with("#minecraft:doors").unwrap() + let new_state_id = if block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_DOORS) + && block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_DOORS) { // get block state of the old log. let door_information = world.get_block_state_id(&location).await; diff --git a/pumpkin/src/item/items/minecart.rs b/pumpkin/src/item/items/minecart.rs index 40f7b60d8..169747991 100644 --- a/pumpkin/src/item/items/minecart.rs +++ b/pumpkin/src/item/items/minecart.rs @@ -5,14 +5,14 @@ use crate::entity::player::Player; use crate::item::pumpkin_item::{ItemMetadata, PumpkinItem}; use crate::server::Server; use async_trait::async_trait; -use pumpkin_data::Block; use pumpkin_data::BlockDirection; use pumpkin_data::block_properties::{ BlockProperties, PoweredRailLikeProperties, RailLikeProperties, }; use pumpkin_data::entity::EntityType; use pumpkin_data::item::Item; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag::Taggable; +use pumpkin_data::{Block, tag}; use pumpkin_util::math::position::BlockPos; use pumpkin_util::math::vector3::Vector3; use uuid::Uuid; @@ -60,7 +60,7 @@ impl PumpkinItem for MinecartItem { ) { let world = player.world().await; - if !block.is_tagged_with("minecraft:rails").unwrap() { + if !block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_RAILS) { return; } let state_id = world.get_block_state_id(&location).await; diff --git a/pumpkin/src/item/items/shovel.rs b/pumpkin/src/item/items/shovel.rs index eeb6324da..c2242197e 100644 --- a/pumpkin/src/item/items/shovel.rs +++ b/pumpkin/src/item/items/shovel.rs @@ -2,13 +2,12 @@ use crate::entity::player::Player; use crate::item::pumpkin_item::{ItemMetadata, PumpkinItem}; use crate::server::Server; use async_trait::async_trait; -use pumpkin_data::Block; use pumpkin_data::BlockDirection; use pumpkin_data::block_properties::{BlockProperties, CampfireLikeProperties}; use pumpkin_data::item::Item; use pumpkin_data::sound::{Sound, SoundCategory}; -use pumpkin_data::tag::Tagable; use pumpkin_data::world::WorldEvent; +use pumpkin_data::{Block, tag}; use pumpkin_util::math::position::BlockPos; use pumpkin_world::world::BlockFlags; use rand::{Rng, rng}; @@ -17,16 +16,7 @@ pub struct ShovelItem; impl ItemMetadata for ShovelItem { fn ids() -> Box<[u16]> { - Item::get_tag_values("#minecraft:shovels") - .expect("This is a valid vanilla tag") - .iter() - .map(|key| { - Item::from_registry_key(key) - .expect("We just got this key from the registry") - .id - }) - .collect::>() - .into_boxed_slice() + tag::Item::MINECRAFT_SHOVELS.1.to_vec().into_boxed_slice() } } diff --git a/pumpkin/src/item/items/swords.rs b/pumpkin/src/item/items/swords.rs index fffd0305d..67350ac52 100644 --- a/pumpkin/src/item/items/swords.rs +++ b/pumpkin/src/item/items/swords.rs @@ -1,24 +1,14 @@ use crate::entity::player::Player; use crate::item::pumpkin_item::{ItemMetadata, PumpkinItem}; use async_trait::async_trait; -use pumpkin_data::item::Item; -use pumpkin_data::tag::Tagable; +use pumpkin_data::tag; use pumpkin_util::GameMode; pub struct SwordItem; impl ItemMetadata for SwordItem { fn ids() -> Box<[u16]> { - Item::get_tag_values("#minecraft:swords") - .expect("This is a valid vanilla tag") - .iter() - .map(|key| { - Item::from_registry_key(key) - .expect("We just got this key from the registry") - .id - }) - .collect::>() - .into_boxed_slice() + tag::Item::MINECRAFT_SWORDS.1.to_vec().into_boxed_slice() } } diff --git a/pumpkin/src/world/portal/nether.rs b/pumpkin/src/world/portal/nether.rs index 2d9ef330b..fd82a7984 100644 --- a/pumpkin/src/world/portal/nether.rs +++ b/pumpkin/src/world/portal/nether.rs @@ -3,7 +3,8 @@ use std::sync::Arc; use pumpkin_data::{ Block, BlockDirection, BlockState, block_properties::{BlockProperties, HorizontalAxis, NetherPortalLikeProperties}, - tag::Tagable, + tag, + tag::Taggable, }; use pumpkin_util::math::position::BlockPos; use pumpkin_world::world::BlockFlags; @@ -242,7 +243,7 @@ impl NetherPortal { /// What is allowed to be inside the Portal frame fn valid_state_inside_portal(block: &Block, state: &BlockState) -> bool { state.is_air() - || block.is_tagged_with("minecraft:fire").unwrap() + || block.is_tagged_with_by_tag(&tag::Block::MINECRAFT_FIRE) || block == &Block::NETHER_PORTAL } }