MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / tickCrafting

Method tickCrafting

source/game/objects/StarContainerObject.cpp:456–496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

454}
455
456void ContainerObject::tickCrafting(float dt) {
457 if (!m_crafting.get())
458 return;
459
460 auto inputItems = m_items->items();
461 inputItems.removeLast();
462 auto recipe = recipeForMaterials(inputItems);
463 bool craftingFail = false;
464 if (recipe.isNull() || m_goalRecipe != recipe)
465 craftingFail = true;
466 ItemPtr targetItem = m_items->at(m_items->size() - 1);
467 if (targetItem) {
468 if (!targetItem->matches(m_goalRecipe.output, true))
469 craftingFail = true;
470 else if (targetItem->count() + m_goalRecipe.output.count() > targetItem->maxStack())
471 craftingFail = true;
472 }
473 if (craftingFail) {
474 m_crafting.set(false);
475 m_craftingProgress.set(0);
476 m_goalRecipe = ItemRecipe();
477 return;
478 }
479 if (m_goalRecipe.duration > 0)
480 m_craftingProgress.set(m_craftingProgress.get() + dt / m_goalRecipe.duration);
481 else
482 m_craftingProgress.set(1.0f);
483 if (m_craftingProgress.get() >= 1.0f) {
484 m_craftingProgress.set(0);
485 for (auto const& input : m_goalRecipe.inputs) {
486 bool consumed = m_items->consumeItems(input);
487 _unused(consumed);
488 starAssert(consumed);
489 }
490 ItemPtr overflow =
491 m_items->putItems(m_items->size() - 1, Root::singleton().itemDatabase()->item(m_goalRecipe.output));
492 if (overflow)
493 world()->addEntity(ItemDrop::createRandomizedDrop(overflow, position()));
494 itemsUpdated();
495 }
496}
497
498ItemPtr ContainerObject::doAddItems(ItemPtr const& items) {
499 itemsUpdated();

Callers

nothing calls this directly

Calls 15

ItemRecipeClass · 0.85
singletonClass · 0.85
itemsMethod · 0.80
itemDatabaseMethod · 0.80
getMethod · 0.45
removeLastMethod · 0.45
isNullMethod · 0.45
atMethod · 0.45
sizeMethod · 0.45
matchesMethod · 0.45
countMethod · 0.45
maxStackMethod · 0.45

Tested by

no test coverage detected