game loop: Refactor the tooltips loop
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
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "net.minecraft.world.level.h"
|
||||
#include "net.minecraft.h"
|
||||
#include "net.minecraft.world.h"
|
||||
#include "net.minecraft.world.entity.player.h"
|
||||
#include "JukeboxTile.h"
|
||||
#include "LevelEvent.h"
|
||||
|
||||
@@ -190,4 +191,32 @@ int JukeboxTile::getAnalogOutputSignal(Level *level, int x, int y, int z, int di
|
||||
{
|
||||
shared_ptr<ItemInstance> record = dynamic_pointer_cast<JukeboxTile::Entity>( level->getTileEntity(x, y, z))->getRecord();
|
||||
return record == nullptr ? Redstone::SIGNAL_NONE : record->id + 1 - Item::record_13_Id;
|
||||
}
|
||||
}
|
||||
|
||||
int JukeboxTile::getInteractTooltipId(Level* level, int x, int y, int z, std::shared_ptr<Player> player, bool bUseItemOn) const
|
||||
{
|
||||
shared_ptr<ItemInstance> item = player->inventory->IsHeldItem() ? player->inventory->getSelected() : nullptr;
|
||||
|
||||
// Not4J Anaël: We need to check if the player holds a disk before displaying the tooltip
|
||||
if (item != nullptr && item->getItem() != nullptr)
|
||||
{
|
||||
int itemId = item->getItem()->id;
|
||||
if (itemId >= Item::record_13_Id && itemId <= Item::record_wait_Id)
|
||||
{
|
||||
// And if the jukebox already has a disk inside
|
||||
auto tileEntity = dynamic_pointer_cast<JukeboxTile::Entity>(level->getTileEntity(x, y, z));
|
||||
if (tileEntity != nullptr && tileEntity->getRecord() == nullptr)
|
||||
{
|
||||
return IDS_TOOLTIPS_PLAY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the player doesn't, we can display the eject tooltip
|
||||
if (Tile::jukebox->TestUse(level, x, y, z, player))
|
||||
{
|
||||
return IDS_TOOLTIPS_EJECT;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user