66 lines
2.1 KiB
Rust
66 lines
2.1 KiB
Rust
use std::sync::{Arc, Weak};
|
|
|
|
use pumpkin_data::entity::EntityType;
|
|
|
|
use crate::entity::{
|
|
Entity, NBTStorage,
|
|
ai::goal::{
|
|
active_target::ActiveTargetGoal, look_around::RandomLookAroundGoal,
|
|
look_at_entity::LookAtEntityGoal, melee_attack::MeleeAttackGoal, revenge::RevengeGoal,
|
|
wander_around::WanderAroundGoal,
|
|
},
|
|
mob::{Mob, MobEntity},
|
|
};
|
|
|
|
/// Represents an Iron Golem, a powerful neutral mob that protects villagers and players.
|
|
///
|
|
/// Wiki: <https://minecraft.wiki/w/Iron_Golem>
|
|
pub struct IronGolemEntity {
|
|
pub mob_entity: MobEntity,
|
|
}
|
|
|
|
impl IronGolemEntity {
|
|
pub async fn new(entity: Entity) -> Arc<Self> {
|
|
let mob_entity = MobEntity::new(entity);
|
|
let iron_golem = Self { mob_entity };
|
|
let mob_arc = Arc::new(iron_golem);
|
|
let mob_weak: Weak<dyn Mob> = {
|
|
let mob_arc: Arc<dyn Mob> = mob_arc.clone();
|
|
Arc::downgrade(&mob_arc)
|
|
};
|
|
|
|
{
|
|
let mut goal_selector = mob_arc.mob_entity.goals_selector.lock().await;
|
|
let mut target_selector = mob_arc.mob_entity.target_selector.lock().await;
|
|
|
|
goal_selector.add_goal(1, Box::new(MeleeAttackGoal::new(1.0, true)));
|
|
goal_selector.add_goal(6, Box::new(WanderAroundGoal::new(0.6)));
|
|
goal_selector.add_goal(
|
|
7,
|
|
LookAtEntityGoal::with_default(mob_weak, &EntityType::PLAYER, 6.0),
|
|
);
|
|
goal_selector.add_goal(8, Box::new(RandomLookAroundGoal::default()));
|
|
|
|
target_selector.add_goal(1, Box::new(RevengeGoal::new(true)));
|
|
target_selector.add_goal(
|
|
2,
|
|
ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, false),
|
|
);
|
|
target_selector.add_goal(
|
|
3,
|
|
ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::ZOMBIE, true),
|
|
);
|
|
};
|
|
|
|
mob_arc
|
|
}
|
|
}
|
|
|
|
impl NBTStorage for IronGolemEntity {}
|
|
|
|
impl Mob for IronGolemEntity {
|
|
fn get_mob_entity(&self) -> &MobEntity {
|
|
&self.mob_entity
|
|
}
|
|
}
|