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
97 lines
2.2 KiB
C++
97 lines
2.2 KiB
C++
#include "stdafx.h"
|
|
#include "net.minecraft.world.phys.h"
|
|
#include "net.minecraft.world.level.h"
|
|
#include "net.minecraft.world.level.tile.h"
|
|
#include "net.minecraft.world.level.material.h"
|
|
#include "net.minecraft.world.entity.player.h"
|
|
#include "WaterLilyTileItem.h"
|
|
|
|
WaterLilyTileItem::WaterLilyTileItem(int id) : ColoredTileItem(id, false)
|
|
{
|
|
}
|
|
|
|
bool WaterLilyTileItem::TestUse(shared_ptr<ItemInstance> itemInstance, Level *level, shared_ptr<Player> player)
|
|
{
|
|
HitResult *hr = getPlayerPOVHitResult(level, player, true);
|
|
if (hr == nullptr) return false;
|
|
|
|
if (hr->type == HitResult::TILE)
|
|
{
|
|
int xt = hr->x;
|
|
int yt = hr->y;
|
|
int zt = hr->z;
|
|
if (!level->mayInteract(player, xt, yt, zt, 0))
|
|
{
|
|
delete hr;
|
|
return false;
|
|
}
|
|
if (!player->mayUseItemAt(xt, yt, zt, hr->f, itemInstance))
|
|
{
|
|
delete hr;
|
|
return false;
|
|
}
|
|
|
|
delete hr;
|
|
if (level->getMaterial(xt, yt, zt) == Material::water && level->getData(xt, yt, zt) == 0 && level->isEmptyTile(xt, yt + 1, zt))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
delete hr;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
shared_ptr<ItemInstance> WaterLilyTileItem::use(shared_ptr<ItemInstance> itemInstance, Level *level, shared_ptr<Player> player)
|
|
{
|
|
HitResult *hr = getPlayerPOVHitResult(level, player, true);
|
|
if (hr == nullptr) return itemInstance;
|
|
|
|
if (hr->type == HitResult::TILE)
|
|
{
|
|
int xt = hr->x;
|
|
int yt = hr->y;
|
|
int zt = hr->z;
|
|
if (!level->mayInteract(player, xt, yt, zt, 0))
|
|
{
|
|
delete hr;
|
|
return itemInstance;
|
|
}
|
|
if (!player->mayUseItemAt(xt, yt, zt, hr->f, itemInstance))
|
|
{
|
|
delete hr;
|
|
return itemInstance;
|
|
}
|
|
|
|
delete hr;
|
|
if (level->getMaterial(xt, yt, zt) == Material::water && level->getData(xt, yt, zt) == 0 && level->isEmptyTile(xt, yt + 1, zt))
|
|
{
|
|
level->setTileAndUpdate(xt, yt + 1, zt, Tile::waterLily->id);
|
|
if (!player->abilities.instabuild)
|
|
{
|
|
itemInstance->count--;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
delete hr;
|
|
}
|
|
return itemInstance;
|
|
}
|
|
|
|
int WaterLilyTileItem::getColor(int data, int spriteLayer)
|
|
{
|
|
return Tile::waterLily->getColor(data);
|
|
}
|
|
|
|
int WaterLilyTileItem::getUseTooltipId(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level* level, int x, int y, int z, bool bUseItem) const
|
|
{
|
|
if (bUseItem)
|
|
return IDS_TOOLTIPS_PLACE;
|
|
|
|
return 0;
|
|
}
|