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/TargetGoal.cpp | 50 ++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 16 deletions(-) (limited to 'Minecraft.World/TargetGoal.cpp') diff --git a/Minecraft.World/TargetGoal.cpp b/Minecraft.World/TargetGoal.cpp index c3ac4f59..982acb5e 100644 --- a/Minecraft.World/TargetGoal.cpp +++ b/Minecraft.World/TargetGoal.cpp @@ -1,40 +1,43 @@ #include "stdafx.h" +#include "net.minecraft.world.entity.h" +#include "net.minecraft.world.entity.ai.attributes.h" #include "net.minecraft.world.entity.ai.navigation.h" #include "net.minecraft.world.entity.ai.sensing.h" -#include "net.minecraft.world.entity.h" #include "net.minecraft.world.entity.animal.h" +#include "net.minecraft.world.entity.monster.h" #include "net.minecraft.world.entity.player.h" #include "net.minecraft.world.level.pathfinder.h" #include "net.minecraft.world.phys.h" #include "TargetGoal.h" -void TargetGoal::_init(Mob *mob, float within, bool mustSee, bool mustReach) +void TargetGoal::_init(PathfinderMob *mob, bool mustSee, bool mustReach) { reachCache = EmptyReachCache; reachCacheTime = 0; unseenTicks = 0; this->mob = mob; - this->within = within; this->mustSee = mustSee; this->mustReach = mustReach; } -TargetGoal::TargetGoal(Mob *mob, float within, bool mustSee) +TargetGoal::TargetGoal(PathfinderMob *mob, bool mustSee) { - _init(mob, within, mustSee, false); + _init(mob, mustSee, false); } -TargetGoal::TargetGoal(Mob *mob, float within, bool mustSee, bool mustReach) +TargetGoal::TargetGoal(PathfinderMob *mob, bool mustSee, bool mustReach) { - _init(mob,within,mustSee,mustReach); + _init(mob,mustSee,mustReach); } bool TargetGoal::canContinueToUse() { - shared_ptr target = mob->getTarget(); + shared_ptr target = mob->getTarget(); if (target == NULL) return false; if (!target->isAlive()) return false; + + double within = getFollowDistance(); if (mob->distanceToSqr(target) > within * within) return false; if (mustSee) { @@ -50,6 +53,12 @@ bool TargetGoal::canContinueToUse() return true; } +double TargetGoal::getFollowDistance() +{ + AttributeInstance *followRange = mob->getAttribute(SharedMonsterAttributes::FOLLOW_RANGE); + return followRange == NULL ? 16 : followRange->getValue(); +} + void TargetGoal::start() { reachCache = EmptyReachCache; @@ -62,21 +71,30 @@ void TargetGoal::stop() mob->setTarget(nullptr); } -bool TargetGoal::canAttack(shared_ptr target, bool allowInvulnerable) +bool TargetGoal::canAttack(shared_ptr target, bool allowInvulnerable) { if (target == NULL) return false; if (target == mob->shared_from_this()) return false; if (!target->isAlive()) return false; if (!mob->canAttackType(target->GetType())) return false; - shared_ptr tamableAnimal = dynamic_pointer_cast(mob->shared_from_this()); - if (tamableAnimal != NULL && tamableAnimal->isTame()) + OwnableEntity *ownableMob = dynamic_cast(mob); + if (ownableMob != NULL && !ownableMob->getOwnerUUID().empty()) { - shared_ptr tamableTarget = dynamic_pointer_cast(target); - if (tamableTarget != NULL && tamableTarget->isTame()) return false; - if (target == tamableAnimal->getOwner()) return false; + shared_ptr ownableTarget = dynamic_pointer_cast(target); + if (ownableTarget != NULL && ownableMob->getOwnerUUID().compare(ownableTarget->getOwnerUUID()) == 0) + { + // We're attacking something owned by the same person... + return false; + } + + if (target == ownableMob->getOwner()) + { + // We're attacking our owner + return false; + } } - else if (dynamic_pointer_cast(target) != NULL) + else if (target->instanceof(eTYPE_PLAYER)) { if (!allowInvulnerable && (dynamic_pointer_cast(target))->abilities.invulnerable) return false; } @@ -95,7 +113,7 @@ bool TargetGoal::canAttack(shared_ptr target, bool allowInvulnerable) return true; } -bool TargetGoal::canReach(shared_ptr target) +bool TargetGoal::canReach(shared_ptr target) { reachCacheTime = 10 + mob->getRandom()->nextInt(5); Path *path = mob->getNavigation()->createPath(target); -- cgit v1.2.3