Search in sources :

Example 11 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project ArsMagica2 by Mithion.

the class RecipeUtilities method getRecipeFor.

public static IRecipe getRecipeFor(ItemStack item) {
    if (item == null || item.getItem() == null)
        return null;
    try {
        List list = CraftingManager.getInstance().getRecipeList();
        ArrayList possibleRecipes = new ArrayList();
        for (Object recipe : list) {
            if (recipe instanceof IRecipe) {
                ItemStack output = ((IRecipe) recipe).getRecipeOutput();
                if (output == null)
                    continue;
                if (output.getItem() == item.getItem() && (output.getItemDamage() == Short.MAX_VALUE || output.getItemDamage() == item.getItemDamage())) {
                    possibleRecipes.add(recipe);
                }
            }
        }
        if (possibleRecipes.size() > 0) {
            for (Object recipe : possibleRecipes) {
                if (((IRecipe) recipe).getRecipeOutput().getItemDamage() == item.getItemDamage()) {
                    return (IRecipe) recipe;
                }
            }
            return (IRecipe) possibleRecipes.get(0);
        }
    } catch (Throwable t) {
    }
    return null;
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 12 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project Railcraft by Railcraft.

the class ThaumcraftApi method getCraftingRecipeKey.

public static Object[] getCraftingRecipeKey(EntityPlayer player, ItemStack stack) {
    int[] key = new int[] { Item.getIdFromItem(stack.getItem()), stack.getItemDamage() };
    if (keyCache.containsKey(key)) {
        if (keyCache.get(key) == null)
            return null;
        if (ResearchHelper.isResearchComplete(player.getName(), (String) (keyCache.get(key))[0]))
            return keyCache.get(key);
        else
            return null;
    }
    for (ResearchCategoryList rcl : ResearchCategories.researchCategories.values()) {
        for (ResearchItem ri : rcl.research.values()) {
            if (ri.getPages() == null)
                continue;
            for (int a = 0; a < ri.getPages().length; a++) {
                ResearchPage page = ri.getPages()[a];
                if (page.recipe != null && page.recipe instanceof CrucibleRecipe[]) {
                    CrucibleRecipe[] crs = (CrucibleRecipe[]) page.recipe;
                    for (CrucibleRecipe cr : crs) {
                        if (cr.getRecipeOutput().isItemEqual(stack)) {
                            keyCache.put(key, new Object[] { ri.key, a });
                            if (ResearchHelper.isResearchComplete(player.getName(), ri.key))
                                return new Object[] { ri.key, a };
                        }
                    }
                } else if (page.recipe != null && page.recipe instanceof InfusionRecipe[]) {
                    InfusionRecipe[] crs = (InfusionRecipe[]) page.recipe;
                    for (InfusionRecipe cr : crs) {
                        if (cr.getRecipeOutput() instanceof ItemStack && ((ItemStack) cr.getRecipeOutput()).isItemEqual(stack)) {
                            keyCache.put(key, new Object[] { ri.key, a });
                            if (ResearchHelper.isResearchComplete(player.getName(), ri.key))
                                return new Object[] { ri.key, a };
                        }
                    }
                } else if (page.recipe != null && page.recipe instanceof IRecipe[]) {
                    IRecipe[] crs = (IRecipe[]) page.recipe;
                    for (IRecipe cr : crs) {
                        if (cr.getRecipeOutput().isItemEqual(stack)) {
                            keyCache.put(key, new Object[] { ri.key, a });
                            if (ResearchHelper.isResearchComplete(player.getName(), ri.key))
                                return new Object[] { ri.key, a };
                        }
                    }
                } else if (page.recipeOutput != null && stack != null && (page.recipeOutput instanceof ItemStack && ((ItemStack) page.recipeOutput).isItemEqual(stack)) || (page.recipeOutput instanceof String && ThaumcraftApiHelper.containsMatch(true, new ItemStack[] { stack }, OreDictionary.getOres((String) page.recipeOutput)))) {
                    keyCache.put(key, new Object[] { ri.key, a });
                    if (ResearchHelper.isResearchComplete(player.getName(), ri.key))
                        return new Object[] { ri.key, a };
                    else
                        return null;
                }
            }
        }
    }
    keyCache.put(key, null);
    return null;
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) CrucibleRecipe(thaumcraft.api.crafting.CrucibleRecipe) ResearchPage(thaumcraft.api.research.ResearchPage) ResearchItem(thaumcraft.api.research.ResearchItem) ResearchCategoryList(thaumcraft.api.research.ResearchCategoryList) InfusionRecipe(thaumcraft.api.crafting.InfusionRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 13 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project Railcraft by Railcraft.

the class ItemLocomotive method defineRecipes.

@Override
public void defineRecipes() {
    IRecipe recipe = new LocomotivePaintingRecipe(new ItemStack(this));
    CraftingPlugin.addRecipe(recipe);
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 14 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project Railcraft by Railcraft.

the class RollingMachineCraftingManager method addRecipe.

@Override
public void addRecipe(@Nullable ItemStack result, Object... recipeArray) {
    CraftingPlugin.ProcessedRecipe processedRecipe;
    try {
        processedRecipe = CraftingPlugin.processRecipe(CraftingPlugin.RecipeType.SHAPED, result, recipeArray);
    } catch (InvalidRecipeException ex) {
        Game.logTrace(Level.WARN, ex.getRawMessage());
        return;
    }
    if (processedRecipe.isOreRecipe) {
        IRecipe recipe = new ShapedOreRecipe(processedRecipe.result, processedRecipe.recipeArray);
        addRecipe(recipe);
    } else
        addRecipe(CraftingPlugin.makeVanillaShapedRecipe(processedRecipe.result, processedRecipe.recipeArray));
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) CraftingPlugin(mods.railcraft.common.plugins.forge.CraftingPlugin)

Example 15 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project Skree by Skelril.

the class MarketVerifyCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Optional<MarketService> optService = Sponge.getServiceManager().provide(MarketService.class);
    if (!optService.isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, "The market service is not currently running."));
        return CommandResult.empty();
    }
    MarketService service = optService.get();
    Task.builder().async().execute(() -> {
        PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
        List<Clause<String, BigDecimal>> profitMargins = new ArrayList<>();
        for (IRecipe recipe : CraftingManager.getInstance().getRecipeList()) {
            ItemStack output = recipe.getRecipeOutput();
            if (output == null) {
                continue;
            }
            Optional<BigDecimal> optResultPrice = service.getPrice(tf(output));
            if (!optResultPrice.isPresent()) {
                continue;
            }
            String name = service.getAlias(tf(output)).orElse(output.getItem().getRegistryName().toString());
            Collection<ItemStack> items = new ArrayList<>();
            if (recipe instanceof ShapedRecipes) {
                items.addAll(Lists.newArrayList(((ShapedRecipes) recipe).recipeItems));
            } else if (recipe instanceof ShapelessRecipes) {
                items.addAll(((ShapelessRecipes) recipe).recipeItems);
            } else {
                src.sendMessage(Text.of(TextColors.RED, "Unsupported recipe for " + name));
                continue;
            }
            items.removeAll(Collections.singleton(null));
            BigDecimal creationCost = BigDecimal.ZERO;
            try {
                for (ItemStack stack : items) {
                    creationCost = creationCost.add(service.getPrice(tf(stack)).orElse(BigDecimal.ZERO));
                }
            } catch (Exception ex) {
                src.sendMessage(Text.of(TextColors.RED, "Couldn't complete checks for " + name));
                continue;
            }
            if (creationCost.equals(BigDecimal.ZERO)) {
                src.sendMessage(Text.of(TextColors.RED, "No ingredients found on market for " + name));
                continue;
            }
            BigDecimal sellPrice = optResultPrice.get();
            sellPrice = sellPrice.multiply(service.getSellFactor(sellPrice));
            profitMargins.add(new Clause<>(name, sellPrice.subtract(creationCost)));
        }
        List<Text> result = profitMargins.stream().sorted((a, b) -> b.getValue().subtract(a.getValue()).intValue()).map(a -> {
            boolean profitable = a.getValue().compareTo(BigDecimal.ZERO) >= 0;
            return Text.of(profitable ? TextColors.RED : TextColors.GREEN, a.getKey().toUpperCase(), " has a profit margin of ", profitable ? "+" : "", MarketImplUtil.format(a.getValue()));
        }).collect(Collectors.toList());
        pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Profit Margin Report")).padding(Text.of(" ")).sendTo(src);
    }).submit(SkreePlugin.inst());
    src.sendMessage(Text.of(TextColors.YELLOW, "Verification in progress..."));
    return CommandResult.success();
}
Also used : java.util(java.util) ItemStack(net.minecraft.item.ItemStack) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) SkreePlugin(com.skelril.skree.SkreePlugin) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) CommandExecutor(org.spongepowered.api.command.spec.CommandExecutor) Task(org.spongepowered.api.scheduler.Task) ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) TextColors(org.spongepowered.api.text.format.TextColors) ForgeTransformer.tf(com.skelril.nitro.transformer.ForgeTransformer.tf) MarketImplUtil(com.skelril.skree.content.market.MarketImplUtil) CommandResult(org.spongepowered.api.command.CommandResult) IRecipe(net.minecraft.item.crafting.IRecipe) CommandSource(org.spongepowered.api.command.CommandSource) Sponge(org.spongepowered.api.Sponge) MarketService(com.skelril.skree.service.MarketService) PaginationService(org.spongepowered.api.service.pagination.PaginationService) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes) Collectors(java.util.stream.Collectors) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) CommandException(org.spongepowered.api.command.CommandException) CraftingManager(net.minecraft.item.crafting.CraftingManager) Clause(com.skelril.nitro.Clause) ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) BigDecimal(java.math.BigDecimal) CommandException(org.spongepowered.api.command.CommandException) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Clause(com.skelril.nitro.Clause) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes) MarketService(com.skelril.skree.service.MarketService)

Aggregations

IRecipe (net.minecraft.item.crafting.IRecipe)34 ItemStack (net.minecraft.item.ItemStack)25 ArrayList (java.util.ArrayList)12 ShapedRecipes (net.minecraft.item.crafting.ShapedRecipes)7 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)7 List (java.util.List)4 CraftingSetType (logisticspipes.network.packets.block.CraftingSetType)4 ShapelessRecipes (net.minecraft.item.crafting.ShapelessRecipes)4 HashMap (java.util.HashMap)3 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)3 Block (net.minecraft.block.Block)3 Item (net.minecraft.item.Item)3 IPostInit (com.builtbroken.mc.core.registry.implement.IPostInit)2 IRecipeContainer (com.builtbroken.mc.core.registry.implement.IRecipeContainer)2 IJsonGenObject (com.builtbroken.mc.lib.json.imp.IJsonGenObject)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 AutoCraftingInventory (logisticspipes.blocks.crafting.AutoCraftingInventory)2 InvalidRecipeException (mods.railcraft.common.util.crafting.InvalidRecipeException)2 ChatComponentText (net.minecraft.util.ChatComponentText)2