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/SitGoal.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Minecraft.World/SitGoal.cpp (limited to 'Minecraft.World/SitGoal.cpp') diff --git a/Minecraft.World/SitGoal.cpp b/Minecraft.World/SitGoal.cpp new file mode 100644 index 00000000..90180201 --- /dev/null +++ b/Minecraft.World/SitGoal.cpp @@ -0,0 +1,45 @@ +#include "stdafx.h" +#include "net.minecraft.world.entity.ai.control.h" +#include "net.minecraft.world.entity.ai.goal.h" +#include "net.minecraft.world.entity.ai.navigation.h" +#include "net.minecraft.world.entity.h" +#include "net.minecraft.world.entity.animal.h" +#include "SitGoal.h" + +SitGoal::SitGoal(TamableAnimal *mob) +{ + _wantToSit = false; + + this->mob = mob; + setRequiredControlFlags(Control::JumpControlFlag | Control::MoveControlFlag); +} + +bool SitGoal::canUse() +{ + if (!mob->isTame()) return false; + if (mob->isInWater()) return false; + if (!mob->onGround) return false; + + shared_ptr owner = mob->getOwner(); + if (owner == NULL) return true; // owner not on level + + if (mob->distanceToSqr(owner) < FollowOwnerGoal::TeleportDistance * FollowOwnerGoal::TeleportDistance && owner->getLastHurtByMob() != NULL) return false; + + return _wantToSit; +} + +void SitGoal::start() +{ + mob->getNavigation()->stop(); + mob->setSitting(true); +} + +void SitGoal::stop() +{ + mob->setSitting(false); +} + +void SitGoal::wantToSit(bool _wantToSit) +{ + this->_wantToSit = _wantToSit; +} \ No newline at end of file -- cgit v1.2.3