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
60 lines
2.5 KiB
C++
60 lines
2.5 KiB
C++
#pragma once
|
|
using namespace std;
|
|
#include "Item.h"
|
|
|
|
class MobEffectInstance;
|
|
|
|
class PotionItem : public Item
|
|
{
|
|
private:
|
|
static const int DRINK_DURATION = static_cast<int>(20 * 1.6);
|
|
|
|
public:
|
|
static const wstring DEFAULT_ICON;
|
|
static const wstring THROWABLE_ICON;
|
|
static const wstring CONTENTS_ICON;
|
|
|
|
private:
|
|
unordered_map<int, vector<MobEffectInstance *> *> cachedMobEffects;
|
|
|
|
Icon *iconThrowable;
|
|
Icon *iconDrinkable;
|
|
Icon *iconOverlay;
|
|
|
|
public:
|
|
PotionItem(int id);
|
|
|
|
virtual vector<MobEffectInstance *> *getMobEffects(shared_ptr<ItemInstance> potion);
|
|
virtual vector<MobEffectInstance *> *getMobEffects(int auxValue);
|
|
virtual shared_ptr<ItemInstance> useTimeDepleted(shared_ptr<ItemInstance> instance, Level *level, shared_ptr<Player> player);
|
|
virtual int getUseDuration(shared_ptr<ItemInstance> itemInstance);
|
|
virtual UseAnim getUseAnimation(shared_ptr<ItemInstance> itemInstance);
|
|
virtual shared_ptr<ItemInstance> use(shared_ptr<ItemInstance> instance, Level *level, shared_ptr<Player> player);
|
|
virtual bool TestUse(shared_ptr<ItemInstance> itemInstance, Level *level, shared_ptr<Player> player);
|
|
virtual bool useOn(shared_ptr<ItemInstance> itemInstance, shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
|
|
virtual Icon *getIcon(int auxValue);
|
|
virtual Icon *getLayerIcon(int auxValue, int spriteLayer);
|
|
static bool isThrowable(int auxValue);
|
|
int getColor(int data);
|
|
virtual int getColor(shared_ptr<ItemInstance> item, int spriteLayer);
|
|
virtual bool hasMultipleSpriteLayers();
|
|
virtual bool hasInstantenousEffects(int itemAuxValue);
|
|
virtual wstring getHoverName(shared_ptr<ItemInstance> itemInstance);
|
|
virtual void appendHoverText(shared_ptr<ItemInstance> itemInstance, shared_ptr<Player> player, vector<HtmlString> *lines, bool advanced);
|
|
virtual bool isFoil(shared_ptr<ItemInstance> itemInstance);
|
|
|
|
virtual unsigned int getUseDescriptionId(shared_ptr<ItemInstance> instance);
|
|
|
|
//@Override
|
|
void registerIcons(IconRegister *iconRegister);
|
|
static Icon *getTexture(const wstring &name);
|
|
|
|
// 4J Stu - Based loosely on a function that gets added in java much later on (1.3)
|
|
static vector<pair<int, int> > *getUniquePotionValues();
|
|
|
|
virtual int getUseTooltipId(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level* level, int x, int y, int z, bool bUseItem) const;
|
|
private:
|
|
// 4J Stu - Added to support function above, different from Java implementation
|
|
static vector<pair<int, int> > s_uniquePotionValues;
|
|
};
|