use of net.mcft.copy.betterstorage.api.crafting.RecipeInputItemStack in project BetterStorage by copygirl.
the class CardboardEnchantmentRecipe method checkMatch.
@Override
public StationCrafting checkMatch(ItemStack[] input, RecipeBounds bounds) {
// Quick check if input matches the recipe.
boolean hasCardboardItems = false;
int bookIndex = -1;
ItemStack book = null;
for (int i = 0; i < input.length; i++) {
ItemStack stack = input[i];
if (stack == null)
continue;
if (stack.getItem() instanceof ICardboardItem)
hasCardboardItems = true;
else if ((book == null) && (stack.getItem() == Items.enchanted_book)) {
bookIndex = i;
book = stack;
} else
return null;
}
if ((book == null) || !hasCardboardItems)
return null;
// Basic items match the recipe,
// do more expensive stuff now.
ItemStack[] output = new ItemStack[9];
int experienceCost = 0;
IRecipeInput[] requiredInput = new IRecipeInput[9];
Collection<StackEnchantment> bookEnchantments = StackUtils.getEnchantments(book).values();
for (int i = 0; i < input.length; i++) {
ItemStack stack = input[i];
if ((stack == null) || !(stack.getItem() instanceof ICardboardItem))
continue;
ItemStack outputStack = stack.copy();
boolean canApply = false;
Map<Integer, StackEnchantment> stackEnchants = StackUtils.getEnchantments(outputStack);
int numEnchants = stackEnchants.size();
for (StackEnchantment bookEnch : bookEnchantments) {
if (!StackUtils.isEnchantmentCompatible(outputStack, stackEnchants.values(), bookEnch))
continue;
StackEnchantment stackEnch = stackEnchants.get(bookEnch.ench.effectId);
// Calculate enchantment cost.
int level = (bookEnch.getLevel() - ((stackEnch != null) ? stackEnch.getLevel() : 0));
experienceCost += calculateCost(bookEnch, (stackEnch == null), numEnchants);
// Set enchantment level of output item.
if (stackEnch != null)
stackEnch.setLevel(bookEnch.getLevel());
else
outputStack.addEnchantment(bookEnch.ench, bookEnch.getLevel());
canApply = true;
}
// be applied on the item, the recipe is invalid.
if (!canApply)
return null;
output[i] = outputStack;
requiredInput[i] = new RecipeInputItemStack(StackUtils.copyStack(stack, 1), true);
}
requiredInput[bookIndex] = new RecipeInputItemStack(StackUtils.copyStack(book, 0, false));
return new StationCrafting(output, requiredInput, experienceCost);
}
use of net.mcft.copy.betterstorage.api.crafting.RecipeInputItemStack in project BetterStorage by copygirl.
the class CardboardRepairRecipe method checkMatch.
@Override
public StationCrafting checkMatch(ItemStack[] input, RecipeBounds bounds) {
// Quick check if input matches the recipe.
boolean hasCardboardItems = false;
int numSheets = 0;
int totalDamage = 0;
for (int i = 0; i < input.length; i++) {
ItemStack stack = input[i];
if (stack == null)
continue;
if (stack.getItem() instanceof ICardboardItem) {
hasCardboardItems = true;
totalDamage += stack.getItemDamage();
} else if (sheetUsed.matches(stack))
numSheets++;
else
return null;
}
if (!hasCardboardItems || (numSheets <= 0))
return null;
// If there's not enough sheets to repair all items, return null.
int numSheetsNeeded = (totalDamage + 79) / 80;
if (numSheetsNeeded > numSheets)
return null;
// Basic items match the recipe,
// do more expensive stuff now.
ItemStack[] output = new ItemStack[9];
int experienceCost = 0;
IRecipeInput[] requiredInput = new IRecipeInput[9];
for (int i = 0; i < input.length; i++) {
ItemStack stack = input[i];
if (stack == null)
continue;
ItemStack outputStack = null;
if (stack.getItem() instanceof ICardboardItem) {
Collection<StackEnchantment> enchantments = StackUtils.getEnchantments(stack).values();
experienceCost += Math.max(enchantments.size() - 1, 0);
for (StackEnchantment ench : enchantments) experienceCost += calculateCost(ench);
outputStack = StackUtils.copyStack(stack, 1);
outputStack.setItemDamage(0);
ItemStack requiredStack = outputStack.copy();
requiredStack.setItemDamage(OreDictionary.WILDCARD_VALUE);
requiredStack.setTagCompound(null);
requiredInput[i] = new RecipeInputItemStack(requiredStack);
} else
requiredInput[i] = ((numSheetsNeeded-- > 0) ? sheetUsed : sheetUnused);
output[i] = outputStack;
}
return new StationCrafting(output, requiredInput, experienceCost);
}
Aggregations