worldstat 0.0.1

Simple library for interfacing with Minecraft world information
Documentation
use std::collections::HashMap;

use fastnbt::Value;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, BoolFromInt};

use crate::player::player_data::PlayerData;

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "PascalCase")]
/// Struct representing the world data.
pub struct WorldData {
  pub data_version: i32,
  pub difficulty: i32,
  #[serde_as(as = "BoolFromInt")]
  pub difficulty_locked: bool,
  pub game_type: i32,
  pub last_played: i64,
  pub level_name: String,
  pub player: Option<PlayerData>,
  pub server_brands: Option<Vec<String>>,
  pub spawn_angle: f32,
  pub spawn_x: i32,
  pub spawn_y: i32,
  pub spawn_z: i32,
  pub time: i64,
  pub version: Version,
  pub world_gen_settings: WorldGenSettings,

  #[serde(flatten)]
  other: HashMap<String, Value>,
}

impl WorldData {
  pub fn get(&self, key: &str) -> Option<&Value> {
    self.other.get(key)
  }

  pub fn get_mut(&mut self, key: &str) -> Option<&mut Value> {
    self.other.get_mut(key)
  }
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct WorldGenSettings {
  #[serde_as(as = "BoolFromInt")]
  pub bonus_chest: bool,
  pub dimensions: Option<Value>,
  #[serde_as(as = "BoolFromInt")]
  pub generate_features: bool,
  pub seed: i64,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "PascalCase")]
pub struct Version {
  pub id: i32,
  pub name: String,
  pub series: String,
  pub snapshot: i32,
}

#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct Level {
  pub data: WorldData,
}