summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rustfmt.toml4
-rw-r--r--src/main.rs156
2 files changed, 107 insertions, 53 deletions
diff --git a/rustfmt.toml b/rustfmt.toml
index 2fd9f19..1c82ce4 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -3,4 +3,6 @@ reorder_imports = true
format_macro_bodies = true
skip_macro_invocations = []
imports_indent = "Visual"
-indent_style = "Visual" \ No newline at end of file
+indent_style = "Block"
+format_brace_macros = true
+unstable_features = true \ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index b7f1203..80dea19 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -56,8 +56,10 @@ impl MinecraftClient {
macro_rules! await_packet {
($packet_type:ident, $conn:expr) => {
- assert_packet!($packet_type,
- $conn.wait_for_packet(Packet761Kind::$packet_type).await?)
+ assert_packet!(
+ $packet_type,
+ $conn.wait_for_packet(Packet761Kind::$packet_type).await?
+ )
};
}
@@ -70,10 +72,13 @@ macro_rules! assert_packet {
}
};
($packet_type:ident, $conn:expr, $errmgs:literal) => {
- assert_packet!($packet_type,
- $conn.read_next_packet()
- .await?
- .ok_or(anyhow::anyhow!("Missing packet"))?)
+ assert_packet!(
+ $packet_type,
+ $conn
+ .read_next_packet()
+ .await?
+ .ok_or(anyhow::anyhow!("Missing packet"))?
+ )
};
}
@@ -117,8 +122,20 @@ impl ShittyToNbt for Tag {
}
}
+impl ShittyToNbt for f32 {
+ fn to_nbt(self) -> Tag {
+ Tag::Float(self)
+ }
+}
+
+impl ShittyToNbt for f64 {
+ fn to_nbt(self) -> Tag {
+ Tag::Double(self)
+ }
+}
+
macro_rules! nbt {
- { {$($name:literal :: $value:tt),* $(,)? } } => {
+ ( {$($name:literal :: $value:tt),* $(,)? } ) => {
Tag::Compound(vec![
$(
nbt!($value).with_name($name)
@@ -164,52 +181,85 @@ async fn handle_conn(mut client: MinecraftClient) -> Result<()> {
let hs = assert_packet!(Handshake, client, "Missing packet");
if hs.next_state == HandshakeNextState::Login {
client.connection.set_state(State::Login);
- let loginstart = assert_packet!(LoginStart,
- client.read_next_packet()
- .await?
- .ok_or(anyhow::anyhow!("Missing packet"))?);
+ let loginstart = assert_packet!(
+ LoginStart,
+ client
+ .read_next_packet()
+ .await?
+ .ok_or(anyhow::anyhow!("Missing packet"))?
+ );
println!("Login: {:?}", loginstart);
let uuid = UUID4::random();
- client.send_packet(Packet761::LoginSuccess(LoginSuccessSpec { uuid,
- username:
- loginstart.name,
- properties:
- vec![].into() }))
- .await?;
- let registry_doex = nbt! {
- "minecraft:dimension_type" :: {
- "type" :: ("minecraft:dimension_type"),
- "value" :: [{
+ client
+ .send_packet(Packet761::LoginSuccess(LoginSuccessSpec {
+ uuid,
+ username: loginstart.name,
+ properties: vec![].into(),
+ }))
+ .await?;
+ let overworld_spec = 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" :: (384),
+ "infiniburn" :: ("#minecraft:infiniburn_overworld"),
+ "logical_height" :: (384),
+ "min_y" :: (-64),
+ "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),
+ },
+ };
+ let biome_spec = nbt!(
+ [
+ {
"id" :: (0),
- "name" :: ("minecraft:overworld"),
+ "name" :: ("minecraft:plains"),
"element" :: {
- "ambient_light" :: (false),
- "bed_works" :: (true),
- "coordinate_scale" :: (1),
- "effects" :: ("minecraft:overworld"),
- "has_ceiling" :: (false),
- "has_skylight" :: (true),
- "has_raids" :: (false),
- "height" :: (384),
- "infiniburn" :: ("#minecraft:infiniburn_overworld"),
- "logical_height" :: (384),
- "min_y" :: (-64),
- "monster_spawn_block_light_limit" :: (0),
- "monster_spawn_light_level" :: {
- "type" :: ("minecraft:uniform"),
- "value" :: {
- "max_inclusive" :: (7),
- "min_inclusive" :: (0),
+ "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),
},
- },
- "natural" :: (true),
- "piglin_safe" :: (false),
- "respawn_anchor_works" :: (false),
- "ultrawarm" :: (false),
-
- },
- }]
+ }
+ }
+ }
+ ]
+ );
+ let registry_doex = nbt! {
+ "minecraft:dimension_type" :: {
+ "type" :: ("minecraft:dimension_type"),
+ "value" :: [(overworld_spec)]
},
+ "minecraft:worldgen/biome" :: {
+ "type" :: ("minecraft:worldgen/biome"),
+ "value" :: (biome_spec),
+ }
};
client.connection.set_state(State::Play);
client
@@ -248,9 +298,10 @@ async fn handle_conn(mut client: MinecraftClient) -> Result<()> {
async fn handle_status(mut client: MinecraftClient) -> Result<()> {
client.connection.set_state(State::Status);
loop {
- match client.read_next_packet()
- .await?
- .ok_or(anyhow::anyhow!("Missing packet"))?
+ match client
+ .read_next_packet()
+ .await?
+ .ok_or(anyhow::anyhow!("Missing packet"))?
{
Packet761::StatusRequest(_) => {
client
@@ -272,8 +323,9 @@ async fn handle_status(mut client: MinecraftClient) -> Result<()> {
.await?;
}
Packet761::PingRequest(PingRequestSpec { payload }) => {
- client.send_packet(Packet761::PingResponse(PingResponseSpec { payload }))
- .await?;
+ client
+ .send_packet(Packet761::PingResponse(PingResponseSpec { payload }))
+ .await?;
return Ok(());
}
_ => anyhow::bail!("Unexpected packet during status communication"),