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
125 lines
3.5 KiB
C++
125 lines
3.5 KiB
C++
#include "stdafx.h"
|
|
#include "net.minecraft.world.level.h"
|
|
#include "net.minecraft.world.entity.player.h"
|
|
#include "net.minecraft.world.entity.projectile.h"
|
|
#include "net.minecraft.world.entity.item.h"
|
|
#include "net.minecraft.world.item.enchantment.h"
|
|
#include "net.minecraft.world.h"
|
|
#include "BowItem.h"
|
|
#include "SoundTypes.h"
|
|
|
|
const wstring BowItem::TEXTURE_PULL[] = {L"bow_pull_0", L"bow_pull_1", L"bow_pull_2"};
|
|
|
|
BowItem::BowItem(int id) : Item( id )
|
|
{
|
|
maxStackSize = 1;
|
|
setMaxDamage(384);
|
|
|
|
icons = nullptr;
|
|
}
|
|
|
|
void BowItem::releaseUsing(shared_ptr<ItemInstance> itemInstance, Level *level, shared_ptr<Player> player, int durationLeft)
|
|
{
|
|
bool infiniteArrows = player->abilities.instabuild || EnchantmentHelper::getEnchantmentLevel(Enchantment::arrowInfinite->id, itemInstance) > 0;
|
|
|
|
if (infiniteArrows || player->inventory->hasResource(Item::arrow_Id))
|
|
{
|
|
int timeHeld = getUseDuration(itemInstance) - durationLeft;
|
|
float pow = timeHeld / static_cast<float>(MAX_DRAW_DURATION);
|
|
pow = ((pow * pow) + pow * 2) / 3;
|
|
if (pow < 0.1) return;
|
|
if (pow > 1) pow = 1;
|
|
|
|
shared_ptr<Arrow> arrow = std::make_shared<Arrow>(level, player, pow * 2.0f);
|
|
if (pow == 1) arrow->setCritArrow(true);
|
|
int damageBonus = EnchantmentHelper::getEnchantmentLevel(Enchantment::arrowBonus->id, itemInstance);
|
|
if (damageBonus > 0)
|
|
{
|
|
arrow->setBaseDamage(arrow->getBaseDamage() + static_cast<double>(damageBonus) * .5 + .5);
|
|
}
|
|
int knockbackBonus = EnchantmentHelper::getEnchantmentLevel(Enchantment::arrowKnockback->id, itemInstance);
|
|
if (knockbackBonus > 0)
|
|
{
|
|
arrow->setKnockback(knockbackBonus);
|
|
}
|
|
if (EnchantmentHelper::getEnchantmentLevel(Enchantment::arrowFire->id, itemInstance) > 0)
|
|
{
|
|
arrow->setOnFire(100);
|
|
}
|
|
itemInstance->hurtAndBreak(1, player);
|
|
|
|
level->playEntitySound(player, eSoundType_RANDOM_BOW, 1.0f, 1 / (random->nextFloat() * 0.4f + 1.2f) + pow * 0.5f);
|
|
|
|
if (infiniteArrows)
|
|
{
|
|
arrow->pickup = Arrow::PICKUP_CREATIVE_ONLY;
|
|
}
|
|
else
|
|
{
|
|
player->inventory->removeResource(Item::arrow_Id);
|
|
}
|
|
if (!level->isClientSide) level->addEntity(arrow);
|
|
}
|
|
}
|
|
|
|
shared_ptr<ItemInstance> BowItem::useTimeDepleted(shared_ptr<ItemInstance> instance, Level *level, shared_ptr<Player> player)
|
|
{
|
|
return instance;
|
|
}
|
|
|
|
int BowItem::getUseDuration(shared_ptr<ItemInstance> itemInstance)
|
|
{
|
|
return 20 * 60 * 60;
|
|
}
|
|
|
|
UseAnim BowItem::getUseAnimation(shared_ptr<ItemInstance> itemInstance)
|
|
{
|
|
return UseAnim_bow;
|
|
}
|
|
|
|
shared_ptr<ItemInstance> BowItem::use(shared_ptr<ItemInstance> instance, Level *level, shared_ptr<Player> player)
|
|
{
|
|
if (player->abilities.instabuild || player->inventory->hasResource(Item::arrow_Id))
|
|
{
|
|
player->startUsingItem(instance, getUseDuration(instance));
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
int BowItem::getEnchantmentValue()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
void BowItem::registerIcons(IconRegister *iconRegister)
|
|
{
|
|
Item::registerIcons(iconRegister);
|
|
|
|
icons = new Icon *[BOW_ICONS_COUNT];
|
|
|
|
for (int i = 0; i < BOW_ICONS_COUNT; i++)
|
|
{
|
|
icons[i] = iconRegister->registerIcon(TEXTURE_PULL[i]);
|
|
}
|
|
}
|
|
|
|
Icon *BowItem::getDrawnIcon(int amount)
|
|
{
|
|
return icons[amount];
|
|
}
|
|
|
|
int BowItem::getUseTooltipId(std::shared_ptr<ItemInstance> itemInstance, std::shared_ptr<Player> player, Level* level, int x, int y, int z, bool bUseItem) const
|
|
{
|
|
if (player->abilities.instabuild || player->inventory->hasResource(Item::arrow_Id))
|
|
{
|
|
if (player->isUsingItem())
|
|
{
|
|
return IDS_TOOLTIPS_RELEASE_BOW;
|
|
}
|
|
else
|
|
{
|
|
return IDS_TOOLTIPS_DRAW_BOW;
|
|
}
|
|
}
|
|
}
|