From 5dd35c7ed82c38ef36ca28f630e8d05c5db2cbea Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Tue, 7 Mar 2023 22:09:56 -0600 Subject: Add World::find_block (#80) * start adding World::find_block * keep working on find_block * BlockStates * fix sorting * update examples that use find_one_block * azalea_block::properties * fix tests * add a gotoblock command to testbot --- azalea-block/src/range.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 azalea-block/src/range.rs (limited to 'azalea-block/src/range.rs') diff --git a/azalea-block/src/range.rs b/azalea-block/src/range.rs new file mode 100644 index 00000000..6ccf4152 --- /dev/null +++ b/azalea-block/src/range.rs @@ -0,0 +1,33 @@ +use std::{collections::HashSet, ops::RangeInclusive}; + +use crate::BlockState; + +#[derive(Debug, Clone)] +pub struct BlockStates { + pub set: HashSet, +} + +impl From> for BlockStates { + fn from(range: RangeInclusive) -> Self { + let mut set = HashSet::with_capacity((range.end() - range.start() + 1) as usize); + for id in range { + set.insert(BlockState { id }); + } + Self { set } + } +} + +impl IntoIterator for BlockStates { + type Item = BlockState; + type IntoIter = std::collections::hash_set::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.set.into_iter() + } +} + +impl BlockStates { + pub fn contains(&self, state: &BlockState) -> bool { + self.set.contains(state) + } +} -- cgit v1.2.3