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);
}
Aggregations