Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8ba0ae6
refactor recipe interfaces
Limeth Jan 2, 2017
9c7701f
fix license
Limeth Jan 2, 2017
3c06bed
fix a NPE
Limeth Jan 2, 2017
9614e90
add a getter for the smelting recipe registry to the GameRegistry
Limeth Jan 2, 2017
ec67f57
fix javadocs in RecipeRegistry
Jan 3, 2017
95c6ca1
improve javadocs of ShapedCraftingRecipe
Jan 3, 2017
03ee6e2
add missing spaces
Jan 3, 2017
83da10c
add missing spaces before braces
Jan 3, 2017
722d9e8
explain CraftingRecipe#getRecipeSize()
Limeth Jan 3, 2017
5e3a284
added missing null-checks
Limeth Jan 3, 2017
7c1bc39
move unnecessary implementation to SpongeCommon
Limeth Jan 3, 2017
15c63c5
added a world parameter to CraftingRecipe methods
Limeth Jan 3, 2017
83d9c96
fix various javadoc issues
Jan 4, 2017
d097751
remove unnecessary implementation
Limeth Jan 4, 2017
b759045
added CraftingResult
Jan 8, 2017
3e6a86f
builder improvements
Jan 8, 2017
6ad27ed
more builder improvements
Jan 8, 2017
ebfb0bf
make CraftingResult actually return ItemStackSnapshots, because it ne…
Jan 8, 2017
c4561f6
revert CraftingRecipe
Jan 8, 2017
0ebfe74
symmetry to nms
Jan 9, 2017
b5e0a3d
conflicting method
Jan 9, 2017
e628dad
create separate interfaces for recipe registries
Jan 9, 2017
d97cefd
make SmeltingRecipeRegistry actually extend RecipeRegistry
Jan 9, 2017
8b30232
remove the default implementation of ShapedCraftingRecipe#getSize()
Limeth Jan 14, 2017
f7a8356
satisfy @liach, mostly
Limeth Jan 14, 2017
38b102d
remove @Nullable from ItemStackSnapshots
Limeth Jan 14, 2017
6f4784f
interface improvements, remove unwanted @Nullables
Limeth Jan 14, 2017
5d85b69
minor adjustments
Limeth Jan 15, 2017
124a286
added a findMatchingRecipe method
Limeth Jan 15, 2017
63b7ac6
implement smelting recipes
Limeth Jan 16, 2017
b84a8a7
PR adjustments
Jan 18, 2017
de99fc1
remove unnecessary @Nonnulls
Limeth Jan 18, 2017
8f7d40b
No star imports.
Limeth Jan 18, 2017
0ef092b
make getIngredientPredicate throw an exception if out of bounds
Jan 19, 2017
40b6241
expose various methods in recipe registries; reintroduce CraftingResult
Jan 20, 2017
ea6161b
implement equals/hashCode/toString in recipe result classes
Limeth Jan 20, 2017
2b0ba2d
improve javadocs
Feb 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/main/java/org/spongepowered/api/GameRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
import org.spongepowered.api.item.ItemType;
import org.spongepowered.api.item.merchant.TradeOfferGenerator;
import org.spongepowered.api.item.merchant.VillagerRegistry;
import org.spongepowered.api.item.recipe.RecipeRegistry;
import org.spongepowered.api.item.recipe.crafting.CraftingRecipeRegistry;
import org.spongepowered.api.item.recipe.smelting.SmeltingRecipeRegistry;
import org.spongepowered.api.network.status.Favicon;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.plugin.PluginManager;
Expand All @@ -44,10 +45,10 @@
import org.spongepowered.api.registry.RegistryModuleAlreadyRegisteredException;
import org.spongepowered.api.resourcepack.ResourcePack;
import org.spongepowered.api.scoreboard.displayslot.DisplaySlot;
import org.spongepowered.api.statistic.Statistic;
import org.spongepowered.api.statistic.BlockStatistic;
import org.spongepowered.api.statistic.EntityStatistic;
import org.spongepowered.api.statistic.ItemStatistic;
import org.spongepowered.api.statistic.Statistic;
import org.spongepowered.api.statistic.StatisticType;
import org.spongepowered.api.text.format.TextColor;
import org.spongepowered.api.text.selector.SelectorFactory;
Expand Down Expand Up @@ -292,11 +293,18 @@ <T extends CatalogType> GameRegistry registerModule(Class<T> catalogClass, Catal
Favicon loadFavicon(BufferedImage image) throws IOException;

/**
* Retrieves the RecipeRegistry for this GameRegistry.
* Retrieves the crafting RecipeRegistry for this GameRegistry.
*
* @return The crafting recipe registry
*/
CraftingRecipeRegistry getCraftingRecipeRegistry();

/**
* Retrieves the smelting RecipeRegistry for this GameRegistry.
*
* @return The recipe registry
* @return The smelting recipe registry
*/
RecipeRegistry getRecipeRegistry();
SmeltingRecipeRegistry getSmeltingRecipeRegistry();

/**
* Gets a {@link ResourcePack} that's already been created by its ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
package org.spongepowered.api.item.inventory.crafting;

import org.spongepowered.api.item.inventory.type.GridInventory;
import org.spongepowered.api.item.recipe.Recipe;
import org.spongepowered.api.item.recipe.crafting.CraftingRecipe;
import org.spongepowered.api.world.World;

import java.util.Optional;

Expand All @@ -51,8 +52,9 @@ public interface CraftingInventory extends GridInventory {
/**
* Retrieves the recipe formed by this CraftingInventory, if any.
*
* @param world The world where the item would be crafted in
* @return The recipe or {@link Optional#empty()} if no recipe is formed
*/
Optional<Recipe> getRecipe();
Optional<CraftingRecipe> getRecipe(World world);

}
45 changes: 6 additions & 39 deletions src/main/java/org/spongepowered/api/item/recipe/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,52 +24,19 @@
*/
package org.spongepowered.api.item.recipe;

