mc_schem/
lib.rs

1/*
2mc_schem is a rust library to generate, load, manipulate and save minecraft schematic files.
3Copyright (C) 2024  joseph
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program.  If not, see <https://www.gnu.org/licenses/>.
17*/
18
19//! A rust library to generate, load, manipulate and save minecraft schematic files.
20//! ## Supported formats:
21//! - Litematica(`.litematica`)
22//! - Vanilla structure(`.nbt`)
23//! - WorldEdit schem (1.13+)(`.schem`)
24//! - WorldEdit schem (1.12-)(`.schematic`)
25//!
26//! ## Contents
27//! 1. `mc_schem` (rlib)
28//!
29//!    The main rust lib
30//! 2. `mc_schem` (cdylib)
31//!
32//!    C ffi for mc_schem
33//! 3. mc_schem C++ wrapper
34//!
35//!    A header-only c++ wrapper based on C ffi of mc_schem
36//! 4. `schemtool` (executable)
37//!
38//!    An executable to do various manipulations on schematics
39//!
40
41
42use strum::Display;
43
44/// Implement minecraft block and string id parsing
45pub mod block;
46/// Number id parsing
47pub mod old_block;
48/// Errors in loading, saving and manipulating
49pub mod error;
50/// Implement region, entity, block entity and pending ticks
51pub mod region;
52/// Implement metadata, schematics and loading/saving
53pub mod schem;
54
55pub mod world;
56
57mod c_ffi;
58mod biome;
59mod raid;
60mod player;
61mod item;
62
63/// `Block` is a type of block with namespace and properties(aka attributes) in MC.
64pub type Block = block::Block;
65/// Enumerate common blocks
66pub type CommonBlock = block::CommonBlock;
67/// An entity in MC, like zombie, minecart, etc.
68pub type Entity = region::Entity;
69/// Block entity(also known as tile entity) in MC, like chest, furnace, etc.
70pub type BlockEntity = region::BlockEntity;
71/// A tick waiting to be processed
72pub type PendingTick = region::PendingTick;
73/// Region is a 3d area in Minecraft, containing blocks and entities.
74//pub trait WorldSlice = region::WorldSlice;
75pub type Region = region::Region;
76/// Schematic is part of a Minecraft world, like `.litematic` of litematica mod, `.schem` and
77/// `.schematic` of world edit, `.nbt` of vanilla structure.
78pub type Schematic = schem::Schematic;
79/// A 3d slice of schematic
80pub type SchemSlice<'a> = schem::schem_slice::SchemSlice<'a>;
81/// Intermediate representation via different metadata formats
82pub type MetaDataIR = schem::MetaDataIR;
83/// Options to load litematica
84pub type LitematicaLoadOption = schem::LitematicaLoadOption;
85/// Options to save litematica
86pub type LitematicaSaveOption = schem::LitematicaSaveOption;
87/// Options to load vanilla structure
88pub type VanillaStructureLoadOption = schem::VanillaStructureLoadOption;
89/// Options to save vanilla structure
90pub type VanillaStructureSaveOption = schem::VanillaStructureSaveOption;
91/// Options to load litematica
92pub type WorldEdit13LoadOption = schem::WorldEdit13LoadOption;
93/// Options to save world edit 1.13+
94pub type WorldEdit13SaveOption = schem::WorldEdit13SaveOption;
95/// Options to load litematica
96pub type WorldEdit12LoadOption = schem::WorldEdit12LoadOption;
97/// Minecraft data versions.
98pub type DataVersion = schem::DataVersion;
99/// Errors when loading and saving schematic
100pub type Error = error::Error;
101
102/// Format of known schematics
103#[repr(u8)]
104#[derive(Debug, Display, Clone, PartialEq)]
105pub enum SchemFormat {
106    Litematica = 0,
107    VanillaStructure = 1,
108    WorldEdit13 = 2,
109    WorldEdit12 = 3,
110}
111
112impl SchemFormat {
113    /// Filename extension with `.`
114    pub fn extension(&self) -> &'static str {
115        return match self {
116            SchemFormat::Litematica => ".litematic",
117            SchemFormat::VanillaStructure => ".nbt",
118            SchemFormat::WorldEdit13 => ".schem",
119            SchemFormat::WorldEdit12 => ".schematic",
120        }
121    }
122
123    /// Return all supported formats
124    pub fn supported_formats() -> &'static [SchemFormat] {
125        return Self::loadable_formats();
126    }
127    /// Return all loadable formats
128    pub fn loadable_formats() -> &'static [SchemFormat] {
129        use SchemFormat::*;
130        return &[Litematica, VanillaStructure, WorldEdit13, WorldEdit12];
131    }
132    /// Return all savable formats
133    pub fn savable_formats() -> &'static [SchemFormat] {
134        use SchemFormat::*;
135        return &[Litematica, VanillaStructure, WorldEdit13];
136    }
137    /// Return if the format can be loaded
138    pub fn loadable(&self) -> bool {
139        return Self::loadable_formats().contains(self);
140    }
141    /// Return if the format can be saved
142    pub fn savable(&self) -> bool {
143        return Self::savable_formats().contains(self);
144    }
145}