From 128651de242de9a7ed47bcb304c7fc9c635e1437 Mon Sep 17 00:00:00 2001 From: Lord Cambion Date: Sat, 30 May 2026 15:59:03 +0200 Subject: [PATCH] fix: Ocelot Can Be Tamed (#132) * Revert "fix: ocelot couldnt be tamed" This reverts commit 77018413814ceb32088faba31a0f526a0a6160f7. * fix: better implementd ocelots taming. --- Minecraft.World/Ocelot.cpp | 27 +++++++++++++++++++++++++-- Minecraft.World/Ocelot.h | 5 +++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Minecraft.World/Ocelot.cpp b/Minecraft.World/Ocelot.cpp index 02ef07c1..6816cabc 100644 --- a/Minecraft.World/Ocelot.cpp +++ b/Minecraft.World/Ocelot.cpp @@ -35,13 +35,16 @@ Ocelot::Ocelot(Level *level) : TamableAnimal(level) registerAttributes(); setHealth(getMaxHealth()); + avoidPlayerGoal = nullptr; + + reassessTameGoals(); + setSize(0.6f, 0.8f); getNavigation()->setAvoidWater(true); goalSelector.addGoal(1, new FloatGoal(this)); goalSelector.addGoal(2, sitGoal, false); goalSelector.addGoal(3, temptGoal = new TemptGoal(this, SNEAK_SPEED_MOD, Item::fish_raw_Id, true), false); - goalSelector.addGoal(4, new AvoidPlayerGoal(this, typeid(Player), 16, WALK_SPEED_MOD, SPRINT_SPEED_MOD)); goalSelector.addGoal(5, new FollowOwnerGoal(this, FOLLOW_SPEED_MOD, 10, 5)); goalSelector.addGoal(6, new OcelotSitOnTileGoal(this, SPRINT_SPEED_MOD)); goalSelector.addGoal(7, new LeapAtTargetGoal(this, 0.3f)); @@ -60,6 +63,21 @@ void Ocelot::defineSynchedData() entityData->define(DATA_TYPE_ID, static_cast(0)); } +void Ocelot::reassessTameGoals() +{ + if (!avoidPlayerGoal) + avoidPlayerGoal = new AvoidPlayerGoal(this, typeid(Player), 16, WALK_SPEED_MOD, SPRINT_SPEED_MOD); + + goalSelector.removeGoal(avoidPlayerGoal); + if (!isTame()) + goalSelector.addGoal(4, avoidPlayerGoal, false); +} + +void Ocelot::setTame(bool tame) +{ + TamableAnimal::setTame(tame); +} + void Ocelot::serverAiMobStep() { if (getMoveControl()->hasWanted()) @@ -199,7 +217,10 @@ bool Ocelot::mobInteract(shared_ptr player) } else { - if (/*temptGoal->isRunning() &&*/ item != nullptr && item->id == Item::fish_raw_Id && player->distanceToSqr(shared_from_this()) < 3 * 3) + //player must be close holding raw fish + // temptGoal->isRunning() check removed + // when the player enters interaction range, which would block taming entirely + if (item != nullptr && item->id == Item::fish_raw_Id && player->distanceToSqr(shared_from_this()) < 3 * 3) { // 4J-PB - don't lose the fish in creative mode if (!player->abilities.instabuild) item->count--; @@ -284,6 +305,8 @@ void Ocelot::setCatType(int type) bool Ocelot::canSpawn() { + + //return level->random->nextInt(3) != 0; when checkSpawnObstruction is implemented // artificially make ozelots more rare if (level->random->nextInt(3) == 0) { diff --git a/Minecraft.World/Ocelot.h b/Minecraft.World/Ocelot.h index 7f02bf02..8336f856 100644 --- a/Minecraft.World/Ocelot.h +++ b/Minecraft.World/Ocelot.h @@ -1,6 +1,7 @@ #pragma once #include "TamableAnimal.h" +#include "AvoidPlayerGoal.h" class TemptGoal; @@ -32,6 +33,7 @@ public: private: TemptGoal *temptGoal; + AvoidPlayerGoal *avoidPlayerGoal; public: Ocelot(Level *level); @@ -41,6 +43,8 @@ protected: public: virtual void serverAiMobStep(); + virtual void reassessTameGoals(); + virtual void setTame(bool tame); protected: virtual bool removeWhenFarAway(); @@ -78,6 +82,7 @@ public: virtual int getCatType(); virtual void setCatType(int type); virtual bool canSpawn(); + //virtual bool checkSpawnObstruction(); TODO when blockstates will be merged. virtual wstring getAName(); virtual MobGroupData *finalizeMobSpawn(MobGroupData *groupData, int extraData = 0); // 4J Added extraData param