1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
package gregtech.api.recipe.check;
import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import gregtech.api.util.GT_Recipe;
/**
* Wrapper class to get result of recipe search for recipemap. Note that this only validates recipe input and voltage,
* and does not involve in actual check in the machine such as output space or special value.
*/
public class FindRecipeResult {
@Nonnull
private final State state;
@Nullable
private final GT_Recipe recipe;
private FindRecipeResult(@Nonnull State state, @Nullable GT_Recipe recipe) {
this.state = state;
this.recipe = recipe;
}
@Nonnull
public State getState() {
return state;
}
public boolean isSuccessful() {
return state.success;
}
/**
* If you already checked {@link #isSuccessful()}, you can use {@link #getRecipeNonNull()} instead.
*/
@Nullable
public GT_Recipe getRecipe() {
return recipe;
}
/**
* You should use this ONLY WHEN state == FOUND or INSUFFICIENT_VOLTAGE.
*/
@Nonnull
public GT_Recipe getRecipeNonNull() {
return Objects.requireNonNull(recipe);
}
/**
* Successfully found recipe.
*/
public static FindRecipeResult ofSuccess(@Nonnull GT_Recipe recipe) {
return new FindRecipeResult(State.FOUND, Objects.requireNonNull(recipe));
}
/**
* Recipe was found, but voltage is not sufficient to run.
*/
public static FindRecipeResult ofInsufficientVoltage(@Nonnull GT_Recipe recipe) {
return new FindRecipeResult(State.INSUFFICIENT_VOLTAGE, Objects.requireNonNull(recipe));
}
/**
* No recipe found.
*/
public static final FindRecipeResult NOT_FOUND = new FindRecipeResult(State.NOT_FOUND, null);
/**
* For Microwave.
*/
public static final FindRecipeResult EXPLODE = new FindRecipeResult(State.EXPLODE, null);
/**
* For Microwave.
*/
public static final FindRecipeResult ON_FIRE = new FindRecipeResult(State.ON_FIRE, null);
public enum State {
/**
* Successfully found recipe.
*/
FOUND(true),
/**
* Recipe was found, but voltage is not sufficient to run.
*/
INSUFFICIENT_VOLTAGE(false),
/**
* No recipe found.
*/
NOT_FOUND(false),
/**
* For Microwave.
*/
EXPLODE(false),
/**
* For Microwave.
*/
ON_FIRE(false);
private final boolean success;
State(boolean success) {
this.success = success;
}
}
}
|