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
260 lines
6.4 KiB
C++
260 lines
6.4 KiB
C++
#include "stdafx.h"
|
|
#include "JavaMath.h"
|
|
#include "net.minecraft.world.entity.player.h"
|
|
#include "net.minecraft.world.level.h"
|
|
#include "net.minecraft.world.level.dimension.h"
|
|
#include "net.minecraft.world.level.material.h"
|
|
#include "net.minecraft.world.level.tile.h"
|
|
#include "net.minecraft.world.phys.h"
|
|
#include "net.minecraft.world.level.tile.h"
|
|
#include "net.minecraft.world.entity.animal.h"
|
|
#include "net.minecraft.stats.h"
|
|
#include "Material.h"
|
|
#include "ItemInstance.h"
|
|
#include "BucketItem.h"
|
|
#include "../Minecraft.Client/LocalPlayer.h"
|
|
#include "../Minecraft.Client/ServerPlayer.h"
|
|
#include "../Minecraft.Client/PlayerConnection.h"
|
|
#include "../Minecraft.World/ChatPacket.h"
|
|
#include "SoundTypes.h"
|
|
|
|
BucketItem::BucketItem(int id, int content) : Item( id )
|
|
{
|
|
maxStackSize = 1;
|
|
this->content = content;
|
|
}
|
|
|
|
bool BucketItem::TestUse(shared_ptr<ItemInstance> itemInstance, Level *level, shared_ptr<Player> player)
|
|
{
|
|
bool pickLiquid = content == 0;
|
|
HitResult *hr = getPlayerPOVHitResult(level, player, pickLiquid);
|
|
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, content))
|
|
{
|
|
delete hr;
|
|
return false;
|
|
}
|
|
|
|
if (content == 0)
|
|
{
|
|
if (!player->mayUseItemAt(xt, yt, zt, hr->f, itemInstance)) return false;
|
|
if (level->getMaterial(xt, yt, zt) == Material::water && level->getData(xt, yt, zt) == 0)
|
|
{
|
|
delete hr;
|
|
return true;
|
|
}
|
|
if (level->getMaterial(xt, yt, zt) == Material::lava && level->getData(xt, yt, zt) == 0)
|
|
{
|
|
delete hr;
|
|
return true;
|
|
}
|
|
}
|
|
else if (content < 0)
|
|
{
|
|
delete hr;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
if (hr->f == 0) yt--;
|
|
if (hr->f == 1) yt++;
|
|
if (hr->f == 2) zt--;
|
|
if (hr->f == 3) zt++;
|
|
if (hr->f == 4) xt--;
|
|
if (hr->f == 5) xt++;
|
|
|
|
if (!player->mayUseItemAt(xt, yt, zt, hr->f, itemInstance)) return false;
|
|
|
|
if (level->isEmptyTile(xt, yt, zt) || !level->getMaterial(xt, yt, zt)->isSolid())
|
|
{
|
|
delete hr;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (content == 0)
|
|
{
|
|
if (hr->entity->GetType() == eTYPE_COW)
|
|
{
|
|
delete hr;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
delete hr;
|
|
|
|
return false;
|
|
}
|
|
|
|
shared_ptr<ItemInstance> BucketItem::use(shared_ptr<ItemInstance> itemInstance, Level *level, shared_ptr<Player> player)
|
|
{
|
|
float a = 1;
|
|
|
|
double x = player->xo + (player->x - player->xo) * a;
|
|
double y = player->yo + (player->y - player->yo) * a + 1.62 - player->heightOffset;
|
|
double z = player->zo + (player->z - player->zo) * a;
|
|
|
|
bool pickLiquid = content == 0;
|
|
HitResult *hr = getPlayerPOVHitResult(level, player, pickLiquid);
|
|
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,content))
|
|
{
|
|
app.DebugPrintf("!!!!!!!!!!! Can't place that here\n");
|
|
shared_ptr<ServerPlayer> servPlayer = dynamic_pointer_cast<ServerPlayer>(player);
|
|
if( servPlayer != nullptr )
|
|
{
|
|
app.DebugPrintf("Sending ChatPacket::e_ChatCannotPlaceLava to player\n");
|
|
servPlayer->connection->send(std::make_shared<ChatPacket>(L"", ChatPacket::e_ChatCannotPlaceLava));
|
|
}
|
|
|
|
delete hr;
|
|
return itemInstance;
|
|
}
|
|
|
|
if (content == 0)
|
|
{
|
|
if (!player->mayUseItemAt(xt, yt, zt, hr->f, itemInstance)) return itemInstance;
|
|
if (level->getMaterial(xt, yt, zt) == Material::water && level->getData(xt, yt, zt) == 0)
|
|
{
|
|
level->removeTile(xt, yt, zt);
|
|
delete hr;
|
|
if (player->abilities.instabuild)
|
|
{
|
|
return itemInstance;
|
|
}
|
|
|
|
if (--itemInstance->count <= 0)
|
|
{
|
|
return std::make_shared<ItemInstance>(Item::water_bucket);
|
|
}
|
|
else
|
|
{
|
|
if (!player->inventory->add(std::make_shared<ItemInstance>(Item::water_bucket)))
|
|
{
|
|
player->drop(std::make_shared<ItemInstance>(Item::water_bucket_Id, 1, 0));
|
|
}
|
|
return itemInstance;
|
|
}
|
|
}
|
|
if (level->getMaterial(xt, yt, zt) == Material::lava && level->getData(xt, yt, zt) == 0)
|
|
{
|
|
if( level->dimension->id == -1 )
|
|
player->awardStat(
|
|
GenericStats::netherLavaCollected(),
|
|
GenericStats::param_noArgs()
|
|
);
|
|
|
|
level->removeTile(xt, yt, zt);
|
|
delete hr;
|
|
if (player->abilities.instabuild)
|
|
{
|
|
return itemInstance;
|
|
}
|
|
if (--itemInstance->count <= 0)
|
|
{
|
|
return std::make_shared<ItemInstance>(Item::lava_bucket);
|
|
}
|
|
else
|
|
{
|
|
if (!player->inventory->add(std::make_shared<ItemInstance>(Item::lava_bucket)))
|
|
{
|
|
player->drop(std::make_shared<ItemInstance>(Item::lava_bucket_Id, 1, 0));
|
|
}
|
|
return itemInstance;
|
|
}
|
|
}
|
|
}
|
|
else if (content < 0)
|
|
{
|
|
delete hr;
|
|
return std::make_shared<ItemInstance>(Item::bucket);
|
|
}
|
|
else
|
|
{
|
|
if (hr->f == 0) yt--;
|
|
if (hr->f == 1) yt++;
|
|
if (hr->f == 2) zt--;
|
|
if (hr->f == 3) zt++;
|
|
if (hr->f == 4) xt--;
|
|
if (hr->f == 5) xt++;
|
|
|
|
if (!player->mayUseItemAt(xt, yt, zt, hr->f, itemInstance)) return itemInstance;
|
|
|
|
|
|
if (emptyBucket(level, xt, yt, zt) && !player->abilities.instabuild)
|
|
{
|
|
return std::make_shared<ItemInstance>(Item::bucket);
|
|
}
|
|
|
|
}
|
|
}
|
|
delete hr;
|
|
return itemInstance;
|
|
}
|
|
|
|
bool BucketItem::emptyBucket(Level *level, int xt, int yt, int zt)
|
|
{
|
|
if (content <= 0) return false;
|
|
|
|
Material *material = level->getMaterial(xt, yt, zt);
|
|
bool nonSolid = !material->isSolid();
|
|
|
|
if (level->isEmptyTile(xt, yt, zt) || nonSolid)
|
|
{
|
|
if (level->dimension->ultraWarm && content == Tile::flowing_water_Id)
|
|
{
|
|
level->playSound(xt + 0.5f, yt + 0.5f, zt + 0.5f, eSoundType_RANDOM_FIZZ, 0.5f, 2.6f + (level->random->nextFloat() - level->random->nextFloat()) * 0.8f);
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
level->addParticle(eParticleType_largesmoke, xt + Math::random(), yt + Math::random(), zt + Math::random(), 0, 0, 0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!level->isClientSide && nonSolid && !material->isLiquid())
|
|
{
|
|
level->destroyTile(xt, yt, zt, true);
|
|
}
|
|
level->setTileAndData(xt, yt, zt, content, 0, Tile::UPDATE_ALL);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
int BucketItem::getUseTooltipId(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level* level, int x, int y, int z, bool bUseItem) const
|
|
{
|
|
if (this->content == 0) // Not4J Anaël: If the bucket is empty, set the tooltip to collect
|
|
{
|
|
if(bUseItem)
|
|
{
|
|
return IDS_TOOLTIPS_COLLECT;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return IDS_TOOLTIPS_EMPTY; // Not4J Anaël: The other way arround but with a full bucket this time
|
|
}
|
|
|
|
return 0;
|
|
}
|