8
8
import java .util .List ;
9
9
import java .util .Map ;
10
10
import java .util .Set ;
11
+ import java .util .logging .Level ;
11
12
12
13
import javax .annotation .Nonnull ;
13
14
import javax .annotation .Nullable ;
14
15
15
16
import org .bukkit .Bukkit ;
16
17
import org .bukkit .Material ;
18
+ import org .bukkit .NamespacedKey ;
17
19
import org .bukkit .inventory .FurnaceRecipe ;
18
20
import org .bukkit .inventory .ItemStack ;
19
21
import org .bukkit .inventory .Recipe ;
20
22
23
+ import io .github .thebusybiscuit .sensibletoolbox .SensibleToolboxPlugin ;
21
24
import io .github .thebusybiscuit .sensibletoolbox .api .SensibleToolbox ;
22
25
import io .github .thebusybiscuit .sensibletoolbox .api .items .BaseSTBItem ;
23
26
import io .github .thebusybiscuit .sensibletoolbox .api .items .BaseSTBMachine ;
@@ -36,29 +39,48 @@ private RecipeUtil() {}
36
39
private static final Map <ItemStack , List <ItemStack >> reverseCustomSmelts = new HashMap <>();
37
40
38
41
public static void setupRecipes () {
39
- for (String key : SensibleToolbox .getItemRegistry ().getItemIds ()) {
40
- // add custom workbench recipes
41
- BaseSTBItem item = SensibleToolbox .getItemRegistry ().getItemById (key );
42
- Recipe r = item .getRecipe ();
43
- if (r != null ) {
44
- Bukkit .addRecipe (r );
45
- }
46
- for (Recipe r2 : item .getExtraRecipes ()) {
47
- Bukkit .addRecipe (r2 );
48
- }
42
+ for (String itemId : SensibleToolbox .getItemRegistry ().getItemIds ()) {
43
+ try {
44
+ BaseSTBItem item = SensibleToolbox .getItemRegistry ().getItemById (itemId );
49
45
50
- // add custom furnace recipes
51
- ItemStack stack = item .getSmeltingResult ();
46
+ addWorkbenchRecipes (item );
47
+ addFurnaceRecipes (item );
48
+ addCustomMachineRecipes (item );
52
49
53
- if (stack != null ) {
54
- Bukkit .addRecipe (new FurnaceRecipe (item .getKey (), stack , item .getMaterial (), 0 , 200 ));
55
- recordReverseSmelt (stack , item .toItemStack ());
50
+ } catch (Exception x ) {
51
+ SensibleToolboxPlugin .getInstance ().getLogger ().log (Level .SEVERE , x , () -> "Could not register recipe for item: " + itemId );
56
52
}
53
+ }
54
+ }
57
55
58
- // add custom processing recipes for any machine items
59
- if (item instanceof BaseSTBMachine ) {
60
- ((BaseSTBMachine ) item ).addCustomRecipes (CustomRecipeManager .getManager ());
61
- }
56
+ private static void addWorkbenchRecipes (@ Nonnull BaseSTBItem item ) {
57
+ // add custom workbench recipes
58
+ Recipe mainRecipe = item .getMainRecipe ();
59
+
60
+ if (mainRecipe != null ) {
61
+ Bukkit .addRecipe (mainRecipe );
62
+ }
63
+
64
+ for (Recipe extraRecipe : item .getExtraRecipes ()) {
65
+ Bukkit .addRecipe (extraRecipe );
66
+ }
67
+ }
68
+
69
+ private static void addFurnaceRecipes (@ Nonnull BaseSTBItem item ) {
70
+ // add custom furnace recipes
71
+ ItemStack stack = item .getSmeltingResult ();
72
+
73
+ if (stack != null ) {
74
+ NamespacedKey key = new NamespacedKey (SensibleToolboxPlugin .getInstance (), item .getItemTypeID () + "_furnacerecipe" );
75
+ Bukkit .addRecipe (new FurnaceRecipe (key , stack , item .getMaterial (), 0 , 200 ));
76
+ recordReverseSmelt (stack , item .toItemStack ());
77
+ }
78
+ }
79
+
80
+ private static void addCustomMachineRecipes (@ Nonnull BaseSTBItem item ) {
81
+ // add custom processing recipes for any machine items
82
+ if (item instanceof BaseSTBMachine ) {
83
+ ((BaseSTBMachine ) item ).addCustomRecipes (CustomRecipeManager .getManager ());
62
84
}
63
85
}
64
86
0 commit comments