Browse Source

Add Sponge Schematic .schem output

main
raffitz 3 years ago
parent
commit
0724b1df20
Signed by: raffitz
GPG Key ID: BB3596BD0A31252D
  1. 2
      .gitignore
  2. 24
      Cargo.lock
  3. 1
      Cargo.toml
  4. 36
      src/main.rs

2
.gitignore vendored

@ -1,2 +1,4 @@ @@ -1,2 +1,4 @@
/target
*/*.png
*/*.schem
*/*.litematic

24
Cargo.lock generated

@ -56,6 +56,12 @@ version = "1.5.1" @@ -56,6 +56,12 @@ version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bed57e2090563b83ba8f83366628ce535a7584c9afa4c9fc0612a03925c6df58"
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -137,6 +143,12 @@ version = "0.2.91" @@ -137,6 +143,12 @@ version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8916b1f6ca17130ec6568feccee27c156ad12037880833a3b842a823236502e7"
[[package]]
name = "linked-hash-map"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]]
name = "lodepng"
version = "3.4.5"
@ -183,6 +195,17 @@ dependencies = [ @@ -183,6 +195,17 @@ dependencies = [
"autocfg",
]
[[package]]
name = "named-binary-tag"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "523298fac63bd954f9a2e03b962b8a4a0e95110ad1b2fa3e0d7048660ffecec3"
dependencies = [
"byteorder",
"flate2",
"linked-hash-map",
]
[[package]]
name = "pomelo"
version = "0.1.5"
@ -293,6 +316,7 @@ dependencies = [ @@ -293,6 +316,7 @@ dependencies = [
"clap",
"lodepng",
"logos",
"named-binary-tag",
"pomelo",
"rgb",
]

1
Cargo.toml

@ -11,3 +11,4 @@ logos = "0.12" @@ -11,3 +11,4 @@ logos = "0.12"
pomelo = "0.1.5"
lodepng = "3.4"
rgb = "0.8"
named-binary-tag = "0.6"

36
src/main.rs

@ -1,5 +1,7 @@ @@ -1,5 +1,7 @@
use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg};
use logos::Logos;
use nbt::encode::write_gzip_compound_tag;
use nbt::CompoundTag;
use pomelo::pomelo;
use rgb::*;
use std::collections::HashMap;
@ -449,11 +451,16 @@ fn main() -> Result<(), error::Error> { @@ -449,11 +451,16 @@ fn main() -> Result<(), error::Error> {
let width: i64 = 1 + max_x - min_x;
let height: i64 = 1 + max_y - min_y;
let depth: i64 = 1 + max_z - min_z;
let pix_width: usize = 6 * (width as usize) + 1;
let pix_height: usize = 6 * (height as usize) + 1;
let pix_size: usize = pix_width * pix_height;
let schem_size: usize = (width as usize) * (height as usize) * (depth as usize);
let mut schem_block_data: Vec<i8> = Vec::with_capacity(schem_size);
for z in min_z..=max_z {
let name = format! {"{}/layer{:04}.png",output_folder,1 + z - min_z};
@ -518,12 +525,37 @@ fn main() -> Result<(), error::Error> { @@ -518,12 +525,37 @@ fn main() -> Result<(), error::Error> {
+ pix_x] = color;
}
}
schem_block_data.push(1);
schem_block_data.push(if is_filled { 1 } else { 0 });
}
}
lodepng::encode32_file(name, &pixels, pix_width, pix_height)?;
}
Ok(())
// Schematic
let mut schem = CompoundTag::new();
schem.insert_i32("Version", 2);
schem.insert_i32("Data Version", 1343);
schem.insert_i16("Width", width as i16);
schem.insert_i16("Height", depth as i16);
schem.insert_i16("Length", height as i16);
schem.insert_i32_vec("Offset", vec![min_x as i32, min_z as i32, min_y as i32]);
schem.insert_i32("PaletteMax", 2);
//println!("Scale was read and is <{}>", scale.unwrap_or(1));
let mut palette_obj = CompoundTag::new();
palette_obj.insert_i32("minecraft:air", 0);
palette_obj.insert_i32("minecraft:stone", 1);
schem.insert("Palette", palette_obj);
schem.insert_i8_vec("BlockData", schem_block_data);
let mut schem_file = fs::File::create(format!("{}/{}.schem", output_folder, output_folder))?;
write_gzip_compound_tag(&mut schem_file, &schem)?;
Ok(())
}

Loading…
Cancel
Save