import org.spongepowered.api.item.ItemType;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.type.GridInventory;

import java.util.List;
import java.util.Optional;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;

/**
* <p>A Recipe represents some craftable recipe in the game.</p>
*
* <p>It is essentially a Predicate that checks for if a recipe is valid as well
* as a function from a crafting matrix to a list of {@link ItemStack}
* (the crafting result), therefore making it an immutable interface.</p>
*
* <p>The passed in ItemGrid is usually a crafting inventory, e.g.
* a 2x2 or 3x3 crafting matrix.</p>
*
* <p>The requirements of a Recipe can be general, they just have to
* eventually return a boolean given an itemgrid.</p>
* A general interface for recipes
*/
public interface Recipe {

/**
* Returns the list of item types that result when successful crafting of
* this Recipe is completed.
*
* @return The resultant list of item types
*/
List<ItemType> getResultTypes();

/**
* Checks if the given {@link GridInventory} fits the required constraints
* to craft this Recipe.
*
* @param grid The ItemGrid to check for validity
* @return True if the given input matches this recipe's requirements
*/
boolean isValid(GridInventory grid);

/**
* Returns the results for running this Recipe over an {@link GridInventory}
* A general result of this recipe. This result may be customized depending
* on the context.
*
* @param grid An ItemGrid as input
* @return A list of ItemStacks or {@link Optional#empty()} if the given
* ItemGrid does not match this recipe's requirements.
* @return The exemplary result of this recipe
*/
Optional<List<ItemStack>> getResults(GridInventory grid);
ItemStackSnapshot getExemplaryResult();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if 'exemplary' makes sense here. What does this represent?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its the item you see in the CraftingOutput before you take it out.

Copy link
Contributor Author

@Limeth Limeth Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The native IRecipe class contains an ItemStack getRecipeOutput(), where this value is used as the return value, and the FurnaceRecipes class contains a Map<ItemStack, ItemStack> smeltingList, where this value is used as a value in the map. I think these might be used in TooManyItems/NotEnoughItems to display the recipes, that's why I chose the word 'exemplary'.


}
20 changes: 10 additions & 10 deletions src/main/java/org/spongepowered/api/item/recipe/RecipeRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@
*/
package org.spongepowered.api.item.recipe;

import java.util.Set;
import java.util.Collection;

/**
* A RecipeRegistry holds all registered recipes for a given game.
*/
public interface RecipeRegistry {
public interface RecipeRegistry<T extends Recipe> {

/**
* Registers the given Recipe to make it available to craft.
* Registers the given {@link Recipe} to make it available to craft.
*
* @param recipe The Recipe to register
* @param recipe The {@link Recipe} to register
*/
void register(Recipe recipe);
void register(T recipe);

/**
* Removes the given Recipe from registration in this registry.
* Removes the given {@link Recipe} from registration in this registry.
*
* @param recipe The Recipe to unregister
* @param recipe The {@link Recipe} to unregister
*/
void remove(Recipe recipe);
void remove(T recipe);

/**
* Retrieves all recipes registered in this registry.
*
* @return All registered recipes
* @return An unmodifiable collection of registered recipes
*/
Set<Recipe> getRecipes();
Collection<T> getRecipes();

}
142 changes: 0 additions & 142 deletions src/main/java/org/spongepowered/api/item/recipe/ShapedRecipe.java

This file was deleted.

This file was deleted.

Loading