From b3feddfef372618c8a9d7a0abcaf18cfad866c18 Mon Sep 17 00:00:00 2001 From: daoge <3523206925@qq.com> Date: Tue, 3 Mar 2026 03:04:10 +0800 Subject: 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 --- Minecraft.World/NearestAttackableTargetGoal.cpp | 60 ++++++++++++++----------- 1 file changed, 34 insertions(+), 26 deletions(-) (limited to 'Minecraft.World/NearestAttackableTargetGoal.cpp') 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) 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(entity), false); +} + NearestAttackableTargetGoal::DistComp::DistComp(Entity *source) { this->source = source; @@ -19,49 +37,39 @@ bool NearestAttackableTargetGoal::DistComp::operator() (shared_ptr 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 potentialTarget = mob->level->getNearestAttackablePlayer(mob->shared_from_this(), within); - if (canAttack(potentialTarget, false)) - { - target = weak_ptr(potentialTarget); - return true; - } - } - else + double within = getFollowDistance(); + + vector > *entities = mob->level->getEntitiesOfClass(targetType, mob->bb->grow(within, 4, within), selector); + + bool result = false; + if(entities != NULL && !entities->empty() ) { - vector > *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 potTarget = dynamic_pointer_cast(*it); - if (canAttack(potTarget, false)) - { - target = weak_ptr(potTarget); - return true; - } - } - delete entities; + target = weak_ptr(dynamic_pointer_cast(entities->at(0))); + result = true; } - return false; + + delete entities; + return result; } void NearestAttackableTargetGoal::start() -- cgit v1.2.3