vintage_schematics/formats/
common.rs1use serde::{Deserialize, Serialize};
4
5use crate::Map;
6
7pub static MODERNISED_BLOCKS: &[(&str, &str)] = &[
14 ("minecraft:grass", "minecraft:grass_block"),
15 ("minecraft:grass_path", "minecraft:dirt_path"),
16 ("minecraft:fence", "minecraft:oak_fence"),
17 ("minecraft:fence_gate", "minecraft:oak_fence_gate"),
18 ("minecraft:noteblock", "minecraft:note_block"),
19 ("minecraft:golden_rail", "minecraft:powered_rail"),
20 ("minecraft:web", "minecraft:cobweb"),
21 ("minecraft:tallgrass", "minecraft:tall_grass"),
22 ("minecraft:deadbush", "minecraft:dead_bush"),
23 ("minecraft:waterlily", "minecraft:lily_pad"),
24 ("minecraft:yellow_flower", "minecraft:dandelion"),
25 ("minecraft:red_flower", "minecraft:poppy"),
26 ("minecraft:reeds", "minecraft:sugar_cane"),
27 ("minecraft:stone_stairs", "minecraft:cobblestone_stairs"),
28 ("minecraft:wooden_door", "minecraft:oak_door"),
29 ("minecraft:trapdoor", "minecraft:oak_trapdoor"),
30 ("minecraft:monster_egg", "minecraft:infested_stone"),
31 ("minecraft:double_stone_slab", "minecraft:smooth_stone"),
32 ("minecraft:stonebrick", "minecraft:stone_bricks"), ("minecraft:lit_furnace", "minecraft:furnace"),
34 ("minecraft:slime", "minecraft:slime_block"),
35 ("minecraft:magma", "minecraft:magma_block"),
36 ("minecraft:flowing_water", "minecraft:water"),
37 ("minecraft:flowing_lava", "minecraft:lava"),
38 ("minecraft:quartz_ore", "minecraft:nether_quartz_ore"),
39 ("minecraft:lit_pumpkin", "minecraft:jack_o_lantern"),
40 ("minecraft:wooden_pressure_plate", "minecraft:oak_pressure_plate"),
41 ("minecraft:snow", "minecraft:snow_block"),
43 ("minecraft:snow_layer", "minecraft:snow"),
44];
45
46pub const FLATTENING_VERSION: i32 = 1519;
49
50#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
52pub struct Xyz {
53 pub x: i32,
54 pub y: i32,
55 pub z: i32,
56}
57
58impl From<(i32, i32, i32)> for Xyz {
59 fn from((x, y, z): (i32, i32, i32)) -> Self { Self { x, y, z } }
60}
61
62#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
65#[serde(rename_all = "PascalCase")]
66pub struct Size {
67 pub width: u16,
69
70 pub height: u16,
72
73 pub length: u16,
75}
76
77impl Size {
78 #[must_use]
80 pub fn blocks(self) -> i32 { i32::from(self.width) * i32::from(self.height) * i32::from(self.length) }
81
82 #[inline]
85 #[must_use]
86 pub fn index_position(self, i: i32) -> Xyz {
87 Xyz {
88 x: i % i32::from(self.width),
89 y: i / (i32::from(self.width) * i32::from(self.length)),
90 z: (i / i32::from(self.width)) % i32::from(self.length),
91 }
92 }
93}
94
95impl From<Size> for Xyz {
96 fn from(value: Size) -> Self {
97 Self {
98 x: i32::from(value.width),
99 y: i32::from(value.height),
100 z: i32::from(value.length),
101 }
102 }
103}
104
105#[derive(Debug, Clone, Deserialize, Serialize)]
107pub struct MinecraftBlockEntity {
108 pub id: String,
109 pub x: i32,
110 pub y: i32,
111 pub z: i32,
112
113 #[serde(flatten, skip_serializing)]
114 pub components: Map<String, mininbt::Value>,
115}
116
117impl MinecraftBlockEntity {
118 #[must_use]
119 pub const fn position(&self) -> Xyz {
120 Xyz {
121 x: self.x,
122 y: self.y,
123 z: self.z,
124 }
125 }
126}
127
128#[derive(Debug, Clone, Deserialize, Serialize)]
130pub struct MinecraftBlockData {
131 pub id: String,
132 #[serde(flatten, skip_serializing)]
133 pub components: Map<String, mininbt::Value>,
134}