summaryrefslogtreecommitdiff
path: root/src/convention.rs
blob: ae9a646ce350d4fa32bbf4dd2ba4b90964a6a44b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
use mcproto_rs::nbt::Tag;
use mcproto_rs::types::NamedNbtTag;
use mcproto_rs::v1_19_3::{BookSettings, CommandNode, CommandNodeSpec, CommandsSpec, GameMode, LoginPlaySpec, Packet761, PreviousGameMode, RecipeBookAction, RecipeBookInitSpec, TagType, TypedTagList, UpdateRecipeBookSpec, UpdateRecipesSpec, UpdateTagsSpec};

use crate::nbt;
use crate::player::Player;

pub struct Universe {
    pub min_build_height: i32,
    pub max_build_height: i32,
    pub min_world_section: i32,
    pub max_world_section: i32,
    pub registry_codex: Tag,
}

fn convention_biome_spec() -> Tag {
    return nbt!(
            [
                {
                    "id" :: (0),
                    "name" :: ("minecraft:plains"),
                    "element" :: {
                        "downfall" :: (0.5),
                        "precipitation" :: ("none"),
                        "temperature" :: (0.5),
                        "effects" :: {
                            "fog_color" :: (12638463),
                            "sky_color" :: (12638463),
                            "water_color" :: (12638463),
                            "water_fog_color" :: (12638463),
                            "mood_sound" :: {
                                "block_search_extent" :: (8),
                                "offset" :: (2),
                                "sound" :: ("minecraft:ambient.cave"),
                                "tick_delay" :: (6000),
                            },
                        }
                    }
                }
            ]
        )
}

fn convention_overworld_spec(min_build_height: i32, world_height: i32) -> Tag {
    return nbt! {
            "id" :: (0),
            "name" :: ("minecraft:overworld"),
            "element" :: {
                "ambient_light" :: (false),
                "bed_works" :: (true),
                "coordinate_scale" :: (1),
                "effects" :: ("minecraft:overworld"),
                "has_ceiling" :: (false),
                "has_skylight" :: (true),
                "has_raids" :: (false),
                "height" :: (world_height),
                "infiniburn" :: ("#minecraft:infiniburn_overworld"),
                "logical_height" :: (world_height),
                "min_y" :: (min_build_height),
                "monster_spawn_block_light_limit" :: (0),
                "monster_spawn_light_level" :: {
                    "type" :: ("minecraft:uniform"),
                    "value" :: {
                        "max_inclusive" :: (7),
                        "min_inclusive" :: (0),
                    },
                },
                "natural" :: (true),
                "piglin_safe" :: (false),
                "respawn_anchor_works" :: (false),
                "ultrawarm" :: (false),
            },
        }
}

impl Universe {
    pub fn default_meta(
        min_build_height: i32,
        max_build_height: i32,
    ) -> Universe {
        let world_height = max_build_height - min_build_height;
        let min_world_section = min_build_height >> 4;
        let max_world_section = ((max_build_height - 1) >> 4) + 1;
        let biome_spec = convention_biome_spec();
        let overworld_spec = convention_overworld_spec(min_build_height, world_height);
        let registry_codex = nbt! {
            "minecraft:dimension_type" :: {
                "type" :: ("minecraft:dimension_type"),
                "value" :: [(overworld_spec)]
            },
            "minecraft:worldgen/biome" :: {
                "type" :: ("minecraft:worldgen/biome"),
                "value" :: (biome_spec),
            }
        };
        Universe {
            min_build_height,
            max_build_height,
            min_world_section,
            max_world_section,
            registry_codex,
        }
    }

    pub fn create_login_play_packet(&self) -> Packet761 {
        Packet761::LoginPlay(LoginPlaySpec {
            entity_id: 0,
            is_hardcore: false,
            gamemode: GameMode::Survival,
            previous_gamemode: PreviousGameMode::NoPrevious,
            dimension_names: vec!["world".into()].into(),
            registry_codex: NamedNbtTag {
                root: self.registry_codex.clone().with_name("root"),
            },
            dimension_type: "minecraft:overworld".into(),
            dimension_name: "world".into(),
            hashed_seed: 0,
            max_players: 10.into(),
            view_distance: 10.into(),
            simulation_distance: 10.into(),
            reduced_debug_info: false,
            enable_respawn_screen: false,
            is_debug: false,
            is_flat: false,
            death_location: None,
        })
    }

    pub fn init_empty_recipe_book(&self) -> Packet761 {
        Packet761::UpdateRecipeBook(UpdateRecipeBookSpec {
            action: RecipeBookAction::Init(RecipeBookInitSpec {
                book_settings: BookSettings::default(),
                known_recipes: vec![].into(),
                highlighted_recipes: vec![].into(),
            })
        })
    }

    pub fn empty_commands(&self) -> Packet761 {
        Packet761::Commands(CommandsSpec {
            nodes: vec![
                CommandNodeSpec {
                    children_indices: vec![].into(),
                    redirect_node: None,
                    is_executable: false,
                    node: CommandNode::Root,
                }
            ].into(),
            root_index: 0.into(),
        })
    }

    pub fn create_tags_and_recipes(&self) -> Vec<Packet761> {
        return vec![
            Packet761::UpdateRecipes(UpdateRecipesSpec { recipes: vec![].into() }),
            Packet761::UpdateTags(UpdateTagsSpec {
                tags: vec![
                    TypedTagList {
                        tag_type: TagType::Block,
                        tags: vec![].into(),
                    },
                    TypedTagList {
                        tag_type: TagType::Item,
                        tags: vec![].into(),
                    },
                    TypedTagList {
                        tag_type: TagType::EntityType,
                        tags: vec![].into(),
                    },
                    TypedTagList {
                        tag_type: TagType::GameEvent,
                        tags: vec![].into(),
                    },
                    TypedTagList {
                        tag_type: TagType::Fluid,
                        tags: vec![].into(),
                    },
                ].into(),
            }),
        ]
    }
}