-
-
Notifications
You must be signed in to change notification settings - Fork 339
Recipe Refactor #1419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recipe Refactor #1419
Changes from all commits
5627e4b
cb52f33
109bca5
1aca9b4
ecc5a22
4d54ae9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,12 +24,8 @@ | |
| */ | ||
| 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 com.google.common.collect.ImmutableCollection; | ||
| import org.spongepowered.api.item.inventory.ItemStackSnapshot; | ||
|
|
||
| /** | ||
| * <p>A Recipe represents some craftable recipe in the game.</p> | ||
|
|
@@ -47,29 +43,18 @@ | |
| 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. | ||
| * Gets the result of this {@link Recipe}. | ||
| * | ||
| * @param grid The ItemGrid to check for validity | ||
| * @return True if the given input matches this recipe's requirements | ||
| * @return the results of this {@link Recipe} | ||
| */ | ||
| boolean isValid(GridInventory grid); | ||
| ImmutableCollection<ItemStackSnapshot> getResults(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer if this returns any kind of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's immutable because we don't want people changing it... |
||
|
|
||
| /** | ||
| * Returns the results for running this Recipe over an {@link GridInventory} | ||
| * Gets the {@link RecipeRegistry} that | ||
| * corresponds with this Recipe. | ||
| * | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise with the previous deprecated method, this should be left in with |
||
| * @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 {@link RecipeRegistry} that corresponds with this Recipe | ||
| */ | ||
| Optional<List<ItemStack>> getResults(GridInventory grid); | ||
| RecipeRegistry<?> getRegistry(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this recipe is restricted to a single registry you should throw an IllegalArgumentException if you try to register it in a different one. Is there a builder method for this one?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason for this method? I'm not really against it being here, but IMO its simply not-required overhead.
What are your thoughts adding this method?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the point in having this method. Just gut it. |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,32 +24,37 @@ | |
| */ | ||
| package org.spongepowered.api.item.recipe; | ||
|
|
||
| import java.util.Set; | ||
| import com.google.common.collect.ImmutableCollection; | ||
| import org.spongepowered.api.item.recipe.crafting.CraftingRegistry; | ||
| import org.spongepowered.api.item.recipe.smelting.SmeltingRegistry; | ||
|
|
||
| import java.util.function.Predicate; | ||
|
|
||
| /** | ||
| * A RecipeRegistry holds all registered recipes for a given game. | ||
| * Used for {@link SmeltingRegistry} and {@link CraftingRegistry} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing full stop at end of sentence. |
||
| */ | ||
| public interface RecipeRegistry { | ||
| public interface RecipeRegistry<T extends Recipe> { | ||
|
|
||
| /** | ||
| * Registers the given Recipe to make it available to craft. | ||
| * | ||
| * @param recipe The Recipe to register | ||
| */ | ||
| void register(Recipe recipe); | ||
| void register(T recipe); | ||
|
|
||
| /** | ||
| * Removes the given Recipe from registration in this registry. | ||
| * Removes Recipes from this Registry using the given Predicate. | ||
| * | ||
| * @param recipe The Recipe to unregister | ||
| * @param predicate The check to remove the Recipe or not | ||
| * @return If it removed any recipes or not | ||
| */ | ||
| void remove(Recipe recipe); | ||
| boolean remove(Predicate<? super T> predicate); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't remove the previous version of this method, add a new one.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seconded, the removal of the recipe can still be retained. |
||
|
|
||
| /** | ||
| * Retrieves all recipes registered in this registry. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary whitespace removal. |
||
| * | ||
| * @return All registered recipes | ||
| */ | ||
| Set<Recipe> getRecipes(); | ||
| ImmutableCollection<T> getRecipes(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use |
||
|
|
||
| } | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * This file is part of SpongeAPI, licensed under the MIT License (MIT). | ||
| * | ||
| * Copyright (c) SpongePowered <https://www.spongepowered.org> | ||
| * Copyright (c) contributors | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
| package org.spongepowered.api.item.recipe.crafting; | ||
|
|
||
| import org.spongepowered.api.item.recipe.Recipe; | ||
|
|
||
| /** | ||
| * This represents a {@link Recipe} to be used in a Crafting Table. | ||
| * @see Recipe | ||
| */ | ||
| public interface CraftingRecipe extends Recipe { | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be left in with
@Deprecatedto just redirect to theCraftingRegistry.