Search in sources :

Example 11 with Ingredient

use of org.spongepowered.api.item.recipe.crafting.Ingredient in project LanternServer by LanternPowered.

the class LanternShapedCraftingRecipeBuilder method build.

@Override
public IShapedCraftingRecipe build(String id, Object plugin) {
    checkState(!this.aisle.isEmpty(), "aisle has not been set");
    checkState(!this.ingredientMap.isEmpty(), "no ingredients set");
    checkState(this.resultProvider != null, "no result provider");
    checkNotNull(id, "id");
    checkNotNull(id, "plugin");
    final PluginContainer container = checkPlugin(plugin, "plugin");
    final int index = id.indexOf(':');
    if (index != -1) {
        final String pluginId = id.substring(0, index);
        checkState(pluginId.equals(container.getId()), "Plugin ids mismatch, " + "found %s in the id but got %s from the container", pluginId, container.getId());
        id = id.substring(index + 1);
    }
    final int h = this.aisle.size();
    checkState(h > 0, "The aisle cannot be empty.");
    final int w = this.aisle.get(0).length();
    checkState(w > 0, "The aisle cannot be empty.");
    final IIngredient[][] ingredients = new IIngredient[w][h];
    for (int j = 0; j < h; j++) {
        final String s = this.aisle.get(j);
        checkState(s.length() == w, "The aisle has an inconsistent width.");
        for (int i = 0; i < w; i++) {
            final char c = s.charAt(i);
            final Ingredient ingredient;
            if (c == ' ') {
                ingredient = Ingredient.NONE;
            } else {
                ingredient = this.ingredientMap.get(c);
                checkState(ingredient != null, "No ingredient is present for the character: %s", c);
            }
            ingredients[i][j] = (IIngredient) ingredient;
        }
    }
    final ItemStackSnapshot exemplary = this.resultProvider.getSnapshot(EmptyCraftingMatrix.INSTANCE, EmptyIngredientList.INSTANCE);
    return new LanternShapedCraftingRecipe(container.getId(), id, exemplary, this.groupName, this.resultProvider, ingredients);
}
Also used : IIngredient(org.lanternpowered.server.item.recipe.IIngredient) PluginContainer(org.spongepowered.api.plugin.PluginContainer) IIngredient(org.lanternpowered.server.item.recipe.IIngredient) Ingredient(org.spongepowered.api.item.recipe.crafting.Ingredient) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot)

Aggregations

Ingredient (org.spongepowered.api.item.recipe.crafting.Ingredient)11 IIngredient (org.lanternpowered.server.item.recipe.IIngredient)6 ItemStack (org.spongepowered.api.item.inventory.ItemStack)5 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)4 PluginContainer (org.spongepowered.api.plugin.PluginContainer)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Nullable (javax.annotation.Nullable)2 ShapedRecipes (net.minecraft.item.crafting.ShapedRecipes)2 ShapedCraftingRecipe (org.spongepowered.api.item.recipe.crafting.ShapedCraftingRecipe)2 Preconditions (com.google.common.base.Preconditions)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Char2ObjectArrayMap (it.unimi.dsi.fastutil.chars.Char2ObjectArrayMap)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1