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/TradeWithPlayerGoal.cpp | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Minecraft.World/TradeWithPlayerGoal.cpp (limited to 'Minecraft.World/TradeWithPlayerGoal.cpp') diff --git a/Minecraft.World/TradeWithPlayerGoal.cpp b/Minecraft.World/TradeWithPlayerGoal.cpp new file mode 100644 index 00000000..e8b791d1 --- /dev/null +++ b/Minecraft.World/TradeWithPlayerGoal.cpp @@ -0,0 +1,51 @@ +#include "stdafx.h" +#include "net.minecraft.world.entity.npc.h" +#include "net.minecraft.world.entity.ai.control.h" +#include "net.minecraft.world.entity.ai.navigation.h" +#include "net.minecraft.world.inventory.h" +#include "TradeWithPlayerGoal.h" + +TradeWithPlayerGoal::TradeWithPlayerGoal(Villager *mob) +{ + this->mob = mob; + setRequiredControlFlags(Control::JumpControlFlag | Control::MoveControlFlag); +} + +bool TradeWithPlayerGoal::canUse() +{ + if (!mob->isAlive()) return false; + if (mob->isInWater()) return false; + if (!mob->onGround) return false; + if (mob->hurtMarked) return false; + + shared_ptr trader = mob->getTradingPlayer(); + if (trader == NULL) + { + // no interaction + return false; + } + + if (mob->distanceToSqr(trader) > (4 * 4)) + { + // too far away + return false; + } + + if (!(trader->containerMenu == trader->inventoryMenu)) + { + // closed container + return false; + } + + return true; +} + +void TradeWithPlayerGoal::start() +{ + mob->getNavigation()->stop(); +} + +void TradeWithPlayerGoal::stop() +{ + mob->setTradingPlayer(nullptr); +} \ No newline at end of file -- cgit v1.2.3