Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 12 additions & 4 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.CraftingRegistry;
import org.spongepowered.api.item.recipe.smelting.SmeltingRegistry;
import org.spongepowered.api.network.status.Favicon;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.plugin.PluginManager;
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 CraftingRegistry for this GameRegistry.
*
* @return The recipe registry
* @return The crafting recipe registry
*/
Copy link
Copy Markdown
Member

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 @Deprecated to just redirect to the CraftingRegistry.

RecipeRegistry getRecipeRegistry();
CraftingRegistry getCraftingRegistry();

/**
* Retrieves the SmeltingRegistry for this GameRegistry.
*
* @return The smelting registry
*/
SmeltingRegistry getSmeltingRegistry();

/**
* Gets a {@link ResourcePack} that's already been created by its ID.
Expand Down
33 changes: 9 additions & 24 deletions src/main/java/org/spongepowered/api/item/recipe/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer if this returns any kind of Collection instead of this specialized one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Collection

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.
*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Likewise with the previous deprecated method, this should be left in with @Deprecated to use the getResults() list.

* @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();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

  • 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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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
Expand Up @@ -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}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Collection

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't use ImmutableCollection, just Collection is fine (you can even say it's unmodifiable in the javadoc).


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

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 {

}
Loading