Skip to content
4 changes: 2 additions & 2 deletions steel-core/src/behavior/blocks/building/door_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use crate::{
BlockBehavior, BlockHitResult, BlockPlaceContext, BlockStateBehaviorExt, InteractionResult,
InventoryAccess, PlacementSource,
},
entity::Entity,
entity::ai::path::PathComputationType,
entity::{Entity, EntityId},
fluid::fluid_state_to_block,
player::Player,
world::{LevelReader, ScheduledTickAccess, World, game_event_context::GameEventContext},
Expand Down Expand Up @@ -175,7 +175,7 @@ impl DoorBlock {
world.destroy_block_effect(bottom_pos, u32::from(bottom_state.0), Some(player.id()));
}

fn play_sound(&self, world: &Arc<World>, pos: BlockPos, open: bool, exclude: Option<i32>) {
fn play_sound(&self, world: &Arc<World>, pos: BlockPos, open: bool, exclude: Option<EntityId>) {
let sound = if open {
self.sound_open
} else {
Expand Down
3 changes: 2 additions & 1 deletion steel-core/src/behavior/blocks/fluid/bubble_column_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ impl BlockBehavior for BubbleColumnBlock {

#[cfg(test)]
mod tests {
use crate::entity::EntityId;
use std::sync::Weak;

use glam::DVec3;
Expand Down Expand Up @@ -245,7 +246,7 @@ mod tests {
fn new() -> Self {
Self {
base: EntityBase::new(
1,
EntityId::new(1),
DVec3::ZERO,
vanilla_entities::ITEM.dimensions,
Weak::new(),
Expand Down
3 changes: 2 additions & 1 deletion steel-core/src/behavior/blocks/portal/end_portal_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ mod tests {
use crate::behavior::block::BlockBehavior;
use crate::behavior::{BlockStateBehaviorExt, init_behaviors};
use crate::block_entity::entities::{EndGatewayBlockEntity, EndPortalBlockEntity};
use crate::entity::EntityId;
use crate::entity::{Entity, EntityBase};
use crate::portal::PortalKind;
use crate::test_support::TestLevel;
Expand Down Expand Up @@ -225,7 +226,7 @@ mod tests {
fn new() -> Self {
Self {
base: EntityBase::new(
1,
EntityId::new(1),
DVec3::ZERO,
vanilla_entities::ITEM.dimensions,
Weak::new(),
Expand Down
3 changes: 2 additions & 1 deletion steel-core/src/behavior/blocks/portal/nether_portal_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl BlockBehavior for NetherPortalBlock {

#[cfg(test)]
mod tests {
use crate::entity::EntityId;
use std::sync::Weak;

use glam::DVec3;
Expand All @@ -96,7 +97,7 @@ mod tests {
fn new() -> Self {
Self {
base: EntityBase::new(
1,
EntityId::new(1),
DVec3::ZERO,
vanilla_entities::ITEM.dimensions,
Weak::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ impl SpeleothemBlockBehavior {

#[cfg(test)]
mod tests {
use crate::entity::EntityId;
use std::sync::Weak;

use super::*;
Expand All @@ -690,7 +691,12 @@ mod tests {
impl TestProjectile {
fn new(entity_type: EntityTypeRef, velocity: DVec3) -> Self {
let projectile = Self {
base: EntityBase::new(1, DVec3::ZERO, entity_type.dimensions, Weak::new()),
base: EntityBase::new(
EntityId::new(1),
DVec3::ZERO,
entity_type.dimensions,
Weak::new(),
),
projectile_base: ProjectileBase::new(),
entity_type,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl Vegetation for SweetBerryBushBlock {}

#[cfg(test)]
mod tests {
use crate::entity::EntityId;
use std::sync::Weak;

use steel_registry::{
Expand All @@ -269,7 +270,7 @@ mod tests {
fn living(entity_type: EntityTypeRef) -> Self {
Self {
base: EntityBase::new(
1,
EntityId::new(1),
DVec3::ZERO,
EntityDimensions::new(0.6, 1.8, 1.62),
Weak::<World>::new(),
Expand Down
7 changes: 5 additions & 2 deletions steel-core/src/behavior/items/mace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl MaceItem {
nearby_living.push_impulse(DVec3::new(horizontal.x, 0.7, horizontal.z));
if let Some(player) = nearby_living.as_player() {
player.send_packet(CSetEntityMotion::new(
nearby_living.id(),
nearby_living.id().get(),
nearby_living.velocity(),
));
}
Expand Down Expand Up @@ -198,7 +198,10 @@ impl ItemBehavior for MaceItem {
Self::calculate_impact_position(attacker),
);
if let Some(player) = attacker.as_player() {
player.send_packet(CSetEntityMotion::new(attacker.id(), attacker.velocity()));
player.send_packet(CSetEntityMotion::new(
attacker.id().get(),
attacker.velocity(),
));
}

if let Some(world) = attacker.level() {
Expand Down
4 changes: 3 additions & 1 deletion steel-core/src/chunk_saver/region_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use std::{
};

use rustc_hash::FxHashMap;

use crate::entity::EntityId;
use steel_utils::{ChunkPos, locks::AsyncRwLock};
use tokio::{
fs::{self, File, OpenOptions},
Expand Down Expand Up @@ -47,7 +49,7 @@ pub struct PreparedChunkSave {
/// The serialized chunk data.
pub persistent: PersistentChunk,
/// Runtime manager entity IDs that were either serialized or explicitly skipped.
pub handled_runtime_entity_ids: Vec<i32>,
pub handled_runtime_entity_ids: Vec<EntityId>,
}

/// An open region file with its header.
Expand Down
8 changes: 4 additions & 4 deletions steel-core/src/chunk_saver/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::chunk::proto_chunk::ProtoChunk;
use crate::chunk::section::{ChunkSection, SectionHolder, Sections};
use crate::chunk_saver::bit_pack::{bits_for_palette_len, pack_indices, unpack_indices};
use crate::entity::{
ENTITIES, Entity, EntityBase, EntityBaseSaveData, EntityFireFreezeState, EntityLoadRequest,
MAX_ENTITY_TAGS, RemovalReason, SharedEntity,
ENTITIES, Entity, EntityBase, EntityBaseSaveData, EntityFireFreezeState, EntityId,
EntityLoadRequest, MAX_ENTITY_TAGS, RemovalReason, SharedEntity,
};
use crate::world::World;
use crate::world::tick_scheduler::{BlockTickList, FluidTickList, ScheduledTick, TickPriority};
Expand Down Expand Up @@ -706,7 +706,7 @@ impl ChunkStorage {
fn assert_unique_save_uuid(
seen_uuids: &mut FxHashSet<uuid::Uuid>,
uuid: uuid::Uuid,
entity_id: i32,
entity_id: EntityId,
chunk_pos: ChunkPos,
) {
assert!(
Expand Down Expand Up @@ -1074,7 +1074,7 @@ impl ChunkStorage {

fn entity_to_persistent(
entity: &SharedEntity,
visited: &mut FxHashSet<i32>,
visited: &mut FxHashSet<EntityId>,
mode: EntityPersistenceMode,
) -> Option<PersistentEntity> {
if !Self::entity_should_persist(entity.as_ref(), mode) {
Expand Down
8 changes: 7 additions & 1 deletion steel-core/src/command/builtins/enchant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ fn missing_argument(name: &str) -> CommandSyntaxError {

#[cfg(test)]
mod tests {
use crate::entity::EntityId;
use std::sync::Weak;

use glam::DVec3;
Expand Down Expand Up @@ -313,7 +314,12 @@ mod tests {
impl TestLivingEntity {
fn new(entity_type: EntityTypeRef) -> Self {
Self {
base: EntityBase::new(1, DVec3::ZERO, entity_type.dimensions, Weak::new()),
base: EntityBase::new(
EntityId::new(1),
DVec3::ZERO,
entity_type.dimensions,
Weak::new(),
),
living_base: LivingEntityBase::new(entity_type),
health: SyncMutex::new(20.0),
entity_type,
Expand Down
6 changes: 3 additions & 3 deletions steel-core/src/command/builtins/teleport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,16 @@ fn perform_teleport(
let world = player.get_world();
world.broadcast_to_entity_trackers(
player.id(),
CAnimate::new(player.id(), AnimateAction::WakeUp),
CAnimate::new(player.id().get(), AnimateAction::WakeUp),
None,
);
player.send_packet(CAnimate::new(player.id(), AnimateAction::WakeUp));
player.send_packet(CAnimate::new(player.id().get(), AnimateAction::WakeUp));
player.stop_sleeping();
player.set_pose(EntityPose::Standing);
// TODO: Complete bed occupancy and sleep aggregation updates with the bed system.
}
player.send_packet(CSetCamera {
camera_id: player.id(),
camera_id: player.id().get(),
});
}
if change_entity_world(Arc::clone(target), &transition).is_none() {
Expand Down
3 changes: 2 additions & 1 deletion steel-core/src/command/execution/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2471,6 +2471,7 @@ const fn is_quoted_string_start(ch: char) -> bool {

#[cfg(test)]
mod tests {
use crate::entity::EntityId;
use std::sync::Weak;

use glam::DVec3;
Expand Down Expand Up @@ -2504,7 +2505,7 @@ mod tests {
fn new() -> Self {
Self {
base: EntityBase::new(
1,
EntityId::new(1),
DVec3::ZERO,
vanilla_entities::ITEM.dimensions,
Weak::new(),
Expand Down
3 changes: 2 additions & 1 deletion steel-core/src/command/execution/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ fn normalize_rotation((mut yaw, mut pitch): (f32, f32)) -> (f32, f32) {

#[cfg(test)]
mod tests {
use crate::entity::EntityId;
use std::sync::Weak;

use glam::DVec3;
Expand Down Expand Up @@ -847,7 +848,7 @@ mod tests {
fn admin_broadcast_uses_current_execution_entity_name() {
let entity = NamedTestEntity {
base: EntityBase::new(
1,
EntityId::new(1),
DVec3::ZERO,
vanilla_entities::ITEM.dimensions,
Weak::new(),
Expand Down
7 changes: 4 additions & 3 deletions steel-core/src/enchantment_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ fn damage_source_predicate_matches(

#[cfg(test)]
mod tests {
use crate::entity::EntityId;
use std::sync::Weak;

use glam::DVec3;
Expand Down Expand Up @@ -1024,9 +1025,9 @@ mod tests {
}

impl TestLivingEntity {
fn new(id: i32, entity_type: EntityTypeRef) -> Self {
fn new(id: impl Into<EntityId>, entity_type: EntityTypeRef) -> Self {
Self {
base: EntityBase::new(id, DVec3::ZERO, entity_type.dimensions, Weak::new()),
base: EntityBase::new(id.into(), DVec3::ZERO, entity_type.dimensions, Weak::new()),
living_base: LivingEntityBase::new(entity_type),
health: SyncMutex::new(20.0),
broken_slots: SyncMutex::new(Vec::new()),
Expand Down Expand Up @@ -1362,7 +1363,7 @@ mod tests {
let owner = TestLivingEntity::new(1, &vanilla_entities::PLAYER);
let projectile = FireworkRocketEntity::new(
&vanilla_entities::FIREWORK_ROCKET,
2,
EntityId::new(2),
DVec3::ZERO,
Weak::new(),
);
Expand Down
3 changes: 2 additions & 1 deletion steel-core/src/entity/ageable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ pub trait AgeableMob: Mob {

#[cfg(test)]
mod tests {
use crate::entity::EntityId;
use std::sync::Weak;

use glam::DVec3;
Expand All @@ -357,7 +358,7 @@ mod tests {
init_test_registry();
Self {
base: EntityBase::new(
1,
EntityId::new(1),
DVec3::ZERO,
vanilla_entities::PIG.dimensions,
Weak::new(),
Expand Down
19 changes: 19 additions & 0 deletions steel-core/src/entity/ai/brain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Brain AI.

mod activity;
mod behavior;
mod container;
mod memory;
mod schedule;
mod sensor;

pub(crate) use activity::Activity;
pub(crate) use behavior::{
AcquireBed, AcquireJobSite, AssignProfession, LookAtTargetSink, MoveToTargetSink,
SetEntityLookTarget, SetWalkTargetFromHome, SetWalkTargetFromJobSite, SleepInBed,
StrollAroundPoi, VillageBoundRandomStroll, WorkAtPoi,
};
pub(crate) use container::Brain;
pub(crate) use memory::MemoryModuleType;
pub(crate) use schedule::Schedule;
pub(crate) use sensor::NearestLivingEntitiesSensor;
13 changes: 13 additions & 0 deletions steel-core/src/entity/ai/brain/activity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Named behavior groups a brain can have

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) enum Activity {
Core,
Idle,
Fight,
Panic,
Work,
Rest,
Meet,
Play,
}
Loading
Loading