9861a1ba04
Move-only step B6 of the horizon-client crate split. These four modules only reached gameplay modules for small helpers, so after this they depend only on the render/world layer and can move into its crate whole, impls included. - save::float moves to horizon_client_core::nbt_value (save re-exports it). - mobs::spawner::normalize_id moves to horizon_client_core::identifier (spawner re-exports it). - containers::Providers moves to its own module, providers.rs (containers re-exports it). - vault, command_block and sculk import number/text/float, item_nbt, Who and scoreboard from their real homes instead of through save and mobs; brewing imports Providers from providers. - The vault, spawner and trial_spawner harnesses record the client-core files the moved helpers now live in. - villager_brain's `impl Poi` (max_tickets, valid_range) moves next to the type in poi_sections, and its two methods become pub. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
36 lines
1.3 KiB
Rust
36 lines
1.3 KiB
Rust
//! Resource identifiers (`Identifier`).
|
|
|
|
/// Identifier.parse: `ns:path` or `path`, validated.
|
|
pub fn parse_identifier(raw: &str) -> Option<String> {
|
|
let (ns, path) = match raw.split_once(':') {
|
|
Some(("", path)) => ("minecraft", path),
|
|
Some((ns, path)) => (ns, path),
|
|
None => ("minecraft", raw),
|
|
};
|
|
let ns_ok = ns != ".."
|
|
&& ns
|
|
.chars()
|
|
.all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || matches!(c, '_' | '.' | '-'));
|
|
let path_ok = path.chars().all(|c| {
|
|
c.is_ascii_lowercase() || c.is_ascii_digit() || matches!(c, '_' | '.' | '-' | '/')
|
|
});
|
|
(ns_ok && path_ok).then(|| format!("{ns}:{path}"))
|
|
}
|
|
|
|
/// `Identifier.CODEC` parsing an entity id: lowercase namespace and path
|
|
/// characters, `minecraft` when the namespace is left out.
|
|
pub fn normalize_id(s: &str) -> Option<String> {
|
|
let (ns, path) = match s.split_once(':') {
|
|
Some((ns, path)) => (if ns.is_empty() { "minecraft" } else { ns }, path),
|
|
None => ("minecraft", s),
|
|
};
|
|
let ok = |c: char, slash: bool| {
|
|
c.is_ascii_lowercase()
|
|
|| c.is_ascii_digit()
|
|
|| matches!(c, '_' | '-' | '.')
|
|
|| slash && c == '/'
|
|
};
|
|
(ns.chars().all(|c| ok(c, false)) && path.chars().all(|c| ok(c, true)))
|
|
.then(|| format!("{ns}:{path}"))
|
|
}
|