use of net.silentchaos512.lib.collection.StackList in project Silent-Gear by SilentChaos512.
the class QuickRepairRecipe method assemble.
@Override
public ItemStack assemble(CraftingContainer inv) {
StackList list = StackList.from(inv);
ItemStack gear = list.uniqueOfType(ICoreItem.class).copy();
ItemStack repairKit = list.uniqueOfType(RepairKitItem.class);
Collection<ItemStack> mats = list.allMatches(mat -> ModRecipes.isRepairMaterial(gear, mat));
// Repair with materials first
repairWithLooseMaterials(gear, repairKit, mats);
// Then use repair kit, if necessary
if (gear.getDamageValue() > 0 && repairKit.getItem() instanceof RepairKitItem) {
RepairKitItem item = (RepairKitItem) repairKit.getItem();
int value = item.getDamageToRepair(gear, repairKit, RepairContext.Type.QUICK);
if (value > 0) {
gear.setDamageValue(gear.getDamageValue() - Math.round(value));
}
}
GearData.incrementRepairCount(gear, 1);
GearData.recalculateStats(gear, ForgeHooks.getCraftingPlayer());
return gear;
}
use of net.silentchaos512.lib.collection.StackList in project Silent-Gear by SilentChaos512.
the class CombineFragmentsRecipe method assemble.
@Override
public ItemStack assemble(CraftingContainer craftingInventory) {
StackList list = StackList.from(craftingInventory);
ItemStack stack = list.firstOfType(FragmentItem.class);
if (stack.isEmpty())
return ItemStack.EMPTY;
IMaterialInstance material = FragmentItem.getMaterial(stack);
if (material == null)
return ItemStack.EMPTY;
// Get the actual item the fragment came from (if present)
if (!material.getItem().isEmpty()) {
return material.getItem();
}
// Try to get an equivalent item from the material's ingredient
ItemStack[] matchingStacks = material.getIngredient().getItems();
if (matchingStacks.length < 1) {
if (material.getIngredient() instanceof ExclusionIngredient) {
// Get excluded ingredients if no others are available
ItemStack[] allMatches = ((ExclusionIngredient) material.getIngredient()).getMatchingStacksWithExclusions();
if (allMatches.length > 0) {
return allMatches[0];
}
}
return ItemStack.EMPTY;
}
return matchingStacks[0].copy();
}
Aggregations