reorganize into different crates

Should help to get a more clear view and simplify things
This commit is contained in:
Snowiiii committed 2024-08-02 10:57:38 +02:00
1 parent 5a1d333f02
commit fd9344a512
34 files changed
+258 -170

No files matched your search

+106
View File
@@ -0,0 +1,106 @@
use super::RegistryValue;
use pumpkin_protocol::VarInt;
use serde::Serialize;
#[derive(Debug, Clone, Serialize)]
pub struct Biome {
has_precipitation: bool,
temperature: f32,
#[serde(skip_serializing_if = "Option::is_none")]
temperature_modifier: Option<String>,
downfall: f32,
effects: BiomeEffects,
}
#[derive(Debug, Clone, Serialize)]
struct BiomeEffects {
fog_color: i32,
water_color: i32,
water_fog_color: i32,
sky_color: i32,
#[serde(skip_serializing_if = "Option::is_none")]
foliage_color: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
grass_color: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
grass_color_modifier: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
particle: Option<Particle>,
#[serde(skip_serializing_if = "Option::is_none")]
ambient_sound: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
mood_sound: Option<MoodSound>,
#[serde(skip_serializing_if = "Option::is_none")]
additions_sound: Option<AdditionsSound>,
#[serde(skip_serializing_if = "Option::is_none")]
music: Option<Music>,
}
#[derive(Debug, Clone, Serialize)]
struct Particle {
options: ParticleOptions,
probability: f32,
}
#[derive(Debug, Clone, Serialize)]
struct ParticleOptions {
typee: String,
#[serde(skip_serializing_if = "Option::is_none")]
value: Option<VarInt>,
}
#[derive(Debug, Clone, Serialize)]
struct MoodSound {
block_search_extent: i32,
offset: f64,
sound: String,
tick_delay: i32,
}
#[derive(Debug, Clone, Serialize)]
struct AdditionsSound {
sound: String,
tick_chance: f64,
}
#[derive(Debug, Clone, Serialize)]
struct Music {
sound: String,
min_delay: i32,
max_delay: i32,
replace_current_music: bool,
}
// 1.20.6 default https://gist.github.com/WinX64/ab8c7a8df797c273b32d3a3b66522906
pub(super) fn all() -> Vec<RegistryValue<Biome>> {
let biome = Biome {
has_precipitation: false,
temperature: 1.0,
temperature_modifier: None,
downfall: 0.0,
effects: BiomeEffects {
fog_color: 0x7FA1FF,
water_color: 0x7FA1FF,
water_fog_color: 0x7FA1FF,
sky_color: 0x7FA1FF,
foliage_color: Some(0x7FA1FF),
grass_color: Some(0x7FA1FF),
grass_color_modifier: None,
particle: None,
ambient_sound: None,
mood_sound: Some(MoodSound {
block_search_extent: 8,
offset: 2.0,
sound: "minecraft:ambient.cave".into(),
tick_delay: 6000,
}),
additions_sound: None,
music: None,
},
};
vec![RegistryValue {
name: "minecraft:plains".into(),
id: 0,
element: biome,
}]
}
+31
View File
@@ -0,0 +1,31 @@
use super::RegistryValue;
use serde::Serialize;
#[derive(Debug, Clone, Serialize)]
pub struct ChatType {
chat: Decoration,
narration: Decoration,
}
#[derive(Debug, Clone, Serialize)]
struct Decoration {
translation_key: String,
// style: Option<>
parameters: Vec<String>,
}
pub(super) fn all() -> Vec<RegistryValue<ChatType>> {
vec![RegistryValue {
name: "minecraft:chat".into(),
id: 0,
element: ChatType {
chat: Decoration {
parameters: vec!["sender".into(), "content".into()],
translation_key: "chat.type.text".into(),
},
narration: Decoration {
parameters: vec!["sender".into(), "content".into()],
translation_key: "chat.type.text.narrate".into(),
},
},
}]
}
+83
View File
@@ -0,0 +1,83 @@
use serde::Serialize;
use super::RegistryValue;
#[derive(Debug, Clone, Serialize)]
pub struct DamageType {
message_id: String,
scaling: String,
exhaustion: f32,
#[serde(skip_serializing_if = "Option::is_none")]
effects: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
death_message_type: Option<String>,
}
const NAMES: &[&str] = &[
"arrow",
"bad_respawn_point",
"cactus",
"cramming",
"dragon_breath",
"drown",
"dry_out",
"explosion",
"fall",
"falling_anvil",
"falling_block",
"falling_stalactite",
"fireball",
"fireworks",
"fly_into_wall",
"freeze",
"generic",
"generic_kill",
"hot_floor",
"in_fire",
"in_wall",
"indirect_magic",
"lava",
"lightning_bolt",
"magic",
"mob_attack",
"mob_attack_no_aggro",
"mob_projectile",
"on_fire",
"out_of_world",
"outside_border",
"player_attack",
"player_explosion",
"sonic_boom",
"spit",
"stalagmite",
"starve",
"sting",
"sweet_berry_bush",
"thorns",
"thrown",
"trident",
"unattributed_fireball",
"wither",
"wither_skull",
];
pub(super) fn all() -> Vec<RegistryValue<DamageType>> {
let mut items: Vec<_> = NAMES
.iter()
.map(|name| RegistryValue {
name: (*name).into(),
id: 0,
element: DamageType {
exhaustion: 0.1,
message_id: "inFire".into(),
scaling: "when_caused_by_living_non_player".into(),
effects: None,
death_message_type: Some("default".into()),
},
})
.collect();
items[1].element.effects = Some("burning".into());
items
}
+88
View File
@@ -0,0 +1,88 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Dimension {
ambient_light: f32,
bed_works: u8,
coordinate_scale: f64,
effects: DimensionEffects,
#[serde(skip_serializing_if = "Option::is_none")]
fixed_time: Option<i64>,
has_ceiling: u8,
has_raids: u8,
has_skylight: u8,
height: i32,
infiniburn: String,
logical_height: i32,
min_y: i32,
monster_spawn_block_light_limit: i32,
monster_spawn_light_level: MonsterSpawnLightLevel,
natural: u8,
piglin_safe: u8,
respawn_anchor_works: u8,
ultrawarm: u8,
}
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Debug)]
pub enum DimensionEffects {
#[serde(rename = "minecraft:overworld")]
#[default]
Overworld,
#[serde(rename = "minecraft:the_nether")]
TheNether,
#[serde(rename = "minecraft:the_end")]
TheEnd,
}
impl Default for Dimension {
fn default() -> Self {
Self {
ambient_light: 0.0,
bed_works: 1,
coordinate_scale: 1.0,
effects: DimensionEffects::default(),
fixed_time: None,
has_ceiling: 0,
has_raids: 1,
has_skylight: 1,
height: 384,
infiniburn: "#minecraft:infiniburn_overworld".into(),
logical_height: 384,
min_y: -64,
monster_spawn_block_light_limit: 0,
monster_spawn_light_level: MonsterSpawnLightLevel::Tagged(
MonsterSpawnLightLevelTagged::Uniform {
min_inclusive: 7,
max_inclusive: 0,
},
),
natural: 1,
piglin_safe: 0,
respawn_anchor_works: 0,
ultrawarm: 0,
}
}
}
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum MonsterSpawnLightLevel {
Int(i32),
Tagged(MonsterSpawnLightLevelTagged),
}
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize)]
#[serde(tag = "type", content = "value")]
pub enum MonsterSpawnLightLevelTagged {
#[serde(rename = "minecraft:uniform")]
Uniform {
min_inclusive: i32,
max_inclusive: i32,
},
}
impl From<i32> for MonsterSpawnLightLevel {
fn from(value: i32) -> Self {
Self::Int(value)
}
}
+121
View File
@@ -0,0 +1,121 @@
use dimensions::Dimension;
use fastnbt::SerOpts;
use pumpkin_protocol::bytebuf::ByteBuffer;
use serde::Serialize;
use wolf::WolfVariant;
mod biomes;
mod chat_type;
mod damage_type;
mod dimensions;
mod wolf;
#[derive(Debug, Clone, Serialize)]
struct LoginInfo {
#[serde(rename = "minecraft:dimension_type")]
dimensions: Codec<dimensions::Dimension>,
// #[serde(rename = "minecraft:wolf_variant")]
// wolf: Codec<wolf::WolfVariant>,
/* #[serde(rename = "minecraft:worldgen/biome")]
biomes: Codec<biomes::Biome>,
#[serde(rename = "minecraft:chat_type")]
chat: Codec<chat_type::ChatType>,
#[serde(rename = "minecraft:damage_type")]
damage: Codec<damage_type::DamageType>, */
}
#[derive(Debug, Clone, Serialize)]
pub struct DimensionCodec {
#[serde(rename = "minecraft:dimension_type")]
dimensions: Codec<dimensions::Dimension>,
}
impl DimensionCodec {
pub fn parse() -> Vec<u8> {
let dimension = Dimension::default();
let codec = DimensionCodec {
dimensions: Codec {
ty: "minecraft:dimension_type".into(),
value: vec![RegistryValue {
name: "minecraft:overworld".into(),
id: 0,
element: dimension,
}],
},
};
fastnbt::to_bytes_with_opts(&codec, SerOpts::network_nbt()).unwrap()
}
}
#[derive(Debug, Clone, Serialize)]
pub struct WolfCodec {
#[serde(rename = "minecraft:wolf_variant")]
wolf: Codec<wolf::WolfVariant>,
}
impl WolfCodec {
pub fn parse() -> Vec<u8> {
let wolf = WolfVariant::default();
let codec = WolfCodec {
wolf: Codec {
ty: "minecraft:wolf_variant".into(),
value: vec![RegistryValue {
name: "minecraft:wolf_variant".into(),
id: 0,
element: wolf,
}],
},
};
fastnbt::to_bytes_with_opts(&codec, SerOpts::network_nbt()).unwrap()
}
}
#[derive(Debug, Clone, Serialize)]
struct Codec<T> {
#[serde(rename = "type")]
ty: String,
value: Vec<RegistryValue<T>>,
}
#[derive(Debug, Clone, Serialize)]
struct RegistryValue<T> {
name: String,
id: i32,
element: T,
}
pub fn write_codec(out: &mut ByteBuffer, world_min_y: i32, world_height: u32) -> Vec<u8> {
let dimension = Dimension::default();
let wolf = WolfVariant::default();
let info = LoginInfo {
dimensions: Codec {
ty: "minecraft:dimension_type".into(),
value: vec![RegistryValue {
name: "minecraft:overworld".into(),
id: 0,
element: dimension,
}],
},
/* wolf: Codec {
ty: "minecraft:wolf_variant".into(),
value: vec![RegistryValue {
name: "minecraft:wolf_variant".into(),
id: 0,
element: wolf,
}],
}, */ /* biomes: Codec {
ty: "minecraft:worldgen/biome".into(),
value: biomes::all(),
},
chat: Codec {
ty: "minecraft:chat_type".into(),
value: chat_type::all(),
},
damage: Codec {
ty: "minecraft:damage_type".into(),
value: damage_type::all(),
}, */
};
fastnbt::to_bytes_with_opts(&info, SerOpts::network_nbt()).unwrap()
}
+20
View File
@@ -0,0 +1,20 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WolfVariant {
wild_texture: String,
tame_texture: String,
angry_texture: String,
biomes: String,
}
impl Default for WolfVariant {
fn default() -> Self {
Self {
wild_texture: "minecraft:entity/wolf/wolf_ashen".to_string(),
tame_texture: "minecraft:entity/wolf/wolf_ashen_tame".to_string(),
angry_texture: "minecraft:entity/wolf/wolf_ashen_angry".to_string(),
biomes: "minecraft:snowy_taiga".to_string(),
}
}
}