-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Spawn Egg Functionality (#350)
* Added spawn egg functionality * Readd changes from before merge * Added basic attacks on mobs * Fixed spawn rotation and position * Updated entities.json * Fixed entity registry * Added correct bounding boxes per entity * Various fixes * use right data types in entity registry * fix: clippy --------- Co-authored-by: Alexander Medvedev <[email protected]>
- Loading branch information
1 parent
02cec58
commit 6f7433e
Showing
12 changed files
with
347 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::{collections::HashMap, sync::LazyLock}; | ||
|
||
use serde::Deserialize; | ||
|
||
const ENTITIES_JSON: &str = include_str!("../../../assets/entities.json"); | ||
|
||
pub static ENTITIES: LazyLock<HashMap<String, Entity>> = LazyLock::new(|| { | ||
serde_json::from_str(ENTITIES_JSON).expect("Could not parse entity.json registry.") | ||
}); | ||
|
||
pub static ENTITIES_BY_ID: LazyLock<HashMap<String, u16>> = LazyLock::new(|| { | ||
let mut map = HashMap::new(); | ||
for (entity_name, entity) in ENTITIES.iter() { | ||
map.insert(entity_name.clone(), entity.id); | ||
} | ||
map | ||
}); | ||
|
||
pub fn get_entity_id(name: &str) -> Option<&u16> { | ||
ENTITIES_BY_ID.get(&name.replace("minecraft:", "")) | ||
} | ||
|
||
pub fn get_entity_by_id<'a>(entity_id: u16) -> Option<&'a Entity> { | ||
ENTITIES.values().find(|&entity| entity.id == entity_id) | ||
} | ||
|
||
#[derive(Deserialize, Clone, Debug)] | ||
pub struct Entity { | ||
pub id: u16, | ||
pub max_health: Option<f32>, | ||
pub attackable: bool, | ||
pub summonable: bool, | ||
pub fire_immune: bool, | ||
pub dimension: [f32; 2], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod entity_registry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.