1use fastnbt::{IntArray, LongArray};
2use mcdata::{util::BlockPos, GenericBlockEntity, GenericBlockState, GenericEntity};
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6type CowStr = std::borrow::Cow<'static, str>;
7
8#[derive(Debug, Serialize, Deserialize, Clone)]
9#[serde(rename_all = "PascalCase")]
10pub struct Litematic<
11 BlockState = GenericBlockState,
12 Entity = GenericEntity,
13 BlockEntity = GenericBlockEntity,
14> where
15 BlockState: mcdata::BlockState,
16 Entity: mcdata::Entity,
17 BlockEntity: mcdata::BlockEntity,
18{
19 #[serde(flatten)]
20 pub regions: LitematicRegions<BlockState, Entity, BlockEntity>,
21 #[serde(flatten)]
22 pub metadata: LitematicMetadata,
23}
24
25#[derive(Debug, Serialize, Deserialize, Clone)]
26#[serde(rename_all = "PascalCase")]
27pub struct LitematicRegions<
28 BlockState = GenericBlockState,
29 Entity = GenericEntity,
30 BlockEntity = GenericBlockEntity,
31> where
32 BlockState: mcdata::BlockState,
33 Entity: mcdata::Entity,
34 BlockEntity: mcdata::BlockEntity,
35{
36 pub regions: HashMap<String, Region<BlockState, Entity, BlockEntity>>,
37}
38
39#[derive(Debug, Serialize, Deserialize, Clone)]
40#[serde(rename_all = "PascalCase")]
41pub struct LitematicMetadata {
42 pub minecraft_data_version: i32,
43 pub version: i32,
44 pub sub_version: Option<i32>,
45 pub metadata: Metadata,
46}
47
48#[derive(Debug, Serialize, Deserialize, Clone)]
49#[serde(rename_all = "PascalCase")]
50pub struct Region<
51 BlockState = GenericBlockState,
52 Entity = GenericEntity,
53 BlockEntity = GenericBlockEntity,
54> where
55 BlockState: mcdata::BlockState,
56 Entity: mcdata::Entity,
57 BlockEntity: mcdata::BlockEntity,
58{
59 pub position: BlockPos,
60 pub size: BlockPos,
61 pub block_state_palette: Vec<BlockState>,
62 pub block_states: LongArray,
63 pub tile_entities: Vec<BlockEntity>,
64 #[serde(default = "Vec::new", skip_serializing_if = "Vec::is_empty")]
65 pub entities: Vec<Entity>,
66 #[serde(default, skip_serializing_if = "Vec::is_empty")]
67 pub pending_block_ticks: Vec<PendingBlockTick>,
68 #[serde(default, skip_serializing_if = "Vec::is_empty")]
69 pub pending_fluid_ticks: Vec<PendingFluidTick>,
70}
71
72#[derive(Debug, Serialize, Deserialize, Clone)]
73#[serde(rename_all = "PascalCase")]
74pub struct Metadata {
75 pub name: String,
76 pub author: String,
77 pub description: String,
78 pub region_count: i32,
79 pub total_volume: i32,
80 pub total_blocks: i64,
81 pub time_created: i64,
82 pub time_modified: i64,
83 pub enclosing_size: BlockPos,
84 pub preview_image_data: Option<IntArray>,
85}
86
87#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
89#[serde(rename_all = "PascalCase")]
90#[allow(missing_docs)]
91pub struct PendingBlockTick {
92 pub block: CowStr,
93 pub priority: i32,
94 pub sub_tick: i64,
95 pub time: i32,
96 #[serde(rename = "x")]
97 pub x: i32,
98 #[serde(rename = "y")]
99 pub y: i32,
100 #[serde(rename = "z")]
101 pub z: i32,
102}
103
104#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
106#[serde(rename_all = "PascalCase")]
107#[allow(missing_docs)]
108pub struct PendingFluidTick {
109 pub fluid: CowStr,
110 pub priority: i32,
111 pub sub_tick: i64,
112 pub time: i32,
113 #[serde(rename = "x")]
114 pub x: i32,
115 #[serde(rename = "y")]
116 pub y: i32,
117 #[serde(rename = "z")]
118 pub z: i32,
119}