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
255 lines
6.3 KiB
C++
255 lines
6.3 KiB
C++
#include "stdafx.h"
|
|
#include "CauldronTile.h"
|
|
#include "Facing.h"
|
|
#include "net.minecraft.world.level.h"
|
|
#include "net.minecraft.world.item.h"
|
|
#include "net.minecraft.world.entity.item.h"
|
|
#include "net.minecraft.world.entity.player.h"
|
|
#include "net.minecraft.world.h"
|
|
#include "../Minecraft.Client/ServerPlayer.h"
|
|
#include "net.minecraft.world.phys.h"
|
|
|
|
const wstring CauldronTile::TEXTURE_INSIDE = L"cauldron_inner";
|
|
const wstring CauldronTile::TEXTURE_BOTTOM = L"cauldron_bottom";
|
|
|
|
CauldronTile::CauldronTile(int id) : Tile(id, Material::metal, isSolidRender())
|
|
{
|
|
setLightBlock(0);
|
|
iconInner = nullptr;
|
|
iconTop = nullptr;
|
|
iconBottom = nullptr;
|
|
}
|
|
|
|
void CauldronTile::createBlockStateDefinition()
|
|
{
|
|
if (!m_blockStateDefinition)
|
|
m_blockStateDefinition = new BlockStateDefinition(this);
|
|
}
|
|
|
|
int CauldronTile::defaultBlockState()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int CauldronTile::convertBlockStateToLegacyData(BlockState *state)
|
|
{
|
|
return state ? (state->value & 0x3) : 0;
|
|
}
|
|
|
|
Tile::BlockState CauldronTile::getBlockState(int data)
|
|
{
|
|
return Tile::BlockState(data & 0x3);
|
|
}
|
|
|
|
Tile::BlockState CauldronTile::getBlockState(LevelSource *level, int x, int y, int z)
|
|
{
|
|
return Tile::BlockState(level->getData(x, y, z) & 0x3);
|
|
}
|
|
|
|
Icon *CauldronTile::getTexture(int face, int data)
|
|
{
|
|
if (face == Facing::UP)
|
|
{
|
|
return iconTop;
|
|
}
|
|
if (face == Facing::DOWN)
|
|
{
|
|
return iconBottom;
|
|
}
|
|
return icon;
|
|
}
|
|
|
|
void CauldronTile::entityInside(Level* level, int x, int y, int z, shared_ptr<Entity> entity)
|
|
{
|
|
if (level->isClientSide) return;
|
|
|
|
int data = level->getData(x, y, z);
|
|
int fillLevel = getFillLevel(data);
|
|
|
|
double waterSurfaceY = ((3 * fillLevel + 6) * 0.0625) + y;
|
|
|
|
if (level->isClientSide) return;
|
|
if (!entity->isOnFire()) return;
|
|
|
|
if (fillLevel <= 0) return;
|
|
|
|
if (entity->bb->y0 <= waterSurfaceY)
|
|
{
|
|
entity->clearFire();
|
|
level->setData(x, y, z, fillLevel - 1, Tile::UPDATE_CLIENTS);
|
|
}
|
|
}
|
|
|
|
void CauldronTile::registerIcons(IconRegister *iconRegister)
|
|
{
|
|
iconInner = iconRegister->registerIcon(L"cauldron_inner");
|
|
iconTop = iconRegister->registerIcon(L"cauldron_top");
|
|
iconBottom = iconRegister->registerIcon(L"cauldron_bottom");
|
|
icon = iconRegister->registerIcon(L"cauldron_side");
|
|
}
|
|
|
|
Icon *CauldronTile::getTexture(const wstring &name)
|
|
{
|
|
if (name.compare(TEXTURE_INSIDE) == 0) return Tile::cauldron->iconInner;
|
|
if (name.compare(TEXTURE_BOTTOM) == 0) return Tile::cauldron->iconBottom;
|
|
return nullptr;
|
|
}
|
|
|
|
void CauldronTile::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBList *boxes, shared_ptr<Entity> source)
|
|
{
|
|
setShape(0, 0, 0, 1, 5.0f / 16.0f, 1);
|
|
Tile::addAABBs(level, x, y, z, box, boxes, source);
|
|
float thickness = 2.0f / 16.0f;
|
|
setShape(0, 0, 0, thickness, 1, 1);
|
|
Tile::addAABBs(level, x, y, z, box, boxes, source);
|
|
setShape(0, 0, 0, 1, 1, thickness);
|
|
Tile::addAABBs(level, x, y, z, box, boxes, source);
|
|
setShape(1 - thickness, 0, 0, 1, 1, 1);
|
|
Tile::addAABBs(level, x, y, z, box, boxes, source);
|
|
setShape(0, 0, 1 - thickness, 1, 1, 1);
|
|
Tile::addAABBs(level, x, y, z, box, boxes, source);
|
|
|
|
updateDefaultShape();
|
|
}
|
|
|
|
void CauldronTile::updateDefaultShape()
|
|
{
|
|
setShape(0, 0, 0, 1, 1, 1);
|
|
}
|
|
|
|
bool CauldronTile::isSolidRender(bool isServerLevel)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
int CauldronTile::getInteractTooltipId(Level* level, int x, int y, int z, std::shared_ptr<Player> player, bool bUseItemOn) const
|
|
{
|
|
shared_ptr<ItemInstance> item = player->inventory->getSelected();
|
|
int currentData = level->getData(x, y, z);
|
|
return (item != nullptr && item->getItem()->id == Item::glass_bottle_Id && currentData > 0) ? IDS_TOOLTIPS_COLLECT : 0;
|
|
}
|
|
|
|
int CauldronTile::getRenderShape()
|
|
{
|
|
return SHAPE_CAULDRON;
|
|
}
|
|
|
|
bool CauldronTile::isCubeShaped()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool CauldronTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly/*=false*/) // 4J added soundOnly param
|
|
{
|
|
if(soundOnly) return false;
|
|
|
|
if (level->isClientSide)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
shared_ptr<ItemInstance> item = player->inventory->getSelected();
|
|
if (item == nullptr)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
int currentData = level->getData(x, y, z);
|
|
int fillLevel = getFillLevel(currentData);
|
|
|
|
if (item->id == Item::water_bucket_Id)
|
|
{
|
|
if (fillLevel < 3)
|
|
{
|
|
if (!player->abilities.instabuild)
|
|
{
|
|
player->inventory->setItem(player->inventory->selected, std::make_shared<ItemInstance>(Item::bucket));
|
|
}
|
|
|
|
level->setData(x, y, z, 3, Tile::UPDATE_CLIENTS);
|
|
level->updateNeighbourForOutputSignal(x, y, z, id);
|
|
}
|
|
return true;
|
|
}
|
|
else if (item->id == Item::glass_bottle_Id)
|
|
{
|
|
if (fillLevel > 0)
|
|
{
|
|
shared_ptr<ItemInstance> potion = std::make_shared<ItemInstance>(Item::potion, 1, 0);
|
|
if (!player->inventory->add(potion))
|
|
{
|
|
level->addEntity(std::make_shared<ItemEntity>(level, x + 0.5, y + 1.5, z + 0.5, potion));
|
|
}
|
|
// 4J Stu - Brought forward change to update inventory when filling bottles with water
|
|
else if (player->instanceof(eTYPE_SERVERPLAYER))
|
|
{
|
|
dynamic_pointer_cast<ServerPlayer>( player )->refreshContainer(player->inventoryMenu);
|
|
}
|
|
// 4J-PB - don't lose the water in creative mode
|
|
if (player->abilities.instabuild==false)
|
|
{
|
|
item->count--;
|
|
if (item->count <= 0)
|
|
{
|
|
player->inventory->setItem(player->inventory->selected, nullptr);
|
|
}
|
|
}
|
|
level->setData(x, y, z, fillLevel - 1, Tile::UPDATE_CLIENTS);
|
|
level->updateNeighbourForOutputSignal(x, y, z, id);
|
|
}
|
|
}
|
|
else if (fillLevel > 0)
|
|
{
|
|
ArmorItem *armor = dynamic_cast<ArmorItem *>(item->getItem());
|
|
if(armor && armor->getMaterial() == ArmorItem::ArmorMaterial::CLOTH)
|
|
{
|
|
armor->clearColor(item);
|
|
level->setData(x, y, z, fillLevel - 1, Tile::UPDATE_CLIENTS);
|
|
level->updateNeighbourForOutputSignal(x, y, z, id);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void CauldronTile::handleRain(Level *level, int x, int y, int z)
|
|
{
|
|
if (level->random->nextInt(20) != 1) return;
|
|
|
|
int data = level->getData(x, y, z);
|
|
|
|
if (data < 3)
|
|
{
|
|
level->setData(x, y, z, data + 1, Tile::UPDATE_CLIENTS);
|
|
}
|
|
}
|
|
|
|
int CauldronTile::getResource(int data, Random *random, int playerBonusLevel)
|
|
{
|
|
return Item::cauldron_Id;
|
|
}
|
|
|
|
int CauldronTile::cloneTileId(Level *level, int x, int y, int z)
|
|
{
|
|
return Item::cauldron_Id;
|
|
}
|
|
|
|
bool CauldronTile::hasAnalogOutputSignal()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
int CauldronTile::getAnalogOutputSignal(Level *level, int x, int y, int z, int dir)
|
|
{
|
|
int data = level->getData(x, y, z);
|
|
|
|
return getFillLevel(data);
|
|
}
|
|
|
|
int CauldronTile::getFillLevel(int data)
|
|
{
|
|
return data;
|
|
}
|