mcmeta_parser/
lib.rs

1use serde::{Serialize,Deserialize};
2use std::collections::HashMap;
3/// The root object.
4#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
5pub struct Mcmeta {
6    /// Holds the pack information.
7    pub pack: McmetaPack,
8    /// (optional) Section for selecting experimental features.
9    pub features: Option<McmetaFeatures>,
10    /// (optional) Section for filtering out files from packs applied below this one.
11    pub filter: Option<McmetaFilter>,
12    /// (optional) Section for specifying the overlays, which are sub-packs applied over the "normal" contents of a pack.
13    pub overlays: Option<McmetaOverlays>,
14    /// (optional) Only present in resource packs — Contains additional languages to add to the language menu.
15    pub language: Option<HashMap<String,McmetaLanguage>>
16}
17        /// Holds the pack information.
18        #[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
19        pub struct McmetaPack {
20            /// A raw JSON text that appears when hovering over the pack's name in the list given by the `/datapack list` command, or when viewing the pack in the Create World screen.
21            pub description: Vec<McmetaPackDescription>,
22            /// Determines the version(s) of Minecraft that this pack is compatible with.
23            ///
24            /// See <https://minecraft.wiki/w/Pack_format> for a full list of pack format numbers.
25            pub pack_format: u8,
26            /// (optional) Describes a range for pack formats that this pack supports.
27            ///
28            /// The range has to include the value of [`McmetaPack::pack_format`].
29            pub supported_formats: Option<McmetaPackSupportedformats>
30        }
31                /// Determines the version(s) of Minecraft that this pack is compatible with.
32                ///
33                /// See <https://minecraft.wiki/w/Pack_format> for a full list of pack format numbers.
34                #[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
35                pub struct McmetaPackDescription {
36                    /// The text in the description.
37                    pub text: String,
38                    /// The colour of the text in the description.
39                    pub color: Option<String>
40                }
41                /// (optional) Describes a range for pack formats that this pack supports.
42                ///
43                /// The range has to include the value of [`McmetaPack::pack_format`].
44                #[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
45                pub struct McmetaPackSupportedformats {
46                    /// Minimum Pack format number
47                    pub min_inclusive: u8,
48                    /// Maximum pack format number
49                    pub max_inclusive: u8
50                }
51
52        // I don't what this looks like
53        /// (optional) Section for selecting experimental features.
54        #[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
55        pub struct McmetaFeatures {
56            /// List of enabled feature flags.
57            ///
58            /// Each item in the Vec is a location of a feature flag.
59            pub enabled: Vec<String>
60        }
61
62        // I don't what this looks like
63        /// (optional) Section for filtering out files from packs applied below this one.
64        #[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
65        pub struct McmetaFilter {
66            /// Vector of patterns.
67            ///
68            /// Any file that matches one of the patterns inside [`McmetaFilter::block`] is treated as if it was not present in the pack at all.
69            pub block: Vec<McmetaFilterBlock>
70        }
71                /// A pattern.
72                ///
73                /// Any file that matches one of the patterns inside here is treated as if it was not present in the pack at all.
74                #[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
75                pub struct McmetaFilterBlock {
76                    /// A regular expression for the namespace of files to be filtered out. If unspecified, it applies to every namespace.
77                    pub namespace: String,
78                    /// A regular expression for the paths of files to be filtered out. If unspecified, it applies to every file.
79                    pub path: String
80                }
81
82        // I don't what this looks like
83        /// (optional) Section for specifying the overlays, which are sub-packs applied over the "normal" contents of a pack.
84        ///
85        /// Their directories have their own assets and data directories, and are placed in the pack's root directory.
86        #[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
87        pub struct McmetaOverlays {
88            /// Vector of overlays. The order is important, as the first in the list is applied first.
89            pub entries: Vec<McmetaOverlaysEntries>
90        }
91                #[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
92                /// An overlay.
93                pub struct McmetaOverlaysEntries {
94                    /// Describes a range for pack formats when this overlay should be active.
95                    pub formats: McmetaOverlaysEntriesFormats,
96                    /// The directory to overlay for the respective versions (allowed characters: a-z, 0-9, _ and -). In this directory, pack.mcmeta and pack.png are ignored.
97                    pub directory: String
98                }
99                        /// Describes a range for pack formats when this overlay should be active.
100                        #[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
101                        pub struct McmetaOverlaysEntriesFormats {
102                            /// Minimum Pack format number.
103                            pub min_inclusive: u8,
104                            /// Maximum Pack format number.
105                            pub max_inclusive: u8
106                        }
107
108        // I don't what this looks like
109        /// (optional) Only present in resource packs — Contains additional languages to add to the language menu.
110        #[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
111        pub struct McmetaLanguage {
112            /// The full name of the language
113            pub name: String,
114            /// The country or region name
115            pub region: String,
116            /// If true, the language reads right to left.
117            pub bidirectional: bool
118        }