use of slimeknights.tconstruct.library.recipe.tinkerstation.IMutableTinkerStationContainer in project TinkersConstruct by SlimeKnights.
the class TinkerStationRepairRecipe method updateInputs.
@Override
public void updateInputs(ItemStack result, IMutableTinkerStationContainer inv, boolean isServer) {
ToolStack inputTool = ToolStack.from(inv.getTinkerableStack());
ToolStack resultTool = ToolStack.from(result);
// iterate stacks, removing items as we repair
int repairRemaining = inputTool.getDamage() - resultTool.getDamage();
MaterialId primaryMaterial = getPrimaryMaterial(inputTool);
for (int i = 0; i < inv.getInputCount() && repairRemaining > 0; i++) {
final int slot = i;
repairRemaining -= repairFromSlot(inputTool, primaryMaterial, inv, repairRemaining, i, count -> inv.shrinkInput(slot, count));
}
if (repairRemaining > 0) {
TConstruct.LOG.error("Recipe repair on {} consumed too few items. {} durability unaccounted for", result, repairRemaining);
}
}
use of slimeknights.tconstruct.library.recipe.tinkerstation.IMutableTinkerStationContainer in project TinkersConstruct by SlimeKnights.
the class ModifierRemovalRecipe method updateInputs.
@Override
public void updateInputs(ItemStack result, IMutableTinkerStationContainer inv, boolean isServer) {
// return salvage items for modifier, using the original tool as that still has the modifier
if (isServer) {
ItemStack toolStack = inv.getTinkerableStack();
ToolStack tool = ToolStack.from(toolStack);
ModifierEntry toRemove = getModifierToRemove(inv, tool.getUpgrades().getModifiers());
if (toRemove != null) {
AbstractModifierSalvage salvage = ModifierRecipeLookup.getSalvage(toolStack, tool, toRemove.getModifier(), toRemove.getLevel());
if (salvage != null) {
int salvageMax = Math.min(toolStack.getMaxStackSize(), salvage.getMaxToolSize());
int currentSize = result.getCount();
Consumer<ItemStack> consumer;
// if the size is smaller than 16, shrink all salvage stack sizes to prevent a salvage dupe
if (currentSize < salvageMax) {
consumer = stack -> {
int newSize = stack.getCount() * currentSize / salvageMax;
if (newSize > 0) {
stack.setCount(newSize);
inv.giveItem(stack);
}
};
// if larger, grow salvage
} else if (currentSize > salvageMax) {
consumer = stack -> {
int newSize = stack.getCount() * currentSize / salvageMax;
int maxStackSize = stack.getMaxStackSize();
while (newSize > maxStackSize) {
inv.giveItem(ItemHandlerHelper.copyStackWithSize(stack, maxStackSize));
newSize -= maxStackSize;
}
if (newSize > 0) {
stack.setCount(newSize);
inv.giveItem(stack);
}
};
} else {
consumer = inv::giveItem;
}
salvage.acceptItems(tool, consumer, TConstruct.RANDOM);
}
}
}
// remove the input item, done second as we need its location for salvage
for (int i = 0; i < inv.getInputCount(); i++) {
ItemStack stack = inv.getInput(i);
if (!stack.isEmpty() && ingredient.test(stack)) {
inv.shrinkInput(i, 1, container.copy());
break;
}
}
}
Aggregations