Skip to content

Commit a0ce641

Browse files
committed
Expand support for exact recipe ingredients
* Fixes error on exact ingredient array construction * Adds exact ingredient support for cooking and stonecutting recipes * Adds support for removing non-vanilla recipes
1 parent 1ac230f commit a0ce641

15 files changed

+265
-297
lines changed

src/main/java/com/laytonsmith/abstraction/MCCookingRecipe.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import com.laytonsmith.abstraction.blocks.MCMaterial;
44

55
public interface MCCookingRecipe extends MCRecipe {
6-
MCMaterial[] getInput();
6+
MCRecipeChoice getInput();
77
void setInput(MCItemStack input);
88
void setInput(MCMaterial mat);
9-
void setInput(MCMaterial... mats);
9+
void setInput(MCRecipeChoice choice);
1010
int getCookingTime();
1111
void setCookingTime(int ticks);
1212
float getExperience();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.laytonsmith.abstraction;
2+
3+
import com.laytonsmith.abstraction.blocks.MCMaterial;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public interface MCRecipeChoice {
9+
10+
class MaterialChoice implements MCRecipeChoice {
11+
List<MCMaterial> choices = new ArrayList<>();
12+
13+
public void addMaterial(MCMaterial material) {
14+
choices.add(material);
15+
}
16+
17+
public List<MCMaterial> getMaterials() {
18+
return choices;
19+
}
20+
}
21+
22+
class ExactChoice implements MCRecipeChoice {
23+
List<MCItemStack> choices = new ArrayList<>();
24+
25+
public void addItem(MCItemStack itemStack) {
26+
choices.add(itemStack);
27+
}
28+
29+
public List<MCItemStack> getItems() {
30+
return choices;
31+
}
32+
}
33+
}

src/main/java/com/laytonsmith/abstraction/MCShapedRecipe.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
import java.util.Map;
66

77
public interface MCShapedRecipe extends MCRecipe {
8-
Map<Character, MCMaterial[]> getIngredientMap();
8+
Map<Character, MCRecipeChoice> getIngredientMap();
99
String[] getShape();
1010
void setIngredient(char key, MCItemStack ingredient);
11-
void setIngredient(char key, MCItemStack... ingredient);
11+
void setIngredient(char key, MCRecipeChoice ingredient);
1212
void setIngredient(char key, MCMaterial ingredient);
13-
void setIngredient(char key, MCMaterial... ingredients);
1413
void setShape(String[] shape);
1514
}

src/main/java/com/laytonsmith/abstraction/MCShapelessRecipe.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
import java.util.List;
66

77
public interface MCShapelessRecipe extends MCRecipe {
8-
void addIngredient(MCItemStack ingredient);
8+
void addIngredient(MCMaterial ingredient, int amount);
99
void addIngredient(MCMaterial ingredient);
10-
void addIngredient(MCMaterial... ingredients);
11-
void addIngredient(MCItemStack... ingredients);
12-
List<MCMaterial[]> getIngredients();
10+
void addIngredient(MCRecipeChoice choice);
11+
List<MCRecipeChoice> getIngredients();
1312
}

src/main/java/com/laytonsmith/abstraction/MCStonecuttingRecipe.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import com.laytonsmith.abstraction.blocks.MCMaterial;
44

55
public interface MCStonecuttingRecipe extends MCRecipe {
6-
MCMaterial[] getInput();
6+
MCRecipeChoice getInput();
77
void setInput(MCItemStack input);
88
void setInput(MCMaterial mat);
9-
void setInput(MCMaterial... mats);
9+
void setInput(MCRecipeChoice choice);
1010
}

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ public MCRecipe GetNewRecipe(String key, MCRecipeType type, MCItemStack result)
845845
case CAMPFIRE:
846846
return new BukkitMCCookingRecipe(new CampfireRecipe(nskey, is, Material.STRUCTURE_VOID, 0.0F, 100), type);
847847
case FURNACE:
848-
return new BukkitMCFurnaceRecipe(new FurnaceRecipe(nskey, is, Material.STRUCTURE_VOID, 0.0F, 200));
848+
return new BukkitMCCookingRecipe(new FurnaceRecipe(nskey, is, Material.STRUCTURE_VOID, 0.0F, 200), type);
849849
case SHAPED:
850850
return new BukkitMCShapedRecipe(new ShapedRecipe(nskey, is));
851851
case SHAPELESS:
@@ -878,6 +878,8 @@ public static MCRecipe BukkitGetRecipe(Recipe r) {
878878
return new BukkitMCCookingRecipe(r, MCRecipeType.CAMPFIRE);
879879
} else if(r instanceof SmokingRecipe) {
880880
return new BukkitMCCookingRecipe(r, MCRecipeType.SMOKING);
881+
} else if(r instanceof FurnaceRecipe) {
882+
return new BukkitMCCookingRecipe(r, MCRecipeType.FURNACE);
881883
} else if(r instanceof StonecuttingRecipe) {
882884
return new BukkitMCStonecuttingRecipe((StonecuttingRecipe) r);
883885
} else if(r instanceof ComplexRecipe) {
@@ -888,8 +890,6 @@ public static MCRecipe BukkitGetRecipe(Recipe r) {
888890
return new BukkitMCShapelessRecipe((ShapelessRecipe) r);
889891
} else if(r instanceof ShapedRecipe) {
890892
return new BukkitMCShapedRecipe((ShapedRecipe) r);
891-
} else if(r instanceof FurnaceRecipe) {
892-
return new BukkitMCFurnaceRecipe((FurnaceRecipe) r);
893893
} else if(r instanceof MerchantRecipe) {
894894
return new BukkitMCMerchantRecipe((MerchantRecipe) r);
895895
} else {

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCCookingRecipe.java

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.laytonsmith.abstraction.MCCookingRecipe;
44
import com.laytonsmith.abstraction.MCItemStack;
5+
import com.laytonsmith.abstraction.MCRecipeChoice;
6+
import com.laytonsmith.abstraction.MCRecipeChoice.ExactChoice;
7+
import com.laytonsmith.abstraction.MCRecipeChoice.MaterialChoice;
58
import com.laytonsmith.abstraction.blocks.MCMaterial;
69
import com.laytonsmith.abstraction.bukkit.blocks.BukkitMCMaterial;
710
import com.laytonsmith.abstraction.enums.MCRecipeType;
@@ -11,11 +14,12 @@
1114
import org.bukkit.inventory.ItemStack;
1215
import org.bukkit.inventory.RecipeChoice;
1316

17+
import java.util.ArrayList;
1418
import java.util.List;
1519

1620
public class BukkitMCCookingRecipe extends BukkitMCRecipe implements MCCookingRecipe {
1721

18-
private MCRecipeType type;
22+
private final MCRecipeType type;
1923

2024
public BukkitMCCookingRecipe(Recipe recipe, MCRecipeType type) {
2125
super(recipe);
@@ -53,18 +57,27 @@ public CookingRecipe getHandle() {
5357
}
5458

5559
@Override
56-
public MCMaterial[] getInput() {
57-
List<Material> choices = ((RecipeChoice.MaterialChoice) getHandle().getInputChoice()).getChoices();
58-
MCMaterial[] ret = new MCMaterial[choices.size()];
59-
for(int i = 0; i < choices.size(); i++) {
60-
ret[i] = BukkitMCMaterial.valueOfConcrete(choices.get(i));
60+
public MCRecipeChoice getInput() {
61+
RecipeChoice recipeChoice = getHandle().getInputChoice();
62+
if(recipeChoice instanceof RecipeChoice.MaterialChoice materialChoice) {
63+
MCRecipeChoice.MaterialChoice choice = new MCRecipeChoice.MaterialChoice();
64+
for(Material material : materialChoice.getChoices()) {
65+
choice.addMaterial(BukkitMCMaterial.valueOfConcrete(material));
66+
}
67+
return choice;
68+
} else if(recipeChoice instanceof RecipeChoice.ExactChoice exactChoice) {
69+
MCRecipeChoice.ExactChoice choice = new MCRecipeChoice.ExactChoice();
70+
for(ItemStack itemStack : exactChoice.getChoices()) {
71+
choice.addItem(new BukkitMCItemStack(itemStack));
72+
}
73+
return choice;
6174
}
62-
return ret;
75+
throw new UnsupportedOperationException("Unsupported recipe choice");
6376
}
6477

6578
@Override
6679
public void setInput(MCItemStack input) {
67-
getHandle().setInput(((ItemStack) input.getHandle()).getType());
80+
getHandle().setInputChoice(new RecipeChoice.ExactChoice((ItemStack) input.getHandle()));
6881
}
6982

7083
@Override
@@ -73,12 +86,20 @@ public void setInput(MCMaterial mat) {
7386
}
7487

7588
@Override
76-
public void setInput(MCMaterial... mats) {
77-
Material[] concrete = new Material[mats.length];
78-
for(int i = 0; i < mats.length; i++) {
79-
concrete[i] = (Material) mats[i].getHandle();
89+
public void setInput(MCRecipeChoice choice) {
90+
if(choice instanceof MCRecipeChoice.ExactChoice) {
91+
List<ItemStack> itemChoice = new ArrayList<>();
92+
for(MCItemStack itemStack : ((ExactChoice) choice).getItems()) {
93+
itemChoice.add((ItemStack) itemStack.getHandle());
94+
}
95+
getHandle().setInputChoice(new RecipeChoice.ExactChoice(itemChoice));
96+
} else if(choice instanceof MCRecipeChoice.MaterialChoice) {
97+
List<Material> materialChoice = new ArrayList<>();
98+
for(MCMaterial material : ((MaterialChoice) choice).getMaterials()) {
99+
materialChoice.add((Material) material.getHandle());
100+
}
101+
getHandle().setInputChoice(new RecipeChoice.MaterialChoice(materialChoice));
80102
}
81-
getHandle().setInputChoice(new RecipeChoice.MaterialChoice(concrete));
82103
}
83104

84105
@Override

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCFurnaceRecipe.java

Lines changed: 0 additions & 102 deletions
This file was deleted.

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCMerchantRecipe.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
public class BukkitMCMerchantRecipe extends BukkitMCRecipe implements MCMerchantRecipe {
1313

14-
private MerchantRecipe handle;
14+
private final MerchantRecipe handle;
15+
1516
public BukkitMCMerchantRecipe(MerchantRecipe recipe) {
1617
super(recipe);
1718
handle = recipe;
@@ -29,7 +30,7 @@ public MerchantRecipe getHandle() {
2930

3031
@Override
3132
public boolean equals(Object obj) {
32-
return getHandle().equals(obj);
33+
return obj instanceof BukkitMCMerchantRecipe && getHandle().equals(((BukkitMCMerchantRecipe) obj).getHandle());
3334
}
3435

3536
@Override

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCRecipe.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public abstract class BukkitMCRecipe implements MCRecipe {
88

9-
private Recipe r;
9+
private final Recipe r;
1010

1111
protected BukkitMCRecipe(Recipe rec) {
1212
r = rec;
@@ -24,7 +24,7 @@ public MCItemStack getResult() {
2424

2525
@Override
2626
public boolean equals(Object obj) {
27-
return r.equals(obj);
27+
return obj instanceof BukkitMCRecipe && r.equals(((BukkitMCRecipe) obj).r);
2828
}
2929

3030
@Override

0 commit comments

Comments
 (0)