use of org.spongepowered.api.item.recipe.crafting.ShapedCraftingRecipe in project SpongeCommon by SpongePowered.
the class SpongeShapedCraftingRecipeBuilder method build.
@Override
public ShapedCraftingRecipe build(String id, Object plugin) {
checkState(!this.aisle.isEmpty(), "aisle has not been set");
checkState(!this.ingredientMap.isEmpty(), "no ingredients set");
checkState(!this.result.isEmpty(), "no result set");
checkNotNull(id, "id");
checkNotNull(id, "plugin");
PluginContainer container = SpongeImpl.getPluginContainer(plugin);
if (!id.startsWith(container.getId() + ":")) {
id = container.getId() + ":" + id;
}
Iterator<String> aisleIterator = this.aisle.iterator();
String aisleRow = aisleIterator.next();
int width = aisleRow.length();
int height = 1;
checkState(width > 0, "The aisle cannot be empty.");
while (aisleIterator.hasNext()) {
height++;
aisleRow = aisleIterator.next();
checkState(aisleRow.length() == width, "The aisle has an inconsistent width.");
}
String[] keys = this.aisle.toArray(new String[this.aisle.size()]);
Map<String, net.minecraft.item.crafting.Ingredient> ingredientsMap = this.ingredientMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().toString(), e -> IngredientUtil.toNative(e.getValue())));
// Default space to Empty Ingredient
ingredientsMap.putIfAbsent(" ", net.minecraft.item.crafting.Ingredient.EMPTY);
// Throws JsonException when pattern is not complete or defines unused Ingredients
NonNullList<net.minecraft.item.crafting.Ingredient> ingredients = ShapedRecipes.deserializeIngredients(keys, ingredientsMap, width, height);
return ((ShapedCraftingRecipe) new SpongeShapedRecipe(id, this.groupName, width, height, ingredients, ItemStackUtil.toNative(this.result)));
}
use of org.spongepowered.api.item.recipe.crafting.ShapedCraftingRecipe in project SpongeCommon by SpongePowered.
the class RecipeTest method onInit.
@Listener
public void onInit(GamePreInitializationEvent event) {
final Ingredient s = Ingredient.of(STONE);
final Ingredient b = Ingredient.of(BED, WOOL);
final ItemStack item = ItemStack.of(BEDROCK, 1);
final DataTransactionResult trans = item.offer(Keys.ITEM_ENCHANTMENTS, Collections.singletonList(Enchantment.of(EnchantmentTypes.UNBREAKING, 1)));
if (trans.getType() != DataTransactionResult.Type.SUCCESS) {
this.plugin.getLogger().error("Could not build recipe output!");
}
final ShapedCraftingRecipe recipe = CraftingRecipe.shapedBuilder().rows().row(s, s, s).row(s, b, s).row(s, s, s).result(item).build("bedrock", this.plugin);
Sponge.getRegistry().getCraftingRecipeRegistry().register(recipe);
}
Aggregations