fix: Ocelot Can Be Tamed (#132)
Some checks failed
Nightly Release / Build Client (push) Has been cancelled
Nightly Release / Build Server (push) Has been cancelled
Nightly Release / Release Server (push) Has been cancelled
Nightly Release / Release Client (push) Has been cancelled
Sync branches with main / sync (push) Has been cancelled
Nightly Release / cleanup (push) Has been cancelled

* Revert "fix: ocelot couldnt be tamed"

This reverts commit 7701841381.

* fix: better implementd ocelots taming.
This commit is contained in:
Lord Cambion 2026-05-30 15:59:03 +02:00 committed by GitHub
parent 1cd3f977e4
commit 128651de24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 2 deletions

View file

@ -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<byte>(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> 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)
{

View file

@ -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