本文整理汇总了C++中Inventory::getSelectedSlot方法的典型用法代码示例。如果您正苦于以下问题:C++ Inventory::getSelectedSlot方法的具体用法?C++ Inventory::getSelectedSlot怎么用?C++ Inventory::getSelectedSlot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Inventory
的用法示例。
在下文中一共展示了Inventory::getSelectedSlot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: use
bool BarrelBlock::use(Player& player, const BlockPos& pos)
{
BarrelEntity* container = (BarrelEntity*)player.region.getBlockEntity(pos);
if(container == nullptr)
return false;
Inventory* playerInventory = *(Inventory**) (((uintptr_t) &player) + 0xD78); // TODO: Do the f*** header of Entity, Mob, Player.
ItemInstance* instance = player.getSelectedItem();
if(container->itemInstance == nullptr && instance != nullptr)
{
container->maxItems = instance->getMaxStackSize() * 64;
container->itemCount = instance->count;
container->itemInstance = ItemInstance::clone(instance);
playerInventory->clearSlot(playerInventory->getSelectedSlot());
}
else if((instance == nullptr || instance->getId() != container->itemInstance->getId()) && container->itemCount > 0)
{
ItemInstance temp(container->itemInstance->getId(), 1, container->itemInstance->getAuxValue());
if(!playerInventory->add(temp)) // This function clone the ItemInstance
{
//If the player does not have space, drop the item to the floor.
player.region.getLevel()->addEntity(std::unique_ptr<Entity>(new ItemEntity(player.region, Vec3(pos), temp, 1)));
}
container->itemCount -= 1;
}
else if(container->itemInstance->sameItemAndAux(instance) && (container->itemCount > 0) && (container->itemCount < container->maxItems))
{
if((container->itemCount + instance->count) > container->maxItems)
{
instance->count = (container->itemCount + instance->count) - container->maxItems;
container->itemCount = container->maxItems;
}
else
{
container->itemCount += instance->count;
playerInventory->clearSlot(playerInventory->getSelectedSlot());
}
}
container->setChanged();
if(container->itemCount <= 0)
container->clear();
if(instance == nullptr)
return false;
return true;
}