@@ -2,6 +2,7 @@ use std::{borrow::Borrow, collections::HashMap, hash::Hash, num::TryFromIntError
22
33use anyhow:: Context ;
44use blocks:: Blocks ;
5+ use bow:: BowCharging ;
56use bytemuck:: { Pod , Zeroable } ;
67use derive_more:: { Constructor , Deref , DerefMut , Display , From } ;
78use flecs_ecs:: prelude:: * ;
@@ -29,6 +30,7 @@ use crate::{
2930
3031pub mod animation;
3132pub mod blocks;
33+ pub mod bow;
3234pub mod command;
3335pub mod entity_kind;
3436pub mod event;
@@ -634,6 +636,8 @@ impl Module for SimModule {
634636
635637 world. component :: < hyperion_inventory:: PlayerInventory > ( ) ;
636638
639+ world. component :: < BowCharging > ( ) ;
640+
637641 observer ! (
638642 world,
639643 Spawn ,
@@ -709,49 +713,53 @@ impl Module for SimModule {
709713 . kind :: < flecs:: pipeline:: OnStore > ( )
710714 . with_enum_wildcard :: < EntityKind > ( )
711715 . each_entity ( |entity, ( position, yaw, pitch, velocity) | {
712- if velocity. velocity != Vec3 :: ZERO {
713- // Update position based on velocity with delta time
714- position. x += velocity. velocity . x ;
715- position. y += velocity. velocity . y ;
716- position. z += velocity. velocity . z ;
717-
718- // re calculate yaw and pitch based on velocity
719- let ( new_yaw, new_pitch) = get_rotation_from_velocity ( velocity. velocity ) ;
720- * yaw = Yaw :: new ( new_yaw) ;
721- * pitch = Pitch :: new ( new_pitch) ;
722-
723- let ray = entity. get :: < ( & Position , & Yaw , & Pitch ) > ( |( position, yaw, pitch) | {
724- let center = * * position;
725-
726- let direction = get_direction_from_rotation ( * * yaw, * * pitch) ;
727-
728- geometry:: ray:: Ray :: new ( center, direction)
729- } ) ;
730-
731- entity. world ( ) . get :: < & mut Blocks > ( |blocks| {
732- // calculate distance limit based on velocity
733- let distance_limit = velocity. velocity . length ( ) ;
734- let Some ( collision) = blocks. first_collision ( ray, distance_limit) else {
735- velocity. velocity . x *= 0.99 ;
736- velocity. velocity . z *= 0.99 ;
737-
738- velocity. velocity . y -= 0.005 ;
739- return ;
740- } ;
741- debug ! ( "distance_limit = {}" , distance_limit) ;
742-
743- debug ! ( "collision = {collision:?}" ) ;
744-
745- velocity. velocity = Vec3 :: ZERO ;
746-
747- // Set arrow position to the collision location
748- * * position = collision. normal ;
749-
750- blocks
751- . set_block ( collision. location , BlockState :: DIRT )
752- . unwrap ( ) ;
753- } ) ;
754- }
716+ entity. get :: < & EntityKind > ( |kind| {
717+ if kind == & EntityKind :: Arrow && velocity. velocity != Vec3 :: ZERO {
718+ // Update position based on velocity with delta time
719+ position. x += velocity. velocity . x ;
720+ position. y += velocity. velocity . y ;
721+ position. z += velocity. velocity . z ;
722+
723+ // re calculate yaw and pitch based on velocity
724+ let ( new_yaw, new_pitch) = get_rotation_from_velocity ( velocity. velocity ) ;
725+ * yaw = Yaw :: new ( new_yaw) ;
726+ * pitch = Pitch :: new ( new_pitch) ;
727+
728+ let ray = entity. get :: < ( & Position , & Yaw , & Pitch ) > ( |( position, yaw, pitch) | {
729+ let center = * * position;
730+
731+ let direction = get_direction_from_rotation ( * * yaw, * * pitch) ;
732+
733+ geometry:: ray:: Ray :: new ( center, direction)
734+ } ) ;
735+
736+ #[ allow( clippy:: excessive_nesting) ]
737+ entity. world ( ) . get :: < & mut Blocks > ( |blocks| {
738+ // calculate distance limit based on velocity
739+ let distance_limit = velocity. velocity . length ( ) ;
740+ let Some ( collision) = blocks. first_collision ( ray, distance_limit) else {
741+ // i think this velocity calculations are all wrong someone redo please
742+ velocity. velocity . x *= 0.99 ;
743+ velocity. velocity . z *= 0.99 ;
744+
745+ velocity. velocity . y -= 0.05 ;
746+ return ;
747+ } ;
748+ debug ! ( "distance_limit = {}" , distance_limit) ;
749+
750+ debug ! ( "collision = {collision:?}" ) ;
751+
752+ velocity. velocity = Vec3 :: ZERO ;
753+
754+ // Set arrow position to the collision location
755+ * * position = collision. normal ;
756+
757+ blocks
758+ . set_block ( collision. location , BlockState :: DIRT )
759+ . unwrap ( ) ;
760+ } ) ;
761+ }
762+ } ) ;
755763 } ) ;
756764 }
757765}
0 commit comments