Skip to content

CraftWithMatchingMaterialsTask picks lower-tier item variant for recipe when higher-tier available #19

Description

@RiaDev1

Description

When crafting items that accept multiple material variants (e.g. beds from any wool color, tools from any pickaxe tier), the bot may craft using a lower-tier/wrong variant even when a better or more preferred variant is available.

Root Cause

In CraftWithMatchingMaterialsTask.onResourceTick():

int canCraftTotal = 0;
int majorityCraftCount = 0;
Item majorityCraftItem = null;
for (Item sameCheck : sameResourceTarget.getMatches()) {
    int count = getExpectedTotalCountOfSameItem(mod, sameCheck);
    int canCraft = (count / sameResourcePerRecipe) * recipe.outputCount();
    canCraftTotal += canCraft;
    if (canCraft > majorityCraftCount) {
        majorityCraftCount = canCraft;
        majorityCraftItem = sameCheck;
    }
}

The majorityCraftItem is chosen based on RAW COUNT, not tier priority. If the bot has 4 wooden planks and 3 oak planks, it will craft using wooden planks (4 > 3) even though oak has no functional difference. For items where tier matters (e.g. wooden pickaxe vs stone pickaxe), this doesn't apply since they're separate recipes.

However, for items like beds (any wool), the bot might use a rare wool color (e.g. cyan) when common colors (white) are also available. The real issue is when getExpectedTotalCountOfSameItem counts items in special slots (crafting grid input, furnace input) — items reserved for another purpose shouldn't be counted as available.

Impact

  • Wastes rare materials when common ones are available
  • Counts items in crafting/furnace input slots that are actually being used for another recipe, causing resource starvation

Suggested Fix

  1. When counting available materials, exclude items in crafting/furnace input slots that are currently in use
  2. Add a tiebreaker: when counts are equal, prefer items with higher tier/rarity

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions