2
2
3
3
import net .minecraft .resources .ResourceLocation ;
4
4
5
+ import com .almostreliable .unified .AlmostUnifiedCommon ;
5
6
import com .almostreliable .unified .api .unification .recipe .RecipeData ;
6
7
import com .almostreliable .unified .utils .JsonCompare ;
7
8
17
18
import java .util .Set ;
18
19
import java .util .stream .Collectors ;
19
20
20
- public class RecipeLink implements RecipeData {
21
+ public final class RecipeLink implements RecipeData {
21
22
/**
22
23
* This cache is an optimization to avoid creating many ResourceLocations for just a few different types.
23
24
* Having fewer ResourceLocation instances can greatly speed up equality checking when these are used as map keys.
@@ -30,15 +31,30 @@ public class RecipeLink implements RecipeData {
30
31
@ Nullable private DuplicateLink duplicateLink ;
31
32
@ Nullable private JsonObject unifiedRecipe ;
32
33
33
- public RecipeLink (ResourceLocation id , JsonObject originalRecipe ) {
34
+ private RecipeLink (ResourceLocation id , JsonObject originalRecipe , ResourceLocation type ) {
34
35
this .id = id ;
35
36
this .originalRecipe = originalRecipe ;
37
+ this .type = type ;
38
+ }
39
+
40
+ @ Nullable
41
+ public static RecipeLink of (ResourceLocation id , JsonObject originalRecipe ) {
42
+ try {
43
+ ResourceLocation type = ResourceLocation .parse (originalRecipe .get ("type" ).getAsString ());
44
+ return new RecipeLink (id , originalRecipe , type );
45
+ } catch (Exception e ) {
46
+ AlmostUnifiedCommon .LOGGER .warn ("Could not detect recipe type for recipe '{}', skipping." , id );
47
+ return null ;
48
+ }
49
+ }
36
50
51
+ public static RecipeLink ofOrThrow (ResourceLocation id , JsonObject originalRecipe ) {
37
52
try {
38
53
String typeString = originalRecipe .get ("type" ).getAsString ();
39
- this .type = PARSED_TYPE_CACHE .computeIfAbsent (typeString , ResourceLocation ::parse );
54
+ ResourceLocation type = PARSED_TYPE_CACHE .computeIfAbsent (typeString , ResourceLocation ::parse );
55
+ return new RecipeLink (id , originalRecipe , type );
40
56
} catch (Exception e ) {
41
- throw new IllegalArgumentException ("could not detect recipe type" );
57
+ throw new IllegalArgumentException ("could not detect recipe type for recipe " + id );
42
58
}
43
59
}
44
60
0 commit comments