diff --git a/events/proof-of-concept/src/command.rs b/events/proof-of-concept/src/command.rs new file mode 100644 index 00000000..1df6806f --- /dev/null +++ b/events/proof-of-concept/src/command.rs @@ -0,0 +1,13 @@ +use flecs_ecs::core::World; +use hyperion_clap::hyperion_command::CommandRegistry; +use hyperion_clap::MinecraftCommand; + +use crate::command::{fly::FlyCommand, speed::SpeedCommand}; + +mod fly; +mod speed; + +pub fn register(registry: &mut CommandRegistry, world: &World) { + SpeedCommand::register(registry, world); + FlyCommand::register(registry, world); +} diff --git a/events/proof-of-concept/src/command/fly.rs b/events/proof-of-concept/src/command/fly.rs new file mode 100644 index 00000000..ededcf8f --- /dev/null +++ b/events/proof-of-concept/src/command/fly.rs @@ -0,0 +1,49 @@ +use clap::Parser; +use flecs_ecs::core::{Entity, EntityViewGet, World, WorldGet}; +use hyperion::{ + net::{Compose, DataBundle, NetworkStreamRef, agnostic}, + system_registry::SystemId, + valence_protocol::packets::play::{ + PlayerAbilitiesS2c, player_abilities_s2c::PlayerAbilitiesFlags, + }, +}; +use hyperion_clap::MinecraftCommand; + +#[derive(Parser, Debug)] +#[command(name = "fly")] +pub struct FlyCommand; + +impl MinecraftCommand for FlyCommand { + fn execute(self, world: &World, caller: Entity) { + let chat = agnostic::chat("§aFlying enabled"); + + world.get::<&Compose>(|compose| { + caller + .entity_view(world) + .get::<&NetworkStreamRef>(|stream| { + let packet = fly_packet(); + + let mut bundle = DataBundle::new(compose); + bundle.add_packet(&packet, world).unwrap(); + bundle.add_packet(&chat, world).unwrap(); + + bundle.send(world, *stream, SystemId(8)).unwrap(); + }); + }); + } +} + +fn fly_packet() -> PlayerAbilitiesS2c { + const SPEED_METER_PER_SECOND: f32 = 10.92; + + // guessing.. idk what the actual conversion is + const SOME_CONVERSION: f32 = SPEED_METER_PER_SECOND / 70.0; + + PlayerAbilitiesS2c { + flags: PlayerAbilitiesFlags::default() + .with_flying(true) + .with_allow_flying(true), + flying_speed: SOME_CONVERSION, + fov_modifier: 0.0, + } +} diff --git a/events/proof-of-concept/src/command/speed.rs b/events/proof-of-concept/src/command/speed.rs new file mode 100644 index 00000000..a171a731 --- /dev/null +++ b/events/proof-of-concept/src/command/speed.rs @@ -0,0 +1,45 @@ +use clap::Parser; +use flecs_ecs::core::{Entity, EntityViewGet, World, WorldGet}; +use hyperion::net::{agnostic, Compose, DataBundle, NetworkStreamRef}; +use hyperion::system_registry::SystemId; +use hyperion::valence_protocol::packets::play::player_abilities_s2c::PlayerAbilitiesFlags; +use hyperion::valence_protocol::packets::play::PlayerAbilitiesS2c; +use hyperion_clap::MinecraftCommand; + +#[derive(Parser, Debug)] +#[command(name = "speed")] +pub struct SpeedCommand { + amount: f32, +} + + +impl MinecraftCommand for SpeedCommand { + fn execute(self, world: &World, caller: Entity) { + let msg = format!("Setting speed to {}", self.amount); + let chat = agnostic::chat(msg); + + world.get::<&Compose>(|compose| { + caller + .entity_view(world) + .get::<&NetworkStreamRef>(|stream| { + let packet = speed_packet(self.amount); + + let mut bundle = DataBundle::new(compose); + bundle.add_packet(&packet, world).unwrap(); + bundle.add_packet(&chat, world).unwrap(); + + bundle.send(world, *stream, SystemId(8)).unwrap(); + }); + }); + } +} + +fn speed_packet(amount: f32) -> PlayerAbilitiesS2c { + PlayerAbilitiesS2c { + flags: PlayerAbilitiesFlags::default() + .with_flying(true) + .with_allow_flying(true), + flying_speed: amount, + fov_modifier: 0.0, + } +} diff --git a/events/proof-of-concept/src/lib.rs b/events/proof-of-concept/src/lib.rs index 96eebcf8..e5b7617f 100644 --- a/events/proof-of-concept/src/lib.rs +++ b/events/proof-of-concept/src/lib.rs @@ -33,42 +33,7 @@ use crate::module::{chat::ChatModule, spawn::SpawnModule, stats::StatsModule}; #[derive(Component)] pub struct ProofOfConceptModule; -#[derive(Parser, Debug)] -#[command(name = "speed")] -struct SpeedCommand { - amount: f32, -} - -impl MinecraftCommand for SpeedCommand { - fn execute(self, world: &World, caller: Entity) { - let msg = format!("Setting speed to {}", self.amount); - let chat = agnostic::chat(msg); - - world.get::<&Compose>(|compose| { - caller - .entity_view(world) - .get::<&NetworkStreamRef>(|stream| { - let packet = fly_speed_packet(self.amount); - - let mut bundle = DataBundle::new(compose); - bundle.add_packet(&packet, world).unwrap(); - bundle.add_packet(&chat, world).unwrap(); - - bundle.send(world, *stream, SystemId(8)).unwrap(); - }); - }); - } -} - -fn fly_speed_packet(amount: f32) -> PlayerAbilitiesS2c { - PlayerAbilitiesS2c { - flags: PlayerAbilitiesFlags::default() - .with_allow_flying(true) - .with_flying(true), - flying_speed: amount, - fov_modifier: 0.0, - } -} +mod command; impl Module for ProofOfConceptModule { fn module(world: &World) { @@ -90,7 +55,7 @@ impl Module for ProofOfConceptModule { world.import::(); world.get::<&mut CommandRegistry>(|registry| { - SpeedCommand::register(registry, world); + command::register(registry, world); }); world.set(hyperion_utils::AppId {