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
59
60
61
62
63
64
65
66
67
68
//! V4064 (24w36a + 1) — schematic-relevant subset of `V4064.java`.
//!
//! ITEM_STACK structure converter: the boolean `minecraft:fire_resistant`
//! component is replaced by a `minecraft:damage_resistant` compound with
//! `types = "#minecraft:is_fire"`.
//!
//! Nothing non-schematic is present in this version.
//!
//! VERSION = MCVersions.V24W36A (4063) + 1 = 4064.
use crate::nbt::NbtMap;
use super::super::registry::RegistryBuilder;
use super::super::types::MapExt;
use super::super::types::ValueExt;
const VERSION: i32 = 4064;
pub fn register(reg: &mut RegistryBuilder) {
reg.item_stack.add_structure_converter(
VERSION,
0,
Box::new(|data: &mut NbtMap, _from, _to| {
let components = match data.get_map_mut("components") {
Some(c) => c,
None => return,
};
if components.has_key("minecraft:fire_resistant") {
components.take("minecraft:fire_resistant");
let mut damage_resistant = NbtMap::new();
damage_resistant.set_string("types", "#minecraft:is_fire");
components.set_map("minecraft:damage_resistant", damage_resistant);
}
}),
);
// Reverse of the structure converter above (V4064.java:21-28).
//
// Forward replaced the unit component `minecraft:fire_resistant` with the
// compound `minecraft:damage_resistant = { types: "#minecraft:is_fire" }`.
// The reverse restores the unit component when it sees that exact marker.
//
// Lossless (rule 11): `damage_resistant` with `types == "#minecraft:is_fire"`
// is the unambiguous forward output, and `fire_resistant` was a unit
// component whose canonical value is the empty compound `{}` — restoring a
// default the old format always carried is exact, not loss. A
// `damage_resistant` carrying any other `types` (or a non-string `types`,
// e.g. an inline tag list) was authored directly and is left untouched.
reg.item_stack.add_reverse_converter(
VERSION,
0,
Box::new(|data: &mut NbtMap, _from, _to| {
let components = match data.get_map_mut("components") {
Some(c) => c,
None => return,
};
let is_fire = components
.get_map("minecraft:damage_resistant")
.and_then(|dr| dr.get("types"))
.and_then(ValueExt::as_str)
== Some("#minecraft:is_fire");
if is_fire {
components.take("minecraft:damage_resistant");
components.set_map("minecraft:fire_resistant", NbtMap::new());
}
}),
);
}