mirror of
https://github.com/Chaoscaot/schemsearch.git
synced 2026-01-04 10:57:06 +01:00
🔧 Add invalid_nbt flag.
This commit is contained in:
27
schemsearch-lib/src/nbt_search.rs
Executable file
27
schemsearch-lib/src/nbt_search.rs
Executable file
@@ -0,0 +1,27 @@
|
||||
use std::borrow::ToOwned;
|
||||
use std::collections::HashSet;
|
||||
use std::iter::Iterator;
|
||||
use lazy_static::lazy_static;
|
||||
use schemsearch_files::SpongeSchematic;
|
||||
|
||||
const NBT_BLOCKS: &str = include_str!("blocks.txt");
|
||||
|
||||
lazy_static! {
|
||||
static ref NBT_BLOCKS_SET: HashSet<String> = NBT_BLOCKS.lines().map(ToOwned::to_owned).collect();
|
||||
}
|
||||
|
||||
pub fn has_invalid_nbt(schem: SpongeSchematic) -> bool {
|
||||
if schem.block_entities.is_empty() && schem.palette.keys().any(|v| NBT_BLOCKS_SET.contains(v)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let nbt_blocks = schem.palette.iter().filter(|(k, _)| NBT_BLOCKS_SET.contains(*k)).map(|(_, v)| *v).collect::<HashSet<i32>>();
|
||||
|
||||
for block_entity in schem.block_data.iter() {
|
||||
if nbt_blocks.contains(block_entity) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user