// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> bool ResponsePolynomial::attachTo(PublicObject* parent) { if ( parent == NULL ) return false; // check all possible parents Inventory* inventory = Inventory::Cast(parent); if ( inventory != NULL ) return inventory->add(this); SEISCOMP_ERROR("ResponsePolynomial::attachTo(%s) -> wrong class type", parent->className()); return false; }
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; }
void BarrelBlock::attack(Player* player, const BlockPos& pos) { BarrelEntity* container = (BarrelEntity*)player->region.getBlockEntity(pos); if(container == nullptr || container->itemInstance == nullptr) return; int stackSize = ((container->itemCount > container->itemInstance->getMaxStackSize()) ? container->itemInstance->getMaxStackSize() : container->itemCount); Inventory* playerInventory = *(Inventory**) (((uintptr_t) player) + 0xD78); // TODO: Do the f*** header of Entity, Mob, Player. ItemInstance newItem(container->itemInstance->getId(), stackSize, container->itemInstance->getAuxValue()); if(!playerInventory->add(newItem)) { player->region.getLevel()->addEntity(std::unique_ptr<Entity>(new ItemEntity(player->region, Vec3(pos), newItem, 1))); } container->itemCount -= stackSize; if(container->itemCount <= 0) container->clear(); container->setChanged(); }