Skip to content

Commit

Permalink
Don't use deprecated ShapelessRecipe constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWoodworth committed Dec 25, 2017
1 parent 1d582aa commit b01edd8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/main/java/co/kepler/fastcraft/util/RecipeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public static int hashRecipe(Recipe r) {
* Clone a recipe.
*
* @param toClone The recipe to clone.
* @return Returns the cloned recipe, or null if unable to clone.
* @return Returns the cloned recipe.
*/
@SuppressWarnings("deprecation")
public static Recipe cloneRecipe(Recipe toClone) {
Expand All @@ -293,8 +293,7 @@ public static Recipe cloneRecipe(Recipe toClone) {
((ShapedRecipe) toClone).getKey(),
recipe.getResult().clone()
);
} catch (NoSuchMethodError e) {
// Fallback
} catch (NoSuchMethodError e) { // Fallback
result = new ShapedRecipe(recipe.getResult().clone());
}

Expand All @@ -312,7 +311,16 @@ public static Recipe cloneRecipe(Recipe toClone) {
return result;
} else if (toClone instanceof ShapelessRecipe) {
ShapelessRecipe recipe = (ShapelessRecipe) toClone;
ShapelessRecipe result = new ShapelessRecipe(recipe.getResult().clone());
ShapelessRecipe result;

try {
result = new ShapelessRecipe(
((ShapelessRecipe) toClone).getKey(),
recipe.getResult().clone()
);
} catch (NoSuchMethodError e) { // Fallback
result = new ShapelessRecipe(recipe.getResult().clone());
}

// Copy ingredients
for (ItemStack ingredient : recipe.getIngredientList()) {
Expand All @@ -323,7 +331,10 @@ public static Recipe cloneRecipe(Recipe toClone) {
FurnaceRecipe recipe = (FurnaceRecipe) toClone;
return new FurnaceRecipe(recipe.getResult().clone(), recipe.getInput().getData());
}
return null;

throw new UnsupportedOperationException(
"Unable to clone recipes of type " + toClone.getClass().getName()
);
}

public static ComparableRecipe comparable(Recipe recipe) {
Expand Down

0 comments on commit b01edd8

Please sign in to comment.