1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! V3833 (1.20.5-pre4 + 1) — schematic-relevant subset of `V3833.java`.
//!
//! Drops a `brushable_block`'s `item` field when it holds nothing
//! (`minecraft:air` or a non-positive count) (V3833.java:14-24).
//!
//! Nothing non-schematic exists in this version file.
//!
//! The id is compared after `NamespaceUtil.correctNamespace` (default `air` when
//! absent); the engine does not export that fn, so the parse rule is inlined.
//!
//! VERSION = MCVersions.V1_20_5_PRE4 (3832) + 1 = 3833.
use crate::nbt::NbtMap;
use super::super::registry::RegistryBuilder;
use super::super::types::MapExt;
const VERSION: i32 = 3833;
/// Port of `NamespaceUtil.correctNamespace`: default-namespace an unnamespaced,
/// parseable resource location; otherwise return the input unchanged.
fn correct_namespace(value: &str) -> String {
if value.contains(':') {
return value.to_string();
}
let valid = !value.is_empty()
&& value
.bytes()
.all(|b| matches!(b, b'a'..=b'z' | b'0'..=b'9' | b'.' | b'_' | b'-' | b'/'));
if valid {
format!("minecraft:{value}")
} else {
value.to_string()
}
}
pub fn register(reg: &mut RegistryBuilder) {
reg.tile_entity.add_converter_for_id(
"minecraft:brushable_block",
VERSION,
0,
Box::new(|data: &mut NbtMap, _from, _to| {
let item = match data.get_map("item") {
Some(i) => i,
None => return,
};
// getString("id", "minecraft:air") — default when absent.
let id = correct_namespace(item.get_string("id").unwrap_or("minecraft:air"));
// getInt("count", 0) — default 0 when absent.
let count = item.get_i32("count").unwrap_or(0);
// Fix DFU: use count <= 0 instead of count == 0.
if id == "minecraft:air" || count <= 0 {
data.take("item");
}
}),
);
}