001/*
002 * Trident - A Multithreaded Server Alternative
003 * Copyright 2014 The TridentSDK Team
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package net.tridentsdk.server.crafting;
018
019import net.tridentsdk.inventory.Item;
020import net.tridentsdk.inventory.crafting.CraftTuple;
021import net.tridentsdk.inventory.crafting.RecipeManager;
022
023import java.util.ArrayList;
024import java.util.List;
025
026/**
027 * Manages the server crafting and smelting recipes
028 *
029 * @author The TridentSDK Team
030 */
031public class TridentRecipeManager implements RecipeManager {
032    private List<SmeltingFuel> smeltingFuels = new ArrayList<>();
033    private List<SmeltingRecipe> smeltingRecipes = new ArrayList<>();
034
035    @Override
036    public void addShapelessRecipe(Item result, List<Item> source) {
037        // TODO
038    }
039
040    @Override
041    public void addShapedRecipe(Item result, char[][] grid, List<CraftTuple> source) {
042
043    }
044
045    @Override
046    public void addSmeltingRecipe(Item result, Item source, int smeltTicks, float experience) {
047        smeltingRecipes.add(new SmeltingRecipe(result, source, smeltTicks, experience));
048    }
049
050    @Override
051    public void addSmeltingFuel(Item source, int burnTicks, Item returnItem) {
052        smeltingFuels.add(new SmeltingFuel(source, burnTicks, returnItem));
053    }
054
055    /**
056     * Checks if the smelting fuel is able to be smelted on the server
057     *
058     * @param item the item to check
059     * @return {@code true} if the fuel can be smelted
060     */
061    public boolean isValidSmeltingFuel(Item item) {
062        return smeltingFuels.stream().anyMatch((fuel) -> fuel.source().isSimilarIgnoreQuantity(item));
063    }
064}