130 lines
4.1 KiB
Rust
130 lines
4.1 KiB
Rust
use std::sync::{Arc, Weak};
|
|
|
|
use pumpkin_data::entity::EntityType;
|
|
use pumpkin_data::sound::Sound;
|
|
use pumpkin_nbt::compound::NbtCompound;
|
|
|
|
use crate::entity::{
|
|
Entity, NbtFuture,
|
|
ai::goal::{
|
|
active_target::ActiveTargetGoal, look_around::RandomLookAroundGoal,
|
|
look_at_entity::LookAtEntityGoal, melee_attack::MeleeAttackGoal, open_door::OpenDoorGoal,
|
|
swim::SwimGoal, wander_around::WanderAroundGoal,
|
|
},
|
|
mob::{
|
|
Mob, MobEntity,
|
|
patrol::{LongDistancePatrolGoal, PatrolData, PatrollingMonster},
|
|
raider::{
|
|
HoldGroundAttackGoal, ObtainRaidLeaderBannerGoal, PathfindToRaidGoal, Raider,
|
|
RaiderCelebrationGoal, RaiderData, RaiderMoveThroughVillageGoal,
|
|
},
|
|
},
|
|
};
|
|
|
|
pub struct VindicatorEntity {
|
|
pub mob_entity: MobEntity,
|
|
pub raider_data: RaiderData,
|
|
}
|
|
|
|
impl VindicatorEntity {
|
|
#[must_use]
|
|
pub fn new(entity: Entity) -> Arc<Self> {
|
|
let mob_entity = MobEntity::new(entity);
|
|
let vindicator = Self {
|
|
mob_entity,
|
|
raider_data: RaiderData::default(),
|
|
};
|
|
let mob_arc = Arc::new(vindicator);
|
|
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()
|
|
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
|
|
|
goal_selector.add_goal(0, Box::new(SwimGoal::default()));
|
|
goal_selector.add_goal(1, Box::new(OpenDoorGoal::new(true)));
|
|
goal_selector.add_goal(1, Box::new(ObtainRaidLeaderBannerGoal));
|
|
goal_selector.add_goal(2, Box::new(HoldGroundAttackGoal::new(10.0)));
|
|
goal_selector.add_goal(3, Box::new(MeleeAttackGoal::new(1.0, true)));
|
|
goal_selector.add_goal(4, Box::new(LongDistancePatrolGoal::new(0.7, 0.595)));
|
|
goal_selector.add_goal(4, Box::new(RaiderMoveThroughVillageGoal::new(1.05)));
|
|
goal_selector.add_goal(4, Box::new(PathfindToRaidGoal::default()));
|
|
goal_selector.add_goal(5, Box::new(RaiderCelebrationGoal));
|
|
goal_selector.add_goal(5, Box::new(WanderAroundGoal::new(1.0)));
|
|
goal_selector.add_goal(
|
|
6,
|
|
LookAtEntityGoal::with_default(mob_weak, &EntityType::PLAYER, 8.0),
|
|
);
|
|
goal_selector.add_goal(7, Box::new(RandomLookAroundGoal::default()));
|
|
|
|
let mut target_selector = mob_arc
|
|
.mob_entity
|
|
.target_selector
|
|
.lock()
|
|
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
|
target_selector.add_goal(
|
|
1,
|
|
ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::PLAYER, true),
|
|
);
|
|
target_selector.add_goal(
|
|
2,
|
|
ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::VILLAGER, true),
|
|
);
|
|
target_selector.add_goal(
|
|
3,
|
|
ActiveTargetGoal::with_default(&mob_arc.mob_entity, &EntityType::IRON_GOLEM, true),
|
|
);
|
|
};
|
|
|
|
mob_arc
|
|
}
|
|
}
|
|
|
|
impl Mob for VindicatorEntity {
|
|
fn get_mob_entity(&self) -> &MobEntity {
|
|
&self.mob_entity
|
|
}
|
|
|
|
fn as_patrolling_monster(&self) -> Option<&dyn PatrollingMonster> {
|
|
Some(self)
|
|
}
|
|
|
|
fn as_raider(&self) -> Option<&dyn Raider> {
|
|
Some(self)
|
|
}
|
|
|
|
fn mob_write_nbt<'a>(&'a self, nbt: &'a mut NbtCompound) -> NbtFuture<'a, ()> {
|
|
Box::pin(async move {
|
|
self.write_raider_nbt(nbt);
|
|
})
|
|
}
|
|
|
|
fn mob_read_nbt<'a>(&'a self, nbt: &'a NbtCompound) -> NbtFuture<'a, ()> {
|
|
Box::pin(async move {
|
|
self.read_raider_nbt(nbt);
|
|
})
|
|
}
|
|
}
|
|
|
|
impl PatrollingMonster for VindicatorEntity {
|
|
fn get_patrol_data(&self) -> &PatrolData {
|
|
&self.raider_data.patrol_data
|
|
}
|
|
}
|
|
|
|
impl Raider for VindicatorEntity {
|
|
fn get_raider_data(&self) -> &RaiderData {
|
|
&self.raider_data
|
|
}
|
|
|
|
fn get_celebrate_sound(&self) -> Sound {
|
|
Sound::EntityVindicatorCelebrate
|
|
}
|
|
}
|