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
446 lines
11 KiB
C++
446 lines
11 KiB
C++
#include "stdafx.h"
|
|
#include "net.minecraft.world.level.h"
|
|
#include "net.minecraft.world.phys.h"
|
|
#include "DoorTile.h"
|
|
#include "LevelEvent.h"
|
|
#include "net.minecraft.world.item.h"
|
|
#include "net.minecraft.world.entity.player.h"
|
|
#include "net.minecraft.world.h"
|
|
#include "net.minecraft.h"
|
|
|
|
static std::map<wstring, int> doorItemMap = {
|
|
{ L"doorWood", Item::wooden_door_Id },
|
|
{ L"doorIron", Item::iron_door_Id },
|
|
{ L"doorSpruce", Item::spruce_door_Id },
|
|
{ L"doorBirch", Item::birch_door_Id },
|
|
{ L"doorJungle", Item::jungle_door_Id },
|
|
{ L"doorAcacia", Item::acacia_door_Id },
|
|
{ L"doorDark", Item::dark_oak_door_Id }
|
|
};
|
|
|
|
DoorTile::DoorTile(int id, Material *material, const wstring& doorType) : Tile(id, material,isSolidRender())
|
|
{
|
|
setLightBlock(0);
|
|
this->doorType = doorType;
|
|
|
|
float r = 0.5f;
|
|
float h = 1.0f;
|
|
Tile::setShape(0.5f - r, 0, 0.5f - r, 0.5f + r, h, 0.5f + r);
|
|
}
|
|
|
|
Icon *DoorTile::getTexture(int face, int data)
|
|
{
|
|
return iconBottom[TEXTURE_NORMAL];
|
|
}
|
|
|
|
Icon *DoorTile::getTexture(LevelSource *level, int x, int y, int z, int face)
|
|
{
|
|
if (face == Facing::UP || face == Facing::DOWN) return iconBottom[TEXTURE_NORMAL];
|
|
|
|
int compositeData = getCompositeData(level, x, y, z);
|
|
int dir = compositeData & C_DIR_MASK;
|
|
bool isOpen = (compositeData & C_OPEN_MASK) != 0;
|
|
bool flip = false;
|
|
bool upper = (compositeData & C_IS_UPPER_MASK) != 0;
|
|
|
|
if (isOpen)
|
|
{
|
|
if (dir == 0 && face == 2) flip = !flip;
|
|
else if (dir == 1 && face == 5) flip = !flip;
|
|
else if (dir == 2 && face == 3) flip = !flip;
|
|
else if (dir == 3 && face == 4) flip = !flip;
|
|
}
|
|
else
|
|
{
|
|
if (dir == 0 && face == 5) flip = !flip;
|
|
else if (dir == 1 && face == 3) flip = !flip;
|
|
else if (dir == 2 && face == 4) flip = !flip;
|
|
else if (dir == 3 && face == 2) flip = !flip;
|
|
if ((compositeData & C_RIGHT_HINGE_MASK) != 0) flip = !flip;
|
|
}
|
|
|
|
if (upper)
|
|
{
|
|
return iconTop[flip ? TEXTURE_FLIPPED : TEXTURE_NORMAL];
|
|
}
|
|
else
|
|
{
|
|
return iconBottom[flip ? TEXTURE_FLIPPED : TEXTURE_NORMAL];
|
|
}
|
|
}
|
|
|
|
void DoorTile::registerIcons(IconRegister *iconRegister)
|
|
{
|
|
iconTop[TEXTURE_NORMAL] = iconRegister->registerIcon(getIconName() + L"_upper");
|
|
iconBottom[TEXTURE_NORMAL] = iconRegister->registerIcon(getIconName() + L"_lower");
|
|
iconTop[TEXTURE_FLIPPED] = new FlippedIcon(iconTop[TEXTURE_NORMAL], true, false);
|
|
iconBottom[TEXTURE_FLIPPED] = new FlippedIcon(iconBottom[TEXTURE_NORMAL], true, false);
|
|
}
|
|
|
|
bool DoorTile::blocksLight()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool DoorTile::isSolidRender(bool isServerLevel)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool DoorTile::isCubeShaped()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
int DoorTile::getRenderShape()
|
|
{
|
|
return Tile::SHAPE_DOOR;
|
|
}
|
|
|
|
AABB *DoorTile::getTileAABB(Level *level, int x, int y, int z)
|
|
{
|
|
updateShape(level, x, y, z);
|
|
AABB *retval = Tile::getTileAABB(level, x, y, z);
|
|
return retval;
|
|
}
|
|
|
|
AABB *DoorTile::getAABB(Level *level, int x, int y, int z)
|
|
{
|
|
updateShape(level, x, y, z);
|
|
AABB *retval = Tile::getAABB(level, x, y, z);
|
|
return retval;
|
|
}
|
|
|
|
void DoorTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param
|
|
{
|
|
setShape(getCompositeData(level,x, y, z));
|
|
}
|
|
|
|
int DoorTile::getDir(LevelSource *level, int x, int y, int z)
|
|
{
|
|
return getCompositeData(level, x, y, z) & C_DIR_MASK;
|
|
}
|
|
|
|
bool DoorTile::isOpen(LevelSource *level, int x, int y, int z)
|
|
{
|
|
return (getCompositeData(level, x, y, z) & C_OPEN_MASK) != 0;
|
|
}
|
|
|
|
void DoorTile::setShape(int compositeData)
|
|
{
|
|
float r = 3 / 16.0f;
|
|
Tile::setShape(0, 0, 0, 1, 2, 1);
|
|
int dir = compositeData & C_DIR_MASK;
|
|
bool open = (compositeData & C_OPEN_MASK) != 0;
|
|
bool hasRightHinge = (compositeData & C_RIGHT_HINGE_MASK) != 0;
|
|
if (dir == 0)
|
|
{
|
|
if (open)
|
|
{
|
|
if (!hasRightHinge) setShape(0, 0, 0, 1, 1, r);
|
|
else setShape(0, 0, 1 - r, 1, 1, 1);
|
|
}
|
|
else setShape(0, 0, 0, r, 1, 1);
|
|
}
|
|
else if (dir == 1)
|
|
{
|
|
if (open)
|
|
{
|
|
if (!hasRightHinge) setShape(1 - r, 0, 0, 1, 1, 1);
|
|
else setShape(0, 0, 0, r, 1, 1);
|
|
}
|
|
else setShape(0, 0, 0, 1, 1, r);
|
|
}
|
|
else if (dir == 2)
|
|
{
|
|
if (open)
|
|
{
|
|
if (!hasRightHinge) setShape(0, 0, 1 - r, 1, 1, 1);
|
|
else setShape(0, 0, 0, 1, 1, r);
|
|
}
|
|
else setShape(1 - r, 0, 0, 1, 1, 1);
|
|
}
|
|
else if (dir == 3)
|
|
{
|
|
if (open)
|
|
{
|
|
if (!hasRightHinge) setShape(0, 0, 0, r, 1, 1);
|
|
else setShape(1 - r, 0, 0, 1, 1, 1);
|
|
}
|
|
else setShape(0, 0, 1 - r, 1, 1, 1);
|
|
}
|
|
}
|
|
|
|
void DoorTile::attack(Level *level, int x, int y, int z, shared_ptr<Player> player)
|
|
{
|
|
// Fix for #92957 - TU11: Content: Multiplayer: Wooden Doors splits in half and glitch in open / close motion while being mined.
|
|
// In lastest PC version this is commented out, so do that now to fix bug above
|
|
//use(level, x, y, z, player);
|
|
}
|
|
|
|
// 4J-PB - Adding a TestUse for tooltip display
|
|
bool DoorTile::TestUse()
|
|
{
|
|
return id == Tile::wooden_door_Id;
|
|
}
|
|
|
|
bool DoorTile::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)
|
|
{
|
|
// 4J - added - just do enough to play the sound
|
|
if (material != Material::metal)
|
|
{
|
|
level->levelEvent(player, LevelEvent::SOUND_OPEN_DOOR, x, y, z, 0);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
if (material == Material::metal) return true;
|
|
|
|
int compositeData = getCompositeData(level, x, y, z);
|
|
int lowerData = compositeData & C_LOWER_DATA_MASK;
|
|
lowerData ^= 4;
|
|
if ((compositeData & C_IS_UPPER_MASK) == 0)
|
|
{
|
|
level->setData(x, y, z, lowerData, Tile::UPDATE_CLIENTS);
|
|
level->setTilesDirty(x, y, z, x, y, z);
|
|
}
|
|
else
|
|
{
|
|
level->setData(x, y - 1, z, lowerData, Tile::UPDATE_CLIENTS);
|
|
level->setTilesDirty(x, y - 1, z, x, y, z);
|
|
}
|
|
|
|
level->levelEvent(player, LevelEvent::SOUND_OPEN_DOOR, x, y, z, 0);
|
|
return true;
|
|
}
|
|
|
|
void DoorTile::setOpen(Level *level, int x, int y, int z, bool shouldOpen)
|
|
{
|
|
int compositeData = getCompositeData(level, x, y, z);
|
|
bool isOpen = (compositeData & C_OPEN_MASK) != 0;
|
|
if (isOpen == shouldOpen) return;
|
|
|
|
int lowerData = compositeData & C_LOWER_DATA_MASK;
|
|
lowerData ^= 4;
|
|
if ((compositeData & C_IS_UPPER_MASK) == 0)
|
|
{
|
|
level->setData(x, y, z, lowerData, Tile::UPDATE_CLIENTS);
|
|
level->setTilesDirty(x, y, z, x, y, z);
|
|
}
|
|
else
|
|
{
|
|
level->setData(x, y - 1, z, lowerData, Tile::UPDATE_CLIENTS);
|
|
level->setTilesDirty(x, y - 1, z, x, y, z);
|
|
}
|
|
|
|
level->levelEvent(nullptr, LevelEvent::SOUND_OPEN_DOOR, x, y, z, 0);
|
|
}
|
|
|
|
void DoorTile::neighborChanged(Level *level, int x, int y, int z, int type)
|
|
{
|
|
int data = level->getData(x, y, z);
|
|
if ((data & UPPER_BIT) == 0)
|
|
{
|
|
bool spawn = false;
|
|
if (level->getTile(x, y + 1, z) != id)
|
|
{
|
|
level->removeTile(x, y, z);
|
|
spawn = true;
|
|
}
|
|
if (!level->isTopSolidBlocking(x, y - 1, z))
|
|
{
|
|
level->removeTile(x, y, z);
|
|
spawn = true;
|
|
if (level->getTile(x, y + 1, z) == id)
|
|
{
|
|
level->removeTile(x, y + 1, z);
|
|
}
|
|
}
|
|
if (spawn)
|
|
{
|
|
if (!level->isClientSide)
|
|
{
|
|
spawnResources(level, x, y, z, data, 0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool signal = level->hasNeighborSignal(x, y, z) || level->hasNeighborSignal(x, y + 1, z);
|
|
if ((signal || (type > 0 && Tile::tiles[type]->isSignalSource())) && type != id)
|
|
{
|
|
setOpen(level, x, y, z, signal);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (level->getTile(x, y - 1, z) != id)
|
|
{
|
|
level->removeTile(x, y, z);
|
|
}
|
|
if (type > 0 && type != id)
|
|
{
|
|
neighborChanged(level, x, y - 1, z, type);
|
|
}
|
|
}
|
|
}
|
|
|
|
int DoorTile::getResource(int data, Random *random, int playerBonusLevel)
|
|
{
|
|
if ((data & 8) != 0) return 0;
|
|
return doorItemMap[doorType];
|
|
}
|
|
|
|
HitResult *DoorTile::clip(Level *level, int xt, int yt, int zt, Vec3 *a, Vec3 *b)
|
|
{
|
|
updateShape(level, xt, yt, zt);
|
|
return Tile::clip(level, xt, yt, zt, a, b);
|
|
}
|
|
|
|
bool DoorTile::mayPlace(Level *level, int x, int y, int z)
|
|
{
|
|
if (y >= Level::maxBuildHeight - 1) return false;
|
|
|
|
return (level->isTopSolidBlocking(x, y - 1, z) && Tile::mayPlace(level, x, y, z) && Tile::mayPlace(level, x, y + 1, z));
|
|
}
|
|
|
|
bool DoorTile::isOpen(int data)
|
|
{
|
|
return (data & 4) != 0;
|
|
}
|
|
|
|
int DoorTile::getPistonPushReaction()
|
|
{
|
|
return Material::PUSH_DESTROY;
|
|
}
|
|
|
|
int DoorTile::getCompositeData(LevelSource *level, int x, int y, int z)
|
|
{
|
|
int data = level->getData(x, y, z);
|
|
bool isUpper = (data & UPPER_BIT) != 0;
|
|
int lowerData;
|
|
int upperData;
|
|
if (isUpper)
|
|
{
|
|
lowerData = level->getData(x, y - 1, z);
|
|
upperData = data;
|
|
}
|
|
else
|
|
{
|
|
lowerData = data;
|
|
upperData = level->getData(x, y + 1, z);
|
|
}
|
|
|
|
// bits: dir, dir, open/closed, isUpper, isRightHinge
|
|
bool isRightHinge = (upperData & 1) != 0;
|
|
return (lowerData & C_LOWER_DATA_MASK) | (isUpper ? 8 : 0) | (isRightHinge ? 16 : 0);
|
|
}
|
|
|
|
int DoorTile::cloneTileId(Level *level, int x, int y, int z)
|
|
{
|
|
return doorItemMap[doorType];
|
|
}
|
|
|
|
void DoorTile::playerWillDestroy(Level *level, int x, int y, int z, int data, shared_ptr<Player> player)
|
|
{
|
|
if (player->abilities.instabuild)
|
|
{
|
|
if ((data & UPPER_BIT) != 0)
|
|
{
|
|
if (level->getTile(x, y - 1, z) == id)
|
|
{
|
|
level->removeTile(x, y - 1, z);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void DoorTile::createBlockStateDefinition()
|
|
{
|
|
if (!m_blockStateDefinition)
|
|
m_blockStateDefinition = new BlockStateDefinition(this);
|
|
}
|
|
|
|
int DoorTile::defaultBlockState()
|
|
{
|
|
return 0; // closed
|
|
}
|
|
|
|
Tile::BlockState DoorTile::getBlockState(LevelSource *level, int x, int y, int z)
|
|
{
|
|
int composite = getCompositeData(level, x, y, z);
|
|
return Tile::BlockState(composite);
|
|
}
|
|
|
|
int DoorTile::convertBlockStateToLegacyData(BlockState *state)
|
|
{
|
|
if (!state) return 0;
|
|
int composite = state->value;
|
|
|
|
if (composite & C_IS_UPPER_MASK)
|
|
{
|
|
int base = (composite & C_RIGHT_HINGE_MASK) ? 9 : 8;
|
|
if (composite & C_OPEN_MASK) base |= 2;
|
|
return base;
|
|
}
|
|
else
|
|
{
|
|
int base = composite & C_DIR_MASK;
|
|
if (composite & C_OPEN_MASK) base |= 4;
|
|
return base;
|
|
}
|
|
}
|
|
|
|
Tile::BlockState DoorTile::getBlockState(int data)
|
|
{
|
|
int composite = 0;
|
|
if ((data & UPPER_BIT) == 0) {
|
|
composite = data & C_LOWER_DATA_MASK;
|
|
} else {
|
|
composite = C_IS_UPPER_MASK;
|
|
if ((data & 1) != 0) composite |= C_RIGHT_HINGE_MASK;
|
|
}
|
|
return Tile::BlockState(composite);
|
|
}
|
|
|
|
void DoorTile::fillVirtualBlockStateProperties(Tile::BlockState *state, LevelSource *level, const BlockPos &pos)
|
|
{
|
|
if (!state) return;
|
|
int composite = getCompositeData(level, pos.getX(), pos.getY(), pos.getZ());
|
|
state->value = composite;
|
|
}
|
|
|
|
bool DoorTile::use(Level *level, const BlockPos &pos, Tile::BlockState *state, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly)
|
|
{
|
|
if (soundOnly)
|
|
{
|
|
if (material != Material::metal)
|
|
level->levelEvent(player, LevelEvent::SOUND_OPEN_DOOR, pos.getX(), pos.getY(), pos.getZ(), 0);
|
|
return false;
|
|
}
|
|
|
|
if (material == Material::metal) return true;
|
|
|
|
int composite = state ? state->value : getCompositeData(level, pos.getX(), pos.getY(), pos.getZ());
|
|
int lowerData = composite & C_LOWER_DATA_MASK;
|
|
lowerData ^= 4;
|
|
|
|
if ((composite & C_IS_UPPER_MASK) == 0) {
|
|
level->setData(pos.getX(), pos.getY(), pos.getZ(), lowerData, Tile::UPDATE_CLIENTS);
|
|
level->setTilesDirty(pos.getX(), pos.getY(), pos.getZ(), pos.getX(), pos.getY(), pos.getZ());
|
|
} else {
|
|
level->setData(pos.getX(), pos.getY() - 1, pos.getZ(), lowerData, Tile::UPDATE_CLIENTS);
|
|
level->setTilesDirty(pos.getX(), pos.getY() - 1, pos.getZ(), pos.getX(), pos.getY(), pos.getZ());
|
|
}
|
|
|
|
level->levelEvent(player, LevelEvent::SOUND_OPEN_DOOR, pos.getX(), pos.getY(), pos.getZ(), 0);
|
|
return true;
|
|
}
|
|
|
|
int DoorTile::getInteractTooltipId(Level* level, int x, int y, int z, std::shared_ptr<Player> player, bool bUseItemOn) const
|
|
{
|
|
return IDS_TOOLTIPS_USE;
|
|
}
|