summaryrefslogtreecommitdiff
path: root/src/convention.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/convention.rs')
-rw-r--r--src/convention.rs189
1 files changed, 189 insertions, 0 deletions
diff --git a/src/convention.rs b/src/convention.rs
new file mode 100644
index 0000000..ae9a646
--- /dev/null
+++ b/src/convention.rs
@@ -0,0 +1,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(),
+ }),
+ ]
+ }
+}
+
+
+
+
+
+
+