@@ -2,6 +2,7 @@ use std::{borrow::Borrow, collections::HashMap, hash::Hash, num::TryFromIntError
2
2
3
3
use anyhow:: Context ;
4
4
use blocks:: Blocks ;
5
+ use bow:: BowCharging ;
5
6
use bytemuck:: { Pod , Zeroable } ;
6
7
use derive_more:: { Constructor , Deref , DerefMut , Display , From } ;
7
8
use flecs_ecs:: prelude:: * ;
@@ -29,6 +30,7 @@ use crate::{
29
30
30
31
pub mod animation;
31
32
pub mod blocks;
33
+ pub mod bow;
32
34
pub mod command;
33
35
pub mod entity_kind;
34
36
pub mod event;
@@ -634,6 +636,8 @@ impl Module for SimModule {
634
636
635
637
world. component :: < hyperion_inventory:: PlayerInventory > ( ) ;
636
638
639
+ world. component :: < BowCharging > ( ) ;
640
+
637
641
observer ! (
638
642
world,
639
643
Spawn ,
@@ -709,49 +713,53 @@ impl Module for SimModule {
709
713
. kind :: < flecs:: pipeline:: OnStore > ( )
710
714
. with_enum_wildcard :: < EntityKind > ( )
711
715
. 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
+ } ) ;
755
763
} ) ;
756
764
}
757
765
}
0 commit comments