protected int calculateRepairAmount(List<Material> materials, NonNullList<ItemStack> repairItems) { Set<Material> materialsMatched = Sets.newHashSet(); float durability = 0f; // try to match each material once for(int index : getRepairParts()) { Material material = materials.get(index); if(materialsMatched.contains(material)) { continue; } // custom repairing durability += repairCustom(material, repairItems) * getRepairModifierForPart(index); Optional<RecipeMatch.Match> matchOptional = material.matches(repairItems); if(matchOptional.isPresent()) { RecipeMatch.Match match = matchOptional.get(); HeadMaterialStats stats = material.getStats(MaterialTypes.HEAD); if(stats != null) { materialsMatched.add(material); durability += ((float) stats.durability * (float) match.amount * getRepairModifierForPart(index)) / 144f; RecipeMatch.removeMatch(repairItems, match); } } } durability *= 1f + ((float) materialsMatched.size() - 1) / 9f; return (int) durability; }
@Override protected int repairCustom(Material material, NonNullList<ItemStack> repairItems) { Optional<RecipeMatch.Match> matchOptional = RecipeMatch.of(TinkerTools.sharpeningKit).matches(repairItems); if(!matchOptional.isPresent()) { return 0; } RecipeMatch.Match match = matchOptional.get(); for(ItemStack stacks : match.stacks) { // invalid material? if(TinkerTools.sharpeningKit.getMaterial(stacks) != material) { return 0; } } RecipeMatch.removeMatch(repairItems, match); HeadMaterialStats stats = material.getStats(MaterialTypes.HEAD); float durability = stats.durability * match.amount * TinkerTools.sharpeningKit.getCost(); durability /= Material.VALUE_Ingot; return (int) (durability); }
RecipeMatch.removeMatch(stacks, match); break; RecipeMatch.removeMatch(stacks, match); RecipeMatch.removeMatch(usedStacks, match);
RecipeMatch.removeMatch(materialItems, match.get());
RecipeMatch.removeMatch(items, match.get());
public Optional<RecipeMatch.Match> matchesRecursively(NonNullList<ItemStack> stacks) { stacks = copyItemStackArray(stacks); // copy so we don't modify original List<RecipeMatch.Match> matches = Lists.newLinkedList(); Optional<RecipeMatch.Match> matchOptional; int sum = 0; while((matchOptional = matches(stacks)).isPresent()) { RecipeMatch.Match match = matchOptional.get(); matches.add(match); RecipeMatch.removeMatch(stacks, match); sum += match.amount; } // merge all found matches into one match List<ItemStack> foundStacks = Lists.newLinkedList(); for(RecipeMatch.Match m : matches) { foundStacks.addAll(m.stacks); } return Optional.of(new RecipeMatch.Match(foundStacks, sum)); }
public Optional<RecipeMatch.Match> matches(NonNullList<ItemStack> stacks, int minAmount) { stacks = copyItemStackArray(stacks); // copy so we don't modify original List<RecipeMatch.Match> matches = Lists.newLinkedList(); Optional<RecipeMatch.Match> matchOptional; int sum = 0; while(sum < minAmount && (matchOptional = matches(stacks)).isPresent()) { RecipeMatch.Match match = matchOptional.get(); matches.add(match); RecipeMatch.removeMatch(stacks, match); sum += match.amount; } // not enough found if(sum < minAmount) { return Optional.empty(); } // merge all found matches into one match List<ItemStack> foundStacks = Lists.newLinkedList(); for(RecipeMatch.Match m : matches) { foundStacks.addAll(m.stacks); } return Optional.of(new RecipeMatch.Match(foundStacks, sum)); }