aboutsummaryrefslogtreecommitdiff
path: root/azalea-block/src/range.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2023-03-07 22:09:56 -0600
committerGitHub <noreply@github.com>2023-03-07 22:09:56 -0600
commit5dd35c7ed82c38ef36ca28f630e8d05c5db2cbea (patch)
tree72719e46479e7884ea535c768ab7c244ce048063 /azalea-block/src/range.rs
parent719379a8a76ab0685f2bd14bebe2f0cd1e97f06b (diff)
downloadazalea-drasl-5dd35c7ed82c38ef36ca28f630e8d05c5db2cbea.tar.xz
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
Diffstat (limited to 'azalea-block/src/range.rs')
-rw-r--r--azalea-block/src/range.rs33
1 files changed, 33 insertions, 0 deletions
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<BlockState>,
+}
+
+impl From<RangeInclusive<u32>> for BlockStates {
+ fn from(range: RangeInclusive<u32>) -> 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<BlockState>;
+
+ fn into_iter(self) -> Self::IntoIter {
+ self.set.into_iter()
+ }
+}
+
+impl BlockStates {
+ pub fn contains(&self, state: &BlockState) -> bool {
+ self.set.contains(state)
+ }
+}