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
143 lines
4.0 KiB
C++
143 lines
4.0 KiB
C++
#include "stdafx.h"
|
|
#include "net.minecraft.h"
|
|
#include "net.minecraft.world.phys.h"
|
|
#include "net.minecraft.world.damagesource.h"
|
|
#include "net.minecraft.world.level.tile.h"
|
|
#include "net.minecraft.world.item.h"
|
|
#include "net.minecraft.world.level.h"
|
|
#include "HangingEntityItem.h"
|
|
#include "HangingEntity.h"
|
|
#include "Painting.h"
|
|
#include "GenericStats.h"
|
|
#include "ItemFrame.h"
|
|
#include "SoundTypes.h"
|
|
|
|
|
|
HangingEntityItem::HangingEntityItem(int id, eINSTANCEOF eClassType) : Item(id)
|
|
{
|
|
this->eType=eClassType;
|
|
}
|
|
|
|
bool HangingEntityItem::useOn(shared_ptr<ItemInstance> instance, shared_ptr<Player> player, Level *level, int xt, int yt, int zt, int face, float clickX, float clickY, float clickZ, bool bTestOnly)
|
|
{
|
|
if (face == Facing::DOWN) return false;
|
|
if (face == Facing::UP) return false;
|
|
|
|
if(bTestOnly)
|
|
{
|
|
if (!player->mayUseItemAt(xt, yt, zt, face, instance)) return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
int dir = Direction::FACING_DIRECTION[face];
|
|
|
|
shared_ptr<HangingEntity> entity = createEntity(level, xt, yt, zt, dir, instance->getAuxValue() );
|
|
|
|
if (!player->mayUseItemAt(xt, yt, zt, face, instance)) return false;
|
|
|
|
if (entity != nullptr && entity->survives())
|
|
{
|
|
if (!level->isClientSide)
|
|
{
|
|
if(level->addEntity(entity)==TRUE)
|
|
{
|
|
if (eType==eTYPE_ITEM_FRAME)
|
|
{
|
|
entity->playSound(eSoundType_ENTITY_ITEMFRAME_PLACE, 1.0f, 1.0f);
|
|
}
|
|
|
|
// 4J-JEV: Hook for durango 'BlockPlaced' event.
|
|
if (eType==eTYPE_PAINTING) player->awardStat(GenericStats::blocksPlaced(Item::painting_Id), GenericStats::param_blocksPlaced(Item::painting_Id,instance->getAuxValue(),1));
|
|
else if (eType==eTYPE_ITEM_FRAME) player->awardStat(GenericStats::blocksPlaced(Item::item_frame_Id), GenericStats::param_blocksPlaced(Item::item_frame_Id,instance->getAuxValue(),1));
|
|
|
|
instance->count--;
|
|
}
|
|
else
|
|
{
|
|
player->displayClientMessage(IDS_MAX_HANGINGENTITIES );
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
instance->count--;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
shared_ptr<HangingEntity> HangingEntityItem::createEntity(Level *level, int x, int y, int z, int dir, int auxValue) // 4J added auxValue
|
|
{
|
|
if (eType == eTYPE_PAINTING)
|
|
{
|
|
shared_ptr<Painting> painting = std::make_shared<Painting>(level, x, y, z, dir);
|
|
painting->placedByPlayer = true;
|
|
painting->placedByTutorial = false;
|
|
|
|
#ifndef _CONTENT_PACKAGE
|
|
if (app.DebugArtToolsOn() && auxValue > 0)
|
|
{
|
|
painting->PaintingPostConstructor(dir, auxValue - 1);
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
painting->PaintingPostConstructor(dir);
|
|
}
|
|
|
|
return dynamic_pointer_cast<HangingEntity> (painting);
|
|
}
|
|
else if (eType == eTYPE_ITEM_FRAME)
|
|
{
|
|
shared_ptr<ItemFrame> itemFrame = std::make_shared<ItemFrame>(level, x, y, z, dir);
|
|
itemFrame->placedByPlayer = true;
|
|
itemFrame->placedByTutorial = false;
|
|
itemFrame->setDir(dir);
|
|
|
|
return dynamic_pointer_cast<HangingEntity> (itemFrame);
|
|
}
|
|
else
|
|
{
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
// 4J Adding overrides for art tools
|
|
void HangingEntityItem::appendHoverText(shared_ptr<ItemInstance> itemInstance, shared_ptr<Player> player, vector<HtmlString> *lines, bool advanced)
|
|
{
|
|
#ifndef _CONTENT_PACKAGE
|
|
if (eType == eTYPE_PAINTING && app.DebugArtToolsOn() && itemInstance->getAuxValue() > 0 )
|
|
{
|
|
int motive = itemInstance->getAuxValue() - 1;
|
|
|
|
wchar_t formatted[256];
|
|
ZeroMemory(formatted, 256 * sizeof(wchar_t));
|
|
swprintf(formatted, 256, L"** %ls %dx%d",Painting::Motive::values[motive]->name.c_str(),Painting::Motive::values[motive]->w/16,Painting::Motive::values[motive]->h/16);
|
|
|
|
wstring motiveName = formatted;
|
|
|
|
lines->push_back(HtmlString(motiveName.c_str(), eHTMLColor_c));
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
return Item::appendHoverText(itemInstance, player, lines, advanced);
|
|
}
|
|
}
|
|
|
|
int HangingEntityItem::getUseTooltipId(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level *level, int x, int y, int z, bool bUseItem) const
|
|
{
|
|
if (bUseItem && level != nullptr)
|
|
{
|
|
// Not4J Anaël: We need a wall or something solid to place it or the tooltip will be wrong
|
|
if (level->isSolidBlockingTile(x, y, z))
|
|
{
|
|
return IDS_TOOLTIPS_HANG;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|