diff options
| author | daoge <3523206925@qq.com> | 2026-03-03 03:04:10 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-03 03:04:10 +0800 |
| commit | b3feddfef372618c8a9d7a0abcaf18cfad866c18 (patch) | |
| tree | 267761c3bb39241ba5c347bfbe2254d06686e287 /Minecraft.World/NearestAttackableTargetGoal.cpp | |
| parent | 84c31a2331f7a0ec85b9d438992e244f60e5020f (diff) | |
feat: TU19 (Dec 2014) Features & Content (#155)
* try to resolve merge conflict
* feat: TU19 (Dec 2014) Features & Content (#32)
* December 2014 files
* Working release build
* Fix compilation issues
* Add sound to Windows64Media
* Add DLC content and force Tutorial DLC
* Revert "Add DLC content and force Tutorial DLC"
This reverts commit 97a43994725008e35fceb984d5549df9c8cea470.
* Disable broken light packing
* Disable breakpoint during DLC texture map load
Allows DLC loading but the DLC textures are still broken
* Fix post build not working
* ...
* fix vs2022 build
* fix cmake build
---------
Co-authored-by: Loki <lokirautio@gmail.com>
Diffstat (limited to 'Minecraft.World/NearestAttackableTargetGoal.cpp')
| -rw-r--r-- | Minecraft.World/NearestAttackableTargetGoal.cpp | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/Minecraft.World/NearestAttackableTargetGoal.cpp b/Minecraft.World/NearestAttackableTargetGoal.cpp index 5ed9f4f1..1dbf587e 100644 --- a/Minecraft.World/NearestAttackableTargetGoal.cpp +++ b/Minecraft.World/NearestAttackableTargetGoal.cpp @@ -4,6 +4,24 @@ #include "net.minecraft.world.phys.h" #include "NearestAttackableTargetGoal.h" +SubselectEntitySelector::SubselectEntitySelector(NearestAttackableTargetGoal *parent, EntitySelector *subselector) +{ + m_parent = parent; + m_subselector = subselector; +} + +SubselectEntitySelector::~SubselectEntitySelector() +{ + delete m_subselector; +} + +bool SubselectEntitySelector::matches(shared_ptr<Entity> entity) const +{ + if (!entity->instanceof(eTYPE_LIVINGENTITY)) return false; + if (m_subselector != NULL && !m_subselector->matches(entity)) return false; + return m_parent->canAttack(dynamic_pointer_cast<LivingEntity>(entity), false); +} + NearestAttackableTargetGoal::DistComp::DistComp(Entity *source) { this->source = source; @@ -19,49 +37,39 @@ bool NearestAttackableTargetGoal::DistComp::operator() (shared_ptr<Entity> e1, s return true; } -NearestAttackableTargetGoal::NearestAttackableTargetGoal(Mob *mob, const type_info& targetType, float within, int randomInterval, bool mustSee, bool mustReach /*= false*/) : TargetGoal(mob, within, mustSee, mustReach), targetType(targetType) +NearestAttackableTargetGoal::NearestAttackableTargetGoal(PathfinderMob *mob, const type_info& targetType, int randomInterval, bool mustSee, bool mustReach /*= false*/, EntitySelector *entitySelector /* =NULL */) + : TargetGoal(mob, mustSee, mustReach), targetType(targetType) { - //this->targetType = targetType; - this->within = within; this->randomInterval = randomInterval; this->distComp = new DistComp(mob); setRequiredControlFlags(TargetGoal::TargetFlag); + + this->selector = new SubselectEntitySelector(this, entitySelector); } NearestAttackableTargetGoal::~NearestAttackableTargetGoal() { delete distComp; + delete selector; } bool NearestAttackableTargetGoal::canUse() { if (randomInterval > 0 && mob->getRandom()->nextInt(randomInterval) != 0) return false; - if (targetType == typeid(Player)) - { - shared_ptr<Mob> potentialTarget = mob->level->getNearestAttackablePlayer(mob->shared_from_this(), within); - if (canAttack(potentialTarget, false)) - { - target = weak_ptr<Mob>(potentialTarget); - return true; - } - } - else + double within = getFollowDistance(); + + vector<shared_ptr<Entity> > *entities = mob->level->getEntitiesOfClass(targetType, mob->bb->grow(within, 4, within), selector); + + bool result = false; + if(entities != NULL && !entities->empty() ) { - vector<shared_ptr<Entity> > *entities = mob->level->getEntitiesOfClass(targetType, mob->bb->grow(within, 4, within)); - //Collections.sort(entities, distComp); std::sort(entities->begin(), entities->end(), *distComp); - for(AUTO_VAR(it, entities->begin()); it != entities->end(); ++it) - { - shared_ptr<Mob> potTarget = dynamic_pointer_cast<Mob>(*it); - if (canAttack(potTarget, false)) - { - target = weak_ptr<Mob>(potTarget); - return true; - } - } - delete entities; + target = weak_ptr<LivingEntity>(dynamic_pointer_cast<LivingEntity>(entities->at(0))); + result = true; } - return false; + + delete entities; + return result; } void NearestAttackableTargetGoal::start() |
