world: rename JSONText to TextValue

New Minecraft version do not store text as JSON anymore.
This commit is contained in:
Matthias Schiffer 2025-04-02 22:39:26 +02:00
parent 442009eb08
commit ba6e4bae7f
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
4 changed files with 20 additions and 20 deletions

View file

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

View file

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

View file

@ -8,7 +8,7 @@ use serde::Serialize;
use super::{ use super::{
de, de,
json_text::{FormattedText, FormattedTextList, JSONText}, text_value::{FormattedText, FormattedTextList, TextValue},
}; };
/// Version-independent reference to (front or back) sign text /// 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 /// A regular sign always has 4 lines of text. The back of pre-1.20
/// signs is represented as a [SignText] without any `messages`. /// signs is represented as a [SignText] without any `messages`.
pub messages: Vec<&'a JSONText>, pub messages: Vec<&'a TextValue>,
/// Sign color /// Sign color
/// ///
/// Defaults to "black". /// Defaults to "black".

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}; use std::{collections::VecDeque, fmt::Display};
@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
/// A span of formatted text /// 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 /// represented as a [FormattedTextTree], but other kinds are possible with
/// is handled by [DeserializedText]. /// is handled by [DeserializedText].
/// ///
@ -21,7 +21,7 @@ pub struct FormattedText {
/// Text content /// Text content
pub text: String, pub text: String,
/// Text color /// 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>, pub color: Option<Color>,
/// Bold formatting /// Bold formatting
#[serde(skip_serializing_if = "Option::is_none")] #[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)] #[derive(Debug, Deserialize)]
#[serde(untagged)] #[serde(untagged)]
pub enum DeserializedText { pub enum DeserializedText {
@ -169,18 +169,18 @@ impl Default for DeserializedText {
} }
} }
/// Minecraft Raw JSON Text /// Minecraft raw text value
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct JSONText(pub String); pub struct TextValue(pub String);
impl JSONText { impl TextValue {
/// Deserializes a [JSONText] into a [DeserializedText] /// Deserializes a [TextValue] into a [DeserializedText]
pub fn deserialize(&self) -> DeserializedText { pub fn deserialize(&self) -> DeserializedText {
serde_json::from_str(&self.0).unwrap_or_default() serde_json::from_str(&self.0).unwrap_or_default()
} }
} }
mod json_color { mod text_color {
//! Helpers for serializing and deserializing [FormattedText](super::FormattedText) colors //! Helpers for serializing and deserializing [FormattedText](super::FormattedText) colors
use minedmap_resource::Color; use minedmap_resource::Color;
@ -190,7 +190,7 @@ mod json_color {
ser::Error as _, ser::Error as _,
}; };
/// Named JSON text colors /// Named text colors
static COLORS: phf::Map<&'static str, Color> = phf::phf_map! { static COLORS: phf::Map<&'static str, Color> = phf::phf_map! {
"black" => Color([0x00, 0x00, 0x00]), "black" => Color([0x00, 0x00, 0x00]),
"dark_blue" => Color([0x00, 0x00, 0xAA]), "dark_blue" => Color([0x00, 0x00, 0xAA]),