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
77 lines
2.1 KiB
C++
77 lines
2.1 KiB
C++
#include "stdafx.h"
|
|
#include "net.minecraft.network.packet.h"
|
|
#include "net.minecraft.world.entity.h"
|
|
#include "net.minecraft.world.entity.player.h"
|
|
#include "net.minecraft.world.level.h"
|
|
#include "net.minecraft.world.level.chunk.h"
|
|
#include "net.minecraft.world.level.material.h"
|
|
#include "net.minecraft.world.level.saveddata.h"
|
|
#include "net.minecraft.world.level.tile.h"
|
|
#include "net.minecraft.world.entity.projectile.h"
|
|
#include "net.minecraft.world.h"
|
|
#include "ItemInstance.h"
|
|
#include "FishingRodItem.h"
|
|
#include "SoundTypes.h"
|
|
|
|
FishingRodItem::FishingRodItem(int id) : Item(id)
|
|
{
|
|
setMaxDamage(64);
|
|
setMaxStackSize(1);
|
|
emptyIcon = nullptr;
|
|
}
|
|
|
|
bool FishingRodItem::isHandEquipped()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool FishingRodItem::isMirroredArt()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
// This makes it so that fishing rods can be enchanted at an enchanting table.
|
|
int FishingRodItem::getEnchantmentValue()
|
|
{
|
|
return 1; // Enchantibility of a fishing rod. // Source: https://minecraft.wiki/w/Fishing_Rod
|
|
}
|
|
|
|
shared_ptr<ItemInstance> FishingRodItem::use(shared_ptr<ItemInstance> instance, Level *level, shared_ptr<Player> player)
|
|
{
|
|
if (player->fishing != nullptr)
|
|
{
|
|
int dmg = player->fishing->retrieve();
|
|
instance->hurtAndBreak(dmg, player);
|
|
player->swing();
|
|
}
|
|
else
|
|
{
|
|
level->playEntitySound(player, eSoundType_RANDOM_BOW, 0.5f, 0.4f / (random->nextFloat() * 0.4f + 0.8f));
|
|
if (!level->isClientSide)
|
|
{
|
|
// 4J Stu - Move the player->fishing out of the ctor as we cannot reference 'this'
|
|
shared_ptr<FishingHook> hook = std::make_shared<FishingHook>(level, player);
|
|
player->fishing = hook;
|
|
level->addEntity( shared_ptr<FishingHook>( hook ) );
|
|
}
|
|
player->swing();
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
void FishingRodItem::registerIcons(IconRegister *iconRegister)
|
|
{
|
|
icon = iconRegister->registerIcon(getIconName() + L"_uncast");
|
|
emptyIcon = iconRegister->registerIcon(getIconName() + L"_cast");
|
|
}
|
|
|
|
Icon *FishingRodItem::getEmptyIcon()
|
|
{
|
|
return emptyIcon;
|
|
}
|
|
|
|
int FishingRodItem::getUseTooltipId(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level* level, int x, int y, int z, bool bUseItem) const
|
|
{
|
|
return IDS_TOOLTIPS_USE;
|
|
}
|