1use azalea_block::fluid_state::FluidKind;
2use azalea_core::{
3 entity_id::MinecraftEntityId,
4 position::{BlockPos, ChunkPos, Vec3},
5};
6use azalea_registry::builtin::EntityKind;
7use azalea_world::WorldName;
8use bevy_ecs::{bundle::Bundle, component::Component};
9use derive_more::{Deref, DerefMut};
10use uuid::Uuid;
11
12use crate::{
13 ActiveEffects, Attributes, EntityUuid, FluidOnEyes, LookDirection, Physics, Position,
14 dimensions::EntityDimensions, indexing::EntityChunkPos,
15};
16
17#[derive(Bundle)]
21pub struct EntityBundle {
22 pub kind: EntityKindComponent,
23 pub minecraft_id: MinecraftEntityId,
24 pub uuid: EntityUuid,
25 pub world_name: WorldName,
26 pub position: Position,
27 pub last_sent_position: LastSentPosition,
28
29 pub chunk_pos: EntityChunkPos,
30
31 pub physics: Physics,
32 pub direction: LookDirection,
33 pub dimensions: EntityDimensions,
34 pub attributes: Attributes,
35 pub jumping: Jumping,
36 pub crouching: Crouching,
37 pub fluid_on_eyes: FluidOnEyes,
38 pub on_climbable: OnClimbable,
39 pub active_effects: ActiveEffects,
40}
41
42impl EntityBundle {
43 pub fn new(
44 uuid: Uuid,
45 minecraft_id: MinecraftEntityId,
46 pos: Vec3,
47 kind: EntityKind,
48 world_name: WorldName,
49 ) -> Self {
50 let dimensions = EntityDimensions::from(kind);
51
52 Self {
53 kind: EntityKindComponent(kind),
54 minecraft_id,
55 uuid: EntityUuid(uuid),
56 world_name,
57 position: Position(pos),
58 chunk_pos: EntityChunkPos(ChunkPos::from(&pos)),
59 last_sent_position: LastSentPosition(pos),
60 physics: Physics::new(&dimensions, pos),
61 dimensions,
62 direction: LookDirection::default(),
63
64 attributes: Attributes::new(EntityKind::Player),
65
66 jumping: Jumping(false),
67 crouching: Crouching(false),
68 fluid_on_eyes: FluidOnEyes(FluidKind::Empty),
69 on_climbable: OnClimbable(false),
70 active_effects: ActiveEffects::default(),
71 }
72 }
73}
74
75#[derive(Clone, Component, Copy, Default)]
79pub struct Dead;
80
81#[derive(Clone, Component, Copy, Debug, Deref, PartialEq)]
86pub struct EntityKindComponent(pub EntityKind);
87
88#[derive(Clone, Component, Copy, Debug, Default)]
95pub struct LocalEntity;
96
97impl FluidOnEyes {
98 pub fn new(fluid: FluidKind) -> Self {
99 Self(fluid)
100 }
101}
102
103#[derive(Clone, Component, Copy, Debug, Deref, DerefMut, PartialEq)]
104pub struct OnClimbable(bool);
105
106#[derive(Clone, Component, Copy, Default, Deref, DerefMut)]
117pub struct Crouching(bool);
118
119#[derive(Component)]
123pub struct HasClientLoaded;
124
125#[derive(Clone, Copy, Component, Debug, Default, Deref, DerefMut, PartialEq)]
130pub struct LastSentPosition(Vec3);
131impl From<&LastSentPosition> for Vec3 {
132 fn from(value: &LastSentPosition) -> Self {
133 value.0
134 }
135}
136impl From<LastSentPosition> for ChunkPos {
137 fn from(value: LastSentPosition) -> Self {
138 ChunkPos::from(&value.0)
139 }
140}
141impl From<LastSentPosition> for BlockPos {
142 fn from(value: LastSentPosition) -> Self {
143 BlockPos::from(&value.0)
144 }
145}
146impl From<&LastSentPosition> for ChunkPos {
147 fn from(value: &LastSentPosition) -> Self {
148 ChunkPos::from(value.0)
149 }
150}
151impl From<&LastSentPosition> for BlockPos {
152 fn from(value: &LastSentPosition) -> Self {
153 BlockPos::from(value.0)
154 }
155}
156
157#[derive(Clone, Copy, Component, Debug, Default, Deref, DerefMut, Eq, PartialEq)]
162pub struct Jumping(pub bool);