Merge pull request #76 from neocturne/mc-1.21.5
Some checks are pending
MinedMap / viewer (push) Waiting to run
MinedMap / fmt (push) Waiting to run
MinedMap / clippy (push) Waiting to run
MinedMap / docs (push) Waiting to run
MinedMap / test (macOS-latest) (push) Waiting to run
MinedMap / test (ubuntu-latest) (push) Waiting to run
MinedMap / test (windows-latest) (push) Waiting to run
MinedMap / build (.exe, windows-2019, i686-pc-windows-msvc) (push) Waiting to run
MinedMap / build (.exe, windows-2019, x86_64-pc-windows-msvc) (push) Waiting to run
MinedMap / build (macos-13, aarch64-apple-darwin) (push) Waiting to run
MinedMap / build (macos-13, x86_64-apple-darwin) (push) Waiting to run
MinedMap / build (ubuntu-22.04, x86_64-unknown-linux-gnu) (push) Waiting to run
MinedMap / build-container (push) Blocked by required conditions
MinedMap / viewer-container (push) Blocked by required conditions

Updates and Minecraft 1.21.5 support
This commit is contained in:
Matthias Schiffer 2025-04-02 23:06:58 +02:00 committed by GitHub
commit 58f2ff53b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 240 additions and 72 deletions

View file

@ -48,7 +48,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: '1.85'
toolchain: '1.85.1'
components: rustfmt
- run: cargo fmt --all -- --check
@ -58,7 +58,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: '1.85'
toolchain: '1.85.1'
components: clippy
- uses: swatinem/rust-cache@v2
- uses: actions-rs/clippy-check@v1
@ -72,7 +72,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: '1.85'
toolchain: '1.85.1'
components: rust-docs
- uses: swatinem/rust-cache@v2
- run: cargo doc --workspace --no-deps --document-private-items
@ -87,7 +87,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: '1.85'
toolchain: '1.85.1'
- uses: swatinem/rust-cache@v2
- run: cargo test --workspace
- run: cargo test --workspace --no-default-features
@ -127,7 +127,7 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: '1.85'
toolchain: '1.85.1'
targets: '${{ matrix.target }}'
- uses: swatinem/rust-cache@v2

View file

@ -2,6 +2,12 @@
## [Unreleased] - ReleaseDate
### Added
- Added support for Minecraft 1.21.5
Added new block types and handling for changed sign text storage format.
## [2.5.0] - 2025-03-16
### Added

105
Cargo.lock generated
View file

