From b691c43c44ff180d10e7d4a9afc83b98551ff586 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Sun, 1 Mar 2026 12:16:08 +0800 Subject: Initial commit --- Minecraft.World/SwellGoal.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Minecraft.World/SwellGoal.cpp (limited to 'Minecraft.World/SwellGoal.cpp') diff --git a/Minecraft.World/SwellGoal.cpp b/Minecraft.World/SwellGoal.cpp new file mode 100644 index 00000000..9065ba16 --- /dev/null +++ b/Minecraft.World/SwellGoal.cpp @@ -0,0 +1,54 @@ +#include "stdafx.h" +#include "net.minecraft.world.entity.ai.control.h" +#include "net.minecraft.world.entity.ai.sensing.h" +#include "net.minecraft.world.entity.ai.navigation.h" +#include "net.minecraft.world.entity.monster.h" +#include "SwellGoal.h" + +SwellGoal::SwellGoal(Creeper *creeper) +{ + target = weak_ptr(); + + this->creeper = creeper; + setRequiredControlFlags(Control::MoveControlFlag); +} + +bool SwellGoal::canUse() +{ + shared_ptr target = creeper->getTarget(); + return creeper->getSwellDir() > 0 || (target != NULL && (creeper->distanceToSqr(target) < 3 * 3)); +} + +void SwellGoal::start() +{ + creeper->getNavigation()->stop(); + target = weak_ptr(creeper->getTarget()); +} + +void SwellGoal::stop() +{ + target = weak_ptr(); +} + +void SwellGoal::tick() +{ + if (target.lock() == NULL) + { + creeper->setSwellDir(-1); + return; + } + + if (creeper->distanceToSqr(target.lock()) > 7 * 7) + { + creeper->setSwellDir(-1); + return; + } + + if (!creeper->getSensing()->canSee(target.lock())) + { + creeper->setSwellDir(-1); + return; + } + + creeper->setSwellDir(1); +} -- cgit v1.2.3