Crafting Stations Cycle Between Tools
bruberu opened this issue ยท 2 comments
Describe the bug
When using multiple tools of the same type within the crafting station, instead of wearing down the first available tool until it is broken, it cycles through all available tools, damaging them equally over time.
Versions
GTCEu: Beta
Steps To Reproduce
Place down a crafting station
Put two saws in it
Saw several glass pieces with it into glass panes
You should now notice that both saws are getting damaged by the craft, alternating between which gets damaged.
Expected behavior
Only one tool should be focused on by the crafting station, preferably the first one in the tool inventory, or the one with the lowest durability.
NOTE: This bug is extraordinarily difficult to fix. Do not fix unless you have nothing else to do (with your life).
On:
public boolean getIngredientEquivalent(int slot) {
ItemStack currentStack = inventory.getStackInSlot(slot);
if (currentStack.isEmpty()) {
return true; //stack is empty, nothing to return
}
ItemStackKey currentStackKey = new ItemStackKey(currentStack.copy());
if (simulateExtractItem(currentStackKey)) {
//we can extract ingredient equal to the one in the crafting grid,
//so just return it without searching equivalent
return true;
}
//iterate stored items to find equivalent
for (ItemStackKey itemStackKey : itemSourceList.getStoredItems()) {
ItemStack itemStack = itemStackKey.getItemStack();
//update item in slot, and check that recipe matches and output item is equal to the expected one
inventory.setInventorySlotContents(slot, itemStack);
if (recipe.matches(inventory, itemSourceList.getWorld()) &&
ItemStack.areItemStacksEqual(expectedOutput, recipe.getCraftingResult(inventory))) {
//ingredient matched, attempt to extract it and return if successful
if (simulateExtractItem(itemStackKey)) {
return true;
}
}
inventory.setInventorySlotContents(slot, currentStack);
}
//nothing matched, so return null
return false;
}
We look for an exact match of the item used in the recipe, which after the first tool is damaged will match the undamaged one.
However removing that check still does not result in the behavior desired due to iterating the key set of the sourceList as our brand newly damaged tool will be added to the end of the set, so the 2nd tool will end up being damaged before the first one in the inventory