Moved the whole logic to a new file (TooltipManager.cpp), and rewrote most of the logic to profit from object oriented programming. The side-effect is that the changes are scattered across entities, tiles and items because moving everything to OOP requires to add the tooltip to every .cpp file for every tile/item/entities (or their class, on plants for example which all use the tooltip IDS_TOOLTIPS_PLANT)
The issue with the default tooltips loop written by 4J is that:
Its running in the main Minecraft::tick loop and is more than a thousand lines long, polluting the function.
Not using C++'s full potential with object oriented programming, 4J decided to use a big switch case (probably because it could run better on hardware without branch prediction like the WiiU or Xbox 360 ?)
And seems to be better off in its own file than in the main Minecraft.cpp file
139 lines
4.0 KiB
C++
139 lines
4.0 KiB
C++
#include "stdafx.h"
|
|
#include "net.minecraft.world.level.h"
|
|
#include "net.minecraft.world.level.tile.h"
|
|
#include "net.minecraft.world.item.h"
|
|
#include "net.minecraft.world.entity.player.h"
|
|
#include "net.minecraft.world.entity.item.h"
|
|
#include "../Minecraft.Client/Textures.h"
|
|
#include "MushroomCow.h"
|
|
#include "MobCategory.h"
|
|
#include "AABB.h"
|
|
|
|
|
|
|
|
MushroomCow::MushroomCow(Level *level) : Cow(level)
|
|
{
|
|
// 4J Stu - This function call had to be moved here from the Entity ctor to ensure that
|
|
// the derived version of the function is called
|
|
this->defineSynchedData();
|
|
setHealth(getMaxHealth());
|
|
|
|
this->setSize(0.9f, 1.3f);
|
|
}
|
|
|
|
bool MushroomCow::mobInteract(shared_ptr<Player> player)
|
|
{
|
|
shared_ptr<ItemInstance> item = player->inventory->getSelected();
|
|
if (item != nullptr && item->id == Item::bowl_Id && getAge() >= 0)
|
|
{
|
|
if (item->count == 1)
|
|
{
|
|
player->inventory->setItem(player->inventory->selected, std::make_shared<ItemInstance>(Item::mushroom_stew));
|
|
return true;
|
|
}
|
|
|
|
if (player->inventory->add(std::make_shared<ItemInstance>(Item::mushroom_stew)) && !player->abilities.instabuild)
|
|
{
|
|
player->inventory->removeItem(player->inventory->selected, 1);
|
|
return true;
|
|
}
|
|
}
|
|
// 4J: Do not allow shearing if we can't create more cows
|
|
if (item != nullptr && item->id == Item::shears_Id && getAge() >= 0 && level->canCreateMore(eTYPE_COW, Level::eSpawnType_Breed))
|
|
{
|
|
remove();
|
|
level->addParticle(eParticleType_largeexplode, x, y + bbHeight / 2, z, 0, 0, 0);
|
|
if(!level->isClientSide)
|
|
{
|
|
remove();
|
|
shared_ptr<Cow> cow = std::make_shared<Cow>(level);
|
|
cow->moveTo(x, y, z, yRot, xRot);
|
|
cow->setHealth(getHealth());
|
|
cow->yBodyRot = yBodyRot;
|
|
level->addEntity(cow);
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
level->addEntity(std::make_shared<ItemEntity>(level, x, y + bbHeight, z, shared_ptr<ItemInstance>(new ItemInstance(Tile::mushroom_red))));
|
|
}
|
|
return true;
|
|
}
|
|
return true;
|
|
}
|
|
return Cow::mobInteract(player);
|
|
}
|
|
|
|
// 4J - added so that mushroom cows have more of a chance of spawning, they can now spawn on mycelium as well as grass - seems a bit odd that they don't already really
|
|
bool MushroomCow::canSpawn()
|
|
{
|
|
int xt = Mth::floor(x);
|
|
int yt = Mth::floor(bb->y0);
|
|
int zt = Mth::floor(z);
|
|
return ( level->getTile(xt, yt - 1, zt) == Tile::grass_Id || level->getTile(xt, yt - 1, zt) == Tile::mycelium_Id ) && level->getDaytimeRawBrightness(xt, yt, zt) > 8 && PathfinderMob::canSpawn();
|
|
}
|
|
|
|
shared_ptr<AgableMob> MushroomCow::getBreedOffspring(shared_ptr<AgableMob> target)
|
|
{
|
|
// 4J - added limit to number of animals that can be bred
|
|
if( level->canCreateMore( GetType(), Level::eSpawnType_Breed) )
|
|
{
|
|
return std::make_shared<MushroomCow>(level);
|
|
}
|
|
else
|
|
{
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
int MushroomCow::getAttackTooltipId(std::shared_ptr<Player> player)
|
|
{
|
|
if (player->isAllowedToAttackAnimals())
|
|
{
|
|
return IDS_TOOLTIPS_HIT;
|
|
}
|
|
}
|
|
|
|
int MushroomCow::getInteractTooltipId(Level *level,
|
|
std::shared_ptr<Player> player,
|
|
std::shared_ptr<ItemInstance> heldItem)
|
|
{
|
|
int heldItemId = -1;
|
|
if (heldItem != nullptr && heldItem->getItem() != nullptr)
|
|
heldItemId = heldItem->getItem()->id;
|
|
|
|
if (this->isLeashed() && this->getLeashHolder() == player)
|
|
return IDS_TOOLTIPS_UNLEASH;
|
|
|
|
// It's an item
|
|
switch (heldItemId)
|
|
{
|
|
// Things to USE
|
|
case Item::name_tag_Id:
|
|
return IDS_TOOLTIPS_NAME;
|
|
|
|
case Item::lead_Id:
|
|
if (!this->isLeashed())
|
|
return IDS_TOOLTIPS_LEASH;
|
|
|
|
case Item::bowl_Id:
|
|
case Item::bucket_Id: // You can milk a mooshroom with either a bowl (mushroom soup) or a bucket (milk)!
|
|
return IDS_TOOLTIPS_MILK;
|
|
|
|
case Item::shears_Id:
|
|
if (!this->isBaby())
|
|
{
|
|
return IDS_TOOLTIPS_SHEAR;
|
|
}
|
|
|
|
default:
|
|
if (!this->isBaby() && !this->isInLove() && (this->getAge() == 0) && this->isFood(heldItem))
|
|
{
|
|
return IDS_TOOLTIPS_LOVEMODE;
|
|
}
|
|
|
|
case -1:
|
|
break; // 4J-JEV: Empty hand.
|
|
}
|
|
|
|
return 0;
|
|
}
|