@ -161,9 +161,9 @@ checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
[[package]]
name = "cc"
version = "1.2.16"
version = "1.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be714c154be609ec7f5dad223a33bf1482fff90472de28f7362806e6d4832b8c"
checksum = "1fcb57c740ae1daf453ae85f16e37396f672b039e00d9d866e07ddb24e328e3a"
dependencies = [
"jobserver",
"libc",
@ -184,9 +184,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.5.32"
version = "4.5.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6088f3ae8c3608d19260cd7445411865a485688711b78b5be70d78cd96136f83"
checksum = "d8aa86934b44c19c50f87cc2790e19f54f7a67aedb64101c2e1a2e5ecfb73944"
dependencies = [
"clap_builder",
"clap_derive",
@ -194,9 +194,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.5.32"
version = "4.5.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22a7ef7f676155edfb82daa97f99441f3ebf4a58d5e32f295a56259f1b6facc8"
checksum = "2414dbb2dd0695280da6ea9261e327479e9d37b0630f6b53ba2a11c60c679fd9"
dependencies = [
"anstream",
"anstyle",
@ -360,9 +360,9 @@ dependencies = [
[[package]]
name = "flate2"
version = "1.1.0"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11faaf5a5236997af9848be0bef4db95824b1d534ebc64d0f0c6cf3e67bd38dc"
checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece"
dependencies = [
"crc32fast",
"libz-rs-sys",
@ -371,9 +371,9 @@ dependencies = [
[[package]]
name = "foldhash"
version = "0.1.4"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]]
name = "fsevent-sys"
@ -421,6 +421,18 @@ dependencies = [
"slab",
]
[[package]]
name = "getrandom"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasi 0.14.2+wasi-0.2.4",
]
[[package]]
name = "gimli"
version = "0.31.1"
@ -449,9 +461,9 @@ dependencies = [
[[package]]
name = "glam"
version = "0.30.0"
version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17fcdf9683c406c2fc4d124afd29c0d595e22210d633cbdb8695ba9935ab1dc6"
checksum = "bf3aa70d918d2b234126ff4f850f628f172542bf0603ded26b8ee36e5e22d5f9"
[[package]]
name = "hashbrown"
@ -484,9 +496,9 @@ checksum = "9b112acc8b3adf4b107a8ec20977da0273a8c386765a3ec0229bd500a1443f9f"
[[package]]
name = "image"
version = "0.25.5"
version = "0.25.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd6f44aed642f18953a158afeb30206f4d50da59fbc66ecb53c66488de73563b"
checksum = "db35664ce6b9810857a38a906215e75a9c879f0696556a39f59c62829710251a"
dependencies = [
"bytemuck",
"byteorder-lite",
@ -558,10 +570,11 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "jobserver"
version = "0.1.32"
version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0"
checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a"
dependencies = [
"getrandom",
"libc",
]
@ -610,18 +623,18 @@ dependencies = [
[[package]]
name = "libz-rs-sys"
version = "0.4.2"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "902bc563b5d65ad9bba616b490842ef0651066a1a1dc3ce1087113ffcb873c8d"
checksum = "6489ca9bd760fe9642d7644e827b0c9add07df89857b0416ee15c1cc1a3b8c5a"
dependencies = [
"zlib-rs",
]
[[package]]
name = "linux-raw-sys"
version = "0.9.2"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9c683daf087dc577b7506e9695b3d556a9f3849903fa28186283afd6809e9"
checksum = "fe7db12097d22ec582439daf8618b8fdd1a7bef6270e9af3b1ebcd30893cf413"
[[package]]
name = "lock_api"
@ -635,9 +648,9 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.26"
version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e"
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]]
name = "lru"
@ -744,7 +757,7 @@ checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd"
dependencies = [
"libc",
"log",
"wasi",
"wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys 0.52.0",
]
@ -822,9 +835,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.21.1"
version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "overload"
@ -952,6 +965,12 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "r-efi"
version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
[[package]]
name = "rand"
version = "0.8.5"
@ -1039,9 +1058,9 @@ checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
[[package]]
name = "rustix"
version = "1.0.2"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7178faa4b75a30e269c71e61c353ce2748cf3d76f0c44c393f4e60abf49b825"
checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf"
dependencies = [
"bitflags 2.9.0",
"errno",
@ -1325,6 +1344,15 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasi"
version = "0.14.2+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
dependencies = [
"wit-bindgen-rt",
]
[[package]]
name = "winapi"
version = "0.3.9"
@ -1439,10 +1467,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "zlib-rs"
version = "0.4.2"
name = "wit-bindgen-rt"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b20717f0917c908dc63de2e44e97f1e6b126ca58d0e391cee86d504eb8fbd05"
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
dependencies = [
"bitflags 2.9.0",
]
[[package]]
name = "zlib-rs"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "868b928d7949e09af2f6086dfc1e01936064cc7a819253bce650d4e2a2d63ba8"
[[package]]
name = "zstd"
@ -1455,18 +1492,18 @@ dependencies = [
[[package]]
name = "zstd-safe"
version = "7.2.3"
version = "7.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3051792fbdc2e1e143244dc28c60f73d8470e93f3f9cbd0ead44da5ed802722"
checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d"
dependencies = [
"zstd-sys",
]
[[package]]
name = "zstd-sys"
version = "2.0.14+zstd.1.5.7"
version = "2.0.15+zstd.1.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fb060d4926e4ac3a3ad15d864e99ceb5f343c6b34f5bd6d81ae6ed417311be5"
checksum = "eb81183ddd97d0c74cedf1d50d85c8d08c1b8b68ee863bdee9e706eedba1a237"
dependencies = [
"cc",
"pkg-config",

View file

@ -1,4 +1,4 @@
FROM docker.io/library/rust:1.85-alpine AS builder
FROM docker.io/library/rust:1.85.1-alpine AS builder
WORKDIR /build
RUN apk add --no-cache build-base tini-static

View file

@ -1488,6 +1488,16 @@ pub const BLOCK_TYPES: &[(&str, ConstBlockType)] = &[
sign_material: None,
},
),
(
"bush",
ConstBlockType {
block_color: BlockColor {
flags: make_bitflags!(BlockFlag::{Opaque|Grass}),
color: Color([119, 120, 119]),
},
sign_material: None,
},
),
(
"cactus",
ConstBlockType {
@ -1498,6 +1508,16 @@ pub const BLOCK_TYPES: &[(&str, ConstBlockType)] = &[
sign_material: None,
},
),
(
"cactus_flower",
ConstBlockType {
block_color: BlockColor {
flags: make_bitflags!(BlockFlag::{Opaque}),
color: Color([209, 120, 135]),
},
sign_material: None,
},
),
(
"cake",
ConstBlockType {
@ -3808,6 +3828,16 @@ pub const BLOCK_TYPES: &[(&str, ConstBlockType)] = &[
sign_material: None,
},
),
(
"firefly_bush",
ConstBlockType {
block_color: BlockColor {
flags: make_bitflags!(BlockFlag::{Opaque}),
color: Color([87, 83, 43]),
},
sign_material: None,
},
),
(
"fletching_table",
ConstBlockType {
@ -4878,6 +4908,16 @@ pub const BLOCK_TYPES: &[(&str, ConstBlockType)] = &[
sign_material: None,
},
),
(
"leaf_litter",
ConstBlockType {
block_color: BlockColor {
flags: make_bitflags!(BlockFlag::{}),
color: Color([0, 0, 0]),
},
sign_material: None,
},
),
(
"lectern",
ConstBlockType {
@ -8698,6 +8738,16 @@ pub const BLOCK_TYPES: &[(&str, ConstBlockType)] = &[
sign_material: None,
},
),
(
"short_dry_grass",
ConstBlockType {
block_color: BlockColor {
flags: make_bitflags!(BlockFlag::{Opaque}),
color: Color([187, 158, 108]),
},
sign_material: None,
},
),
(
"short_grass",
ConstBlockType {
@ -9638,6 +9688,16 @@ pub const BLOCK_TYPES: &[(&str, ConstBlockType)] = &[
sign_material: None,
},
),
(
"tall_dry_grass",
ConstBlockType {
block_color: BlockColor {
flags: make_bitflags!(BlockFlag::{Opaque}),
color: Color([196, 171, 122]),
},
sign_material: None,
},
),
(
"tall_grass",
ConstBlockType {
@ -9678,6 +9738,26 @@ pub const BLOCK_TYPES: &[(&str, ConstBlockType)] = &[
sign_material: None,
},
),
(
"test_block",
ConstBlockType {
block_color: BlockColor {
flags: make_bitflags!(BlockFlag::{}),
color: Color([0, 0, 0]),
},
sign_material: None,
},
),
(
"test_instance_block",
ConstBlockType {
block_color: BlockColor {
flags: make_bitflags!(BlockFlag::{}),
color: Color([0, 0, 0]),
},
sign_material: None,
},
),
(
"tinted_glass",
ConstBlockType {
@ -10828,6 +10908,16 @@ pub const BLOCK_TYPES: &[(&str, ConstBlockType)] = &[
sign_material: None,
},
),
(
"wildflowers",
ConstBlockType {
block_color: BlockColor {
flags: make_bitflags!(BlockFlag::{}),
color: Color([0, 0, 0]),
},
sign_material: None,
},
),
(
"wither_rose",
ConstBlockType {

View file

@ -316,9 +316,13 @@
"bubble_coral_fan": null,
"bubble_coral_wall_fan": null,
"budding_amethyst": {},
"bush": {
"grass": true
},
"cactus": {
"texture": "cactus_top"
},
"cactus_flower": {},
"cake": {
"texture": "cake_top"
},
@ -778,6 +782,7 @@
"fire_coral_block": {},
"fire_coral_fan": null,
"fire_coral_wall_fan": null,
"firefly_bush": {},
"fletching_table": {
"texture": "fletching_table_top"
},
@ -987,6 +992,7 @@
"lava_cauldron": {
"texture": "cauldron_top"
},
"leaf_litter": null,
"lectern": {
"texture": "lectern_top"
},
@ -1782,6 +1788,7 @@
"sea_lantern": {},
"sea_pickle": {},
"seagrass": {},
"short_dry_grass": {},
"short_grass": null,
"shroomlight": {},
"shulker_box": {},
@ -2013,6 +2020,7 @@
"sweet_berry_bush": {
"texture": "sweet_berry_bush_stage3"
},
"tall_dry_grass": {},
"tall_grass": {
"grass": true,
"texture": "tall_grass_top"
@ -2024,6 +2032,8 @@
"texture": "target_top"
},
"terracotta": {},
"test_block": null,
"test_instance_block": null,
"tinted_glass": {},
"tnt": {
"texture": "tnt_top"
@ -2288,6 +2298,7 @@
"white_tulip": null,
"white_wall_banner": null,
"white_wool": {},
"wildflowers": null,
"wither_rose": null,
"wither_skeleton_skull": null,
"wither_skeleton_wall_skull": null,

View file

@ -26,7 +26,7 @@ use crate::{
///
/// Increase when the generation of processed regions from region data changes
/// (usually because of updated resource data)
pub const REGION_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(6);
pub const REGION_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(7);
/// MinedMap map tile data version number
///
@ -38,7 +38,7 @@ pub const MAP_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(0);
///
/// Increase when the generation of lightmap tiles from region data changes
/// (usually because of updated resource data)
pub const LIGHTMAP_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(4);
pub const LIGHTMAP_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(5);
/// MinedMap mipmap data version number
///

View file

@ -41,10 +41,15 @@ pub struct Sign {
impl Sign {
/// Processes a [de::BlockEntitySign] into a [Sign]
fn new(sign: &de::BlockEntitySign, kind: SignKind, material: Option<String>) -> Sign {
fn new(
sign: &de::BlockEntitySign,
kind: SignKind,
material: Option<String>,
data_version: u32,
) -> Sign {
let (front_text, back_text) = sign.text();
let front_text = front_text.decode();
let back_text = back_text.decode();
let front_text = front_text.decode(data_version);
let back_text = back_text.decode(data_version);
Sign {
kind,
material,
@ -78,7 +83,11 @@ pub struct BlockEntity {
impl BlockEntity {
/// Processes a [de::BlockEntity] into a [BlockEntity]
pub fn new(entity: &de::BlockEntity, block_type: Option<&BlockType>) -> Option<Self> {
pub fn new(
entity: &de::BlockEntity,
block_type: Option<&BlockType>,
data_version: u32,
) -> Option<Self> {
let wall_sign = block_type
.map(|block_type| block_type.block_color.is(BlockFlag::WallSign))
.unwrap_or_default();
@ -92,7 +101,7 @@ impl BlockEntity {
let material = block_type
.as_ref()
.and_then(|block_type| block_type.sign_material.as_ref());
let data = BlockEntityData::Sign(Sign::new(sign, kind, material.cloned()));
let data = BlockEntityData::Sign(Sign::new(sign, kind, material.cloned(), data_version));
Some(BlockEntity {
x: entity.x,

View file

@ -58,6 +58,8 @@ pub struct Chunk<'a> {
inner: ChunkInner<'a>,
/// Unprocessed block entities
block_entities: &'a Vec<de::BlockEntity>,
/// Chunk data version
data_version: u32,
}
impl<'a> Chunk<'a> {
@ -87,6 +89,7 @@ impl<'a> Chunk<'a> {
Chunk {
inner,
block_entities,
data_version,
},
has_unknown,
))
@ -292,7 +295,11 @@ impl<'a> Chunk<'a> {
.iter()
.map(|block_entity| {
let block_type = self.block_type_at_block_entity(block_entity)?;
Ok(BlockEntity::new(block_entity, block_type))
Ok(BlockEntity::new(
block_entity,
block_type,
self.data_version,
))
})
.collect::<Result<_>>()?;
Ok(entities.into_iter().flatten().collect())

View file

@ -2,7 +2,7 @@
use serde::Deserialize;
use super::json_text::JSONText;
use super::text_value::TextValue;
/// Element of the `palette` list of 1.18+ [block states](BlockStatesV1_18)
#[derive(Debug, Deserialize)]
@ -110,7 +110,7 @@ pub enum BiomesV0 {
#[derive(Debug, Deserialize)]
pub struct BlockEntitySignV1_20Text {
/// Lines of sign text
pub messages: Vec<JSONText>,
pub messages: Vec<TextValue>,
/// Default text color
pub color: Option<String>,
}
@ -125,13 +125,13 @@ pub enum BlockEntitySign {
#[serde(rename_all = "PascalCase")]
V0 {
/// Line 1 of the sign text
text1: JSONText,
text1: TextValue,
/// Line 2 of the sign text
text2: JSONText,
text2: TextValue,
/// Line 3 of the sign text
text3: JSONText,
text3: TextValue,
/// Line 4 of the sign text
text4: JSONText,
text4: TextValue,
/// Default text color
color: Option<String>,
},

View file

@ -3,7 +3,7 @@
pub mod block_entity;
pub mod chunk;
pub mod de;
pub mod json_text;
pub mod layer;
pub mod section;
pub mod sign;
pub mod text_value;

View file

@ -8,7 +8,7 @@ use serde::Serialize;
use super::{
de,
json_text::{FormattedText, FormattedTextList, JSONText},
text_value::{FormattedText, FormattedTextList, TextValue},
};
/// Version-independent reference to (front or back) sign text
@ -18,7 +18,7 @@ pub struct RawSignText<'a> {
///
/// A regular sign always has 4 lines of text. The back of pre-1.20
/// signs is represented as a [SignText] without any `messages`.
pub messages: Vec<&'a JSONText>,
pub messages: Vec<&'a TextValue>,
/// Sign color
///
/// Defaults to "black".
@ -49,7 +49,7 @@ static DYE_COLORS: phf::Map<&'static str, Color> = phf::phf_map! {
impl RawSignText<'_> {
/// Decodes the [RawSignText] into a [SignText]
pub fn decode(&self) -> SignText {
pub fn decode(&self, data_version: u32) -> SignText {
let color = self
.color
.map(|c| DYE_COLORS.get(c).copied().unwrap_or(DEFAULT_COLOR));
@ -60,7 +60,7 @@ impl RawSignText<'_> {
SignText(
self.messages
.iter()
.map(|message| message.deserialize().linearize(&parent))
.map(|message| message.deserialize(data_version).linearize(&parent))
.collect(),
)
}

View file

@ -1,4 +1,4 @@
//! Newtype and helper methods for handling Minecraft Raw JSON Text
//! Newtype and helper methods for handling Minecraft text values
use std::{collections::VecDeque, fmt::Display};
@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
/// A span of formatted text
///
/// A [JSONText] consists of a tree of [FormattedText] nodes (canonically
/// A [TextValue] consists of a tree of [FormattedText] nodes (canonically
/// represented as a [FormattedTextTree], but other kinds are possible with
/// is handled by [DeserializedText].
///
@ -21,7 +21,7 @@ pub struct FormattedText {
/// Text content
pub text: String,
/// Text color
#[serde(skip_serializing_if = "Option::is_none", with = "json_color")]
#[serde(skip_serializing_if = "Option::is_none", with = "text_color")]
pub color: Option<Color>,
/// Bold formatting
#[serde(skip_serializing_if = "Option::is_none")]
@ -107,9 +107,9 @@ impl Display for FormattedTextList {
}
}
/// Raw deserialized [JSONText]
/// Raw deserialized [TextValue]
///
/// A [JSONText] can contain various different JSON types.
/// A [TextValue] can contain various different types serialized as JSON or NBT.
#[derive(Debug, Deserialize)]
#[serde(untagged)]
pub enum DeserializedText {
@ -169,18 +169,26 @@ impl Default for DeserializedText {
}
}
/// Minecraft Raw JSON Text
/// Minecraft raw text value
#[derive(Debug, Deserialize)]
pub struct JSONText(pub String);
pub struct TextValue(pub fastnbt::Value);
impl JSONText {
/// Deserializes a [JSONText] into a [DeserializedText]
pub fn deserialize(&self) -> DeserializedText {
serde_json::from_str(&self.0).unwrap_or_default()
impl TextValue {
/// Deserializes a [TextValue] into a [DeserializedText]
pub fn deserialize(&self, data_version: u32) -> DeserializedText {
if data_version < 4290 {
if let fastnbt::Value::String(json) = &self.0 {
if let Ok(content) = serde_json::from_str(json) {
return content;
}
}
}
fastnbt::from_value(&self.0).unwrap_or_default()
}
}
mod json_color {
mod text_color {
//! Helpers for serializing and deserializing [FormattedText](super::FormattedText) colors
use minedmap_resource::Color;
@ -190,7 +198,7 @@ mod json_color {
ser::Error as _,
};
/// Named JSON text colors
/// Named text colors
static COLORS: phf::Map<&'static str, Color> = phf::phf_map! {
"black" => Color([0x00, 0x00, 0x00]),
"dark_blue" => Color([0x00, 0x00, 0xAA]),