Search in sources :

Example 1 with IRecipeInput

use of net.mcft.copy.betterstorage.api.crafting.IRecipeInput 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);
}
Also used : IRecipeInput(net.mcft.copy.betterstorage.api.crafting.IRecipeInput) StationCrafting(net.mcft.copy.betterstorage.api.crafting.StationCrafting) StackEnchantment(net.mcft.copy.betterstorage.utils.StackUtils.StackEnchantment) RecipeInputItemStack(net.mcft.copy.betterstorage.api.crafting.RecipeInputItemStack) ItemStack(net.minecraft.item.ItemStack) RecipeInputItemStack(net.mcft.copy.betterstorage.api.crafting.RecipeInputItemStack)

Example 2 with IRecipeInput

use of net.mcft.copy.betterstorage.api.crafting.IRecipeInput in project BetterStorage by copygirl.

the class CardboardRepairRecipe method getSampleInputs.

@Override
@SideOnly(Side.CLIENT)
public List<IRecipeInput[]> getSampleInputs() {
    List<IRecipeInput[]> sampleInputs = new ArrayList<IRecipeInput[]>();
    if (BetterStorageItems.cardboardPickaxe != null) {
        ItemStack stack = new ItemStack(BetterStorageItems.cardboardPickaxe, 1, 32);
        stack.addEnchantment(Enchantment.efficiency, 5);
        stack.addEnchantment(Enchantment.unbreaking, 3);
        makeInput(sampleInputs, stack, BetterStorageItems.cardboardSheet);
    }
    makeInput(sampleInputs, new ItemStack(BetterStorageItems.cardboardPickaxe, 1, 32), BetterStorageItems.cardboardSheet);
    makeInput(sampleInputs, new ItemStack(BetterStorageItems.cardboardHelmet, 1, 11), new ItemStack(BetterStorageItems.cardboardChestplate, 1, 16), BetterStorageItems.cardboardSheet, new ItemStack(BetterStorageItems.cardboardLeggings, 1, 15), new ItemStack(BetterStorageItems.cardboardBoots, 1, 13));
    makeInput(sampleInputs, new ItemStack(BetterStorageItems.cardboardHelmet, 1, 11 * 2), new ItemStack(BetterStorageItems.cardboardChestplate, 1, 16 * 2), BetterStorageItems.cardboardSheet, new ItemStack(BetterStorageItems.cardboardLeggings, 1, 15 * 2), new ItemStack(BetterStorageItems.cardboardBoots, 1, 13 * 2), BetterStorageItems.cardboardSheet);
    makeInput(sampleInputs, new ItemStack(BetterStorageItems.cardboardHelmet, 1, 11 * 3), new ItemStack(BetterStorageItems.cardboardChestplate, 1, 16 * 3), BetterStorageItems.cardboardSheet, new ItemStack(BetterStorageItems.cardboardLeggings, 1, 15 * 3), new ItemStack(BetterStorageItems.cardboardBoots, 1, 13 * 3), BetterStorageItems.cardboardSheet, new ItemStack(BetterStorageItems.cardboardShovel, 1, 32), new ItemStack(BetterStorageItems.cardboardHoe, 1, 32), BetterStorageItems.cardboardSheet);
    return sampleInputs;
}
Also used : IRecipeInput(net.mcft.copy.betterstorage.api.crafting.IRecipeInput) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) RecipeInputItemStack(net.mcft.copy.betterstorage.api.crafting.RecipeInputItemStack) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 3 with IRecipeInput

use of net.mcft.copy.betterstorage.api.crafting.IRecipeInput 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);
}
Also used : IRecipeInput(net.mcft.copy.betterstorage.api.crafting.IRecipeInput) StationCrafting(net.mcft.copy.betterstorage.api.crafting.StationCrafting) StackEnchantment(net.mcft.copy.betterstorage.utils.StackUtils.StackEnchantment) RecipeInputItemStack(net.mcft.copy.betterstorage.api.crafting.RecipeInputItemStack) ItemStack(net.minecraft.item.ItemStack) RecipeInputItemStack(net.mcft.copy.betterstorage.api.crafting.RecipeInputItemStack)

Example 4 with IRecipeInput

use of net.mcft.copy.betterstorage.api.crafting.IRecipeInput in project BetterStorage by copygirl.

the class InventoryCraftingStation method craft.

/** Called when an item is removed from the output slot while it doesn't
	 *  store any real items. Returns if the recipe can be crafted again.*/
private boolean craft(EntityPlayer player, boolean simulate) {
    ItemStack[] contents = (simulate ? this.contents.clone() : this.contents);
    ItemStack[] crafting = (simulate ? this.crafting.clone() : this.crafting);
    if (simulate)
        for (int i = 0; i < crafting.length; i++) crafting[i] = ItemStack.copyItemStack(crafting[i]);
    if (currentCrafting instanceof VanillaStationCrafting) {
        boolean unset = false;
        if (player == null) {
            player = FakePlayer.get(entity);
            unset = true;
        }
        ItemStack craftOutput = (simulate ? output[4].copy() : output[4]);
        IInventory craftMatrix = new InventoryStacks(crafting);
        FMLCommonHandler.instance().firePlayerCraftingEvent(player, craftOutput, craftMatrix);
        new CustomSlotCrafting(player, craftOutput);
        if (unset) {
            FakePlayer.unset();
            player = null;
        }
    }
    ICraftingSource source = new CraftingSourceTileEntity(entity, player);
    currentCrafting.craft(source);
    IRecipeInput[] requiredInput = currentCrafting.getCraftRequirements();
    for (int i = 0; i < crafting.length; i++) if (crafting[i] != null)
        crafting[i] = craftSlot(crafting[i], requiredInput[i], player, simulate);
    boolean pulled = pullRequired(contents, crafting, requiredInput);
    if (!simulate) {
        int requiredExperience = currentCrafting.getRequiredExperience();
        if ((requiredExperience != 0) && (player != null) && !player.capabilities.isCreativeMode)
            player.experienceLevel -= requiredExperience;
        outputIsReal = !outputEmpty();
        progress = 0;
        inputChanged();
        checkHasRequirements = true;
    }
    return pulled;
}
Also used : VanillaStationCrafting(net.mcft.copy.betterstorage.item.recipe.VanillaStationCrafting) IInventory(net.minecraft.inventory.IInventory) ICraftingSource(net.mcft.copy.betterstorage.api.crafting.ICraftingSource) CraftingSourceTileEntity(net.mcft.copy.betterstorage.api.crafting.CraftingSourceTileEntity) IRecipeInput(net.mcft.copy.betterstorage.api.crafting.IRecipeInput) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IRecipeInput (net.mcft.copy.betterstorage.api.crafting.IRecipeInput)4 ItemStack (net.minecraft.item.ItemStack)4 RecipeInputItemStack (net.mcft.copy.betterstorage.api.crafting.RecipeInputItemStack)3 StationCrafting (net.mcft.copy.betterstorage.api.crafting.StationCrafting)2 StackEnchantment (net.mcft.copy.betterstorage.utils.StackUtils.StackEnchantment)2 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 ArrayList (java.util.ArrayList)1 CraftingSourceTileEntity (net.mcft.copy.betterstorage.api.crafting.CraftingSourceTileEntity)1 ICraftingSource (net.mcft.copy.betterstorage.api.crafting.ICraftingSource)1 VanillaStationCrafting (net.mcft.copy.betterstorage.item.recipe.VanillaStationCrafting)1 IInventory (net.minecraft.inventory.IInventory)1