Conversation
| * @param output the {@link ItemStack} the recipe gives | ||
| * @param exp the amount of exp the recipe gives | ||
| */ | ||
| void addSmeltingRecipe(ItemStack input, ItemStack output, float exp); |
| @@ -0,0 +1,37 @@ | |||
| package org.spongepowered.api.item.recipe; | |||
|
I would like to see a public interface SmeltingRecipeRegistry {
void register(SmeltingRecipe recipe);
void remove(SmeltingRecipe recipe);
Set<SmeltingRecipe> getRecipes();
Optional<SmeltingRecipe> match(ItemStack itemStack);
// Move these to their own registry???
void registerFuel(Fuel fuel);
void removeFuel(Fuel fuel);
Set<Fuel> getFuels();
Optional<Fuel> matchFuel(ItemStack itemStack);
}public interface SmeltingRecipe {
ItemStackSnapshot getInput();
ItemStackSnapshot getOutput();
double getExperience();
int getDuration(); // Duration may also be nice to have
public interface Builder {
// Builder stuff
}
}And maybe also custom fuel? public interface Fuel {
ItemStackSnapshot getInput();
// The result item when the fuel is consumed, like a bucket from a lava bucket
Optional<ItemStackSnapshot> getReturnItem();
int getDuration();
public interface Builder {
// Builder stuff
}
} |
| public interface SmeltingRegistry { | ||
| /** | ||
| * Adds a smelting recipe to this registry. | ||
| * @param input the input of the recipe |
There was a problem hiding this comment.
Needs an empty javadoc line before this line. Same goes for all methods in this class.
Also the param descriptions should start with a capital letter after the param name.
| * @return the experience of the {@link ItemStack} | ||
| */ | ||
| float getExperience(ItemStack stack); | ||
| } |
There was a problem hiding this comment.
Please add an empty line before this line.
| * @param the {@link ItemStack} | ||
| * @return the {@link ItemStack} it makes | ||
| */ | ||
| ItemStack getMapping(ItemStack stack); |
There was a problem hiding this comment.
This should return Optionals for materials that are not registered/smeltable.
| * A RecipeRegistry holds all registered smelting recipes for a given game. | ||
| */ | ||
| public interface SmeltingRegistry { | ||
| /** |
There was a problem hiding this comment.
Missing newline before this line.
|
@Cybermaxke I was going to do that, until I realized that it would just be alot of = statements ... |
|
@Maxqia What are a lot of |
|
@Cybermaxke Minecraft Forge manages fuel registry with a list of |
|
eg. setInput(ItemStack input) { SpongeSmeltingStack : ItemStack input,output; |
|
Also SmeltingRegistry.register(SmeltingRecipe.builder().setInput(input).setOutput(output).setExp(exp).build()) -> SmeltingRegistry.addSmeltingRecipe(input,output,exp) |
| * @param stack the {@link ItemStack} | ||
| * @return the {@link ItemStack} it makes | ||
| */ | ||
| ItemStack getMapping(ItemStack stack); |
There was a problem hiding this comment.
This should return Optional<ItemStack>.
There was a problem hiding this comment.
Oops, forgot about that ...
gabizou
left a comment
There was a problem hiding this comment.
Some discussion is necessary on the use of ItemStacks instead of ItemStackSnapshots. Since there's a big difference between the two (recipes in the underlying implementation aren't meant to change, but seeing as there's no immutable implementation aside from Sponge's, that's a different issue). To the API, we should be marking the objects as immutable as much as possible, when necessary.
| * @return The recipe registry | ||
| * @return The smelting registry | ||
| */ | ||
| RecipeRegistry getRecipeRegistry(); |
There was a problem hiding this comment.
This needs to be left in with @Deprecated to just redirect to the CraftingRegistry.
| * @return The resultant list of item types | ||
| * @return the results of this {@link Recipe} | ||
| */ | ||
| List<ItemType> getResultTypes(); |
There was a problem hiding this comment.
Likewise with the previous deprecated method, this should be left in with @Deprecated to use the getResults() list.
| * @param grid The ItemGrid to check for validity | ||
| * @return True if the given input matches this recipe's requirements | ||
| */ | ||
| boolean isValid(GridInventory grid); |
There was a problem hiding this comment.
Should be left in as deprecated, potentially default implemented to return true? I'm not sure about it, but try to have as minimal of a breakage as possible.
There was a problem hiding this comment.
I mean there's nothing to break... it was always broken
There was a problem hiding this comment.
@Maxqia There's a difference between binary compatibility and something being inherently broken. This is a binary breakage, anything relying on these methods (while they should be deprecated) would ultimately fail to work between API builds. I don't see the reason why this wouldn't be possible to retain for the sake of deprecation and uselessness (you can even print out a pretty printed log if you want)
| * @return All registered recipes | ||
| */ | ||
| Set<Recipe> getRecipes(); | ||
|
|
| * type of recipe for this registry | ||
| */ | ||
| void register(Recipe recipe); | ||
| void register(Recipe recipe) throws IllegalArgumentException; |
There was a problem hiding this comment.
This is screaming about how it should use generics instead of just a raw Recipe type.
There was a problem hiding this comment.
Was just about to say that to myself :P
| * | ||
| * @return the experience given when this recipe is made | ||
| */ | ||
| float getExperience(); |
There was a problem hiding this comment.
Never use float, you gain nothing from it. Use double.
| * | ||
| * @return item needed to make this recipe | ||
| */ | ||
| ItemStack getIngredient(); |
There was a problem hiding this comment.
I'm curious why you're using an ItemStack instead of an ItemStackSnapshot.
| * | ||
| * @return the result of this {@link Recipe} | ||
| */ | ||
| ItemStack getResult(); |
| * @param stack the {@link ItemStack} | ||
| * @return the experience of the {@link ItemStack} | ||
| */ | ||
| Optional<Float> getExperience(ItemStack stack); |
There was a problem hiding this comment.
Should use Optional<Double> or if you want, java.util.OptionalDouble.
| * @return A ItemStack or {@link Optional#empty()} if the given | ||
| * ItemStack does not match any recipes. | ||
| */ | ||
| Optional<ItemStack> getResult(ItemStack stack); |
There was a problem hiding this comment.
Likewise, here, Optional<ItemStackSnapshot> instead.
| * @param ingredient The ingredient | ||
| * @return fluent interface | ||
| */ | ||
| Builder setIngredient(ItemStack ingredient); |
There was a problem hiding this comment.
You don't have to prefix the builder methods with set, just use for example ingredient.
There was a problem hiding this comment.
You should not prefix builder methods with set.
| */ | ||
| ItemStack getResult(); | ||
|
|
||
| default List<ItemStack> getResults() { |
|
|
||
| import java.util.List; | ||
|
|
||
| public interface SmeltingRecipe extends Recipe { |
| * Sets the ingredient for the requirements of this {@link SmeltingRecipe}. | ||
| * | ||
| * @param ingredient The ingredient | ||
| * @return fluent interface |
There was a problem hiding this comment.
Maybe change this to @return This instance for chaining (see other builders)
There was a problem hiding this comment.
Oh, I just copied that part of the comment from the other recipe builders, I'll change them too while I'm at it
2c10b77 to
304af21
Compare
| * @param stack the {@link ItemStack} | ||
| * @return the experience of the {@link ItemStack} | ||
| */ | ||
| Optional<Double> getExperience(ItemStack stack); |
There was a problem hiding this comment.
Use java.util.OptionalDouble
There was a problem hiding this comment.
No, it doesn't have a bunch of functions that Optional has ...
| * ItemStack does not match any recipes. | ||
| */ | ||
| Optional<ItemStack> getResult(ItemStack stack); | ||
| } |
| * @return A new {@link SmeltingRecipe} | ||
| */ | ||
| SmeltingRecipe build(); | ||
| } |
| * @param exp the experience | ||
| * @return This builder, for chaining | ||
| */ | ||
| Builder experience(float exp); |
There was a problem hiding this comment.
missed that, will do
| * | ||
| * @return the result of this {@link Recipe} | ||
| */ | ||
| ItemStack getResult(); |
| * @return A list of ItemStacks or {@link Optional#empty()} if the given | ||
| * {@link GridInventory} does not match any recipes. | ||
| */ | ||
| Optional<List<ItemStack>> getResults(GridInventory grid); |
There was a problem hiding this comment.
Can it return an empty list for nothing?
There was a problem hiding this comment.
Yeah, have to agree here, why Optional instead of just an empty list?
There was a problem hiding this comment.
IDK, just moved it from Recipe....
There was a problem hiding this comment.
| * {@link GridInventory} does not match any recipes. | ||
| */ | ||
| Optional<List<ItemStack>> getResults(GridInventory grid); | ||
| } |
| * Removes the given Recipe from registration in this registry. | ||
| * | ||
| * @param recipe The Recipe to unregister | ||
| * @return if it was successful or not |
| * ItemGrid does not match this recipe's requirements. | ||
| */ | ||
| Optional<List<ItemStack>> getResults(GridInventory grid); | ||
| RecipeRegistry<?> getRegistry(); |
There was a problem hiding this comment.
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?
| * @param grid The ItemGrid to check for validity | ||
| * @return True if the given input matches this recipe's requirements | ||
| */ | ||
| boolean isValid(GridInventory grid); |
There was a problem hiding this comment.
ImO this method would be better returning the matching recipe. The javadoc are strange currently.
| * @return The ingredients | ||
| */ | ||
| Collection<ItemStack> getIngredients(); | ||
| Collection<ItemStackSnapshot> getIngredients(); |
There was a problem hiding this comment.
Getting ingredients as snapshots makes sense but I wouldn't require them when adding to the builder. Makes working with the API painful (when it could turn them into snapshots itself).
| * @return the results of this {@link Recipe} | ||
| */ | ||
| Collection<ItemStackSnapshot> getResults(); | ||
| ImmutableCollection<ItemStackSnapshot> getResults(); |
There was a problem hiding this comment.
I would prefer if this returns any kind of Collection instead of this specialized one.
|
|
||
| /** | ||
| * A RecipeRegistry holds all registered recipes for a given game. | ||
| * Used for {@link SmeltingRegistry} and {@link CraftingRegistry} |
There was a problem hiding this comment.
Missing full stop at end of sentence.
| * @return the results of this {@link Recipe} | ||
| */ | ||
| boolean isValid(GridInventory grid); | ||
| ImmutableCollection<ItemStackSnapshot> getResults(); |
There was a problem hiding this comment.
It's immutable because we don't want people changing it...
| * @return All registered recipes | ||
| */ | ||
| Set<Recipe> getRecipes(); | ||
| ImmutableCollection<T> getRecipes(); |
There was a problem hiding this comment.
Don't use ImmutableCollection, just Collection is fine (you can even say it's unmodifiable in the javadoc).
| * @return A list of ItemStacks or {@link Optional#empty()} if the given | ||
| * {@link GridInventory} does not match any recipes. | ||
| */ | ||
| Optional<ImmutableCollection<ItemStackSnapshot>> getResults(GridInventory grid); |
There was a problem hiding this comment.
Collection<ItemStackSnapshot>
| * | ||
| * @return The ingredients | ||
| */ | ||
| ImmutableMap<Character, ItemStackSnapshot> getIngredients(); |
| * | ||
| * @return The aisle | ||
| */ | ||
| ImmutableCollection<String> getShape(); |
| * @return The builder | ||
| */ | ||
| default Builder ingredients(ItemStack... ingredients) { | ||
| return ingredients(ingredients); |
There was a problem hiding this comment.
Will cause StackOverflowException
| * @return A {@link ItemStackSnapshot} or {@link Optional#empty()} if the given | ||
| * {@link ItemType} does not match any recipes. | ||
| */ | ||
| Optional<ItemStackSnapshot> getResult(ItemType type); |
There was a problem hiding this comment.
Take ItemStackSnapshot as argument instead
There was a problem hiding this comment.
I put ItemType there because it ignores stack size. I'll probably be changing getExperience to that too
There was a problem hiding this comment.
No, meta is super important. Stack size can simply be ignored.
There was a problem hiding this comment.
The data on the ItemStack is 100% very important, not to just the ItemType.
| * @return If it removed any recipes or not | ||
| */ | ||
| void remove(Recipe recipe); | ||
| boolean remove(Predicate<? super T> predicate); |
There was a problem hiding this comment.
Don't remove the previous version of this method, add a new one.
There was a problem hiding this comment.
Seconded, the removal of the recipe can still be retained.
| * @param ingredients The ingredients | ||
| * @return The builder | ||
| */ | ||
| Builder ingredients(Collection<ItemStack> ingredients); |
There was a problem hiding this comment.
No ItemStackSnapshot support? (Sorry for nagging)
There was a problem hiding this comment.
Requested by Zidane to be an ItemStack :P https://github.com/SpongePowered/SpongeAPI/pull/1419/files/109bca54aacdfe4112c7a2b6ae536b5d86b62abb#diff-a6badc7df0748d1ae0caa7f85876c1c2
| * @return the {@link RecipeRegistry} that corresponds with this Recipe | ||
| */ | ||
| Optional<List<ItemStack>> getResults(GridInventory grid); | ||
| RecipeRegistry<?> getRegistry(); |
There was a problem hiding this comment.
What is the reason for this method?
I'm not really against it being here, but IMO its simply not-required overhead.
- If this is not yet/no longer registered, this would return null
- (if ever supported) custom impls might return the wrong registry
- I don't see a usecase
What are your thoughts adding this method?
There was a problem hiding this comment.
I don't see the point in having this method. Just gut it.
| * | ||
| * <p>This returns an unmodifiable copy of the original aisle.</p> | ||
| * | ||
| * @return The aisle |
| * @param ingredients The ingredients | ||
| * @return The builder | ||
| */ | ||
| default Builder ingredients(ItemStack... ingredients) { |
There was a problem hiding this comment.
In general, avoid only adding vararg methods like this, if possible, you should have single argument methods and then two argument methods with the second argument being a vararg. This would simplify some logic.
| * @return The builder | ||
| */ | ||
| default Builder ingredients(ItemType... ingredients) { | ||
| return ingredients(Lists.newArrayList(ingredients).stream().map( |
There was a problem hiding this comment.
Fix this formatting, it looks bad. Refer to other areas where streams are used.
| */ | ||
| ItemStackSnapshot getResult(); | ||
|
|
||
| default ImmutableCollection<ItemStackSnapshot> getResults() { |
There was a problem hiding this comment.
You javadoc everything else but not this method? I'm confused as to why there's a single result and then a collection of other results. What other results can there be?
There was a problem hiding this comment.
I'm fairly certain there are a number of mods which give out more than one result in the furnace, can't think of any off the top of my head though.
There was a problem hiding this comment.
Oh, It's a defaulted method from Recipe :P. not sure if @OverRide works here
There was a problem hiding this comment.
@Maxqia Yes, @Override works here. You should always annotate the methods appropriately so it's plain and clear that the method doesn't originate from this interface/class and is an overridden method. Everything in Sponge follows this rule.
|
This is more than likely going to need changes with 1.12 arrives. |
|
@kashike While that is true, would it be worth having the changes being made so that recipes can be managed in API 6 and maybe 7? |
|
I'm going to close this in favour of #1582. |
API | Common
Test Code : https://gist.github.com/Maxqia/5579f49f9cfd3f4b08d6912d899d259d