1212import net .minecraft .util .valueproviders .UniformInt ;
1313import net .minecraftforge .fluids .FluidStack ;
1414
15+ import com .google .errorprone .annotations .DoNotCall ;
1516import com .google .gson .*;
1617import com .mojang .serialization .Codec ;
1718import com .mojang .serialization .JsonOps ;
1819import lombok .Getter ;
1920import lombok .Setter ;
2021import org .jetbrains .annotations .NotNull ;
2122
23+ /**
24+ * Allows a {@link FluidIngredient} to be created with a ranged {@code amount}, which will be randomly rolled upon
25+ * recipe completion.
26+ * Only valid as a recipe fluid {@code output}.
27+ * Instantiated using {@link IntProviderFluidIngredient#of()}, with a {@link FluidIngredient}
28+ * and either an {@link IntProvider} or {@code int, int} range bounds (inclusive).
29+ * Functions similarly to {@link IntProviderIngredient}.
30+ */
2231public class IntProviderFluidIngredient extends FluidIngredient {
2332
2433 public static final Codec <IntProviderFluidIngredient > CODEC = ExtraCodecs .JSON
2534 .xmap (IntProviderFluidIngredient ::fromJson , IntProviderFluidIngredient ::toJson );
2635
2736 @ Getter
2837 private final IntProvider countProvider ;
38+ /**
39+ * The last result of {@link IntProviderFluidIngredient#getSampledCount()}. -1 if not rolled.
40+ */
2941 @ Setter
3042 protected int sampledCount = -1 ;
43+ /**
44+ * The {@link FluidIngredient} to have a ranged amount.
45+ */
3146 @ Getter
3247 private final FluidIngredient inner ;
3348 @ Setter
@@ -46,11 +61,23 @@ public IntProviderFluidIngredient copy() {
4661 return ipfi ;
4762 }
4863
64+ /**
65+ * An {@link IntProviderFluidIngredient} does not have an amount.
66+ * You probably want either {@link IntProviderFluidIngredient#getStacks()} or
67+ * {@link IntProviderFluidIngredient#getMaxSizeStack()}.
68+ */
69+ @ DoNotCall
4970 @ Override
5071 public int getAmount () {
5172 return -1 ;
5273 }
5374
75+ /**
76+ * Gets a usable {@link FluidStack FluidStack[]} from this {@link IntProviderFluidIngredient}.
77+ * If this ingredient has not yet had its {@link IntProviderFluidIngredient#sampledCount} rolled, rolls it.
78+ *
79+ * @return a {@link FluidStack FluidStack[]} with amount {@link IntProviderFluidIngredient#sampledCount}
80+ */
5481 @ Override
5582 public FluidStack [] getStacks () {
5683 if (fluidStacks == null ) {
@@ -68,12 +95,40 @@ public FluidStack[] getStacks() {
6895 return fluidStacks ;
6996 }
7097
98+ /**
99+ * Gets a {@link FluidStack} containing the maximum possible output from this {@link IntProviderFluidIngredient}.
100+ * Mainly used for things like Recipe provider simulations to see if there is enough tank space to handle
101+ * the recipe output.
102+ *
103+ * @return a {@link FluidStack} with amount {@link IntProvider#getMaxValue()}
104+ */
71105 public @ NotNull FluidStack getMaxSizeStack () {
72106 FluidStack [] in = inner .getStacks ();
73107 if (in .length == 0 ) return FluidStack .EMPTY ;
74108 return new FluidStack (in [0 ], countProvider .getMaxValue ());
75109 }
76110
111+ /**
112+ * If this ingredient has not yet had its {@link IntProviderFluidIngredient#sampledCount} rolled, rolls it and
113+ * returns the roll.
114+ * If it has, returns the existing roll.
115+ * Passthrough method, invokes {@link IntProviderFluidIngredient#getSampledCount(RandomSource)} using the threadsafe
116+ * {@link GTValues#RNG}.
117+ *
118+ * @return the amount rolled
119+ */
120+ public int getSampledCount () {
121+ return getSampledCount (GTValues .RNG );
122+ }
123+
124+ /**
125+ * If this ingredient has not yet had its {@link IntProviderFluidIngredient#sampledCount} rolled, rolls it and
126+ * returns the roll.
127+ * If it has, returns the existing roll.
128+ *
129+ * @param random {@link RandomSource}, must be threadsafe, usually called using {@link GTValues#RNG}.
130+ * @return the amount rolled
131+ */
77132 public int getSampledCount (@ NotNull RandomSource random ) {
78133 if (sampledCount == -1 ) {
79134 sampledCount = countProvider .sample (random );
@@ -86,6 +141,10 @@ public boolean isEmpty() {
86141 return inner .isEmpty ();
87142 }
88143
144+ /**
145+ * @param inner {@link FluidIngredient}
146+ * @param provider usually as {@link UniformInt#of(int, int)}
147+ */
89148 public static IntProviderFluidIngredient of (FluidIngredient inner , IntProvider provider ) {
90149 return new IntProviderFluidIngredient (inner , provider );
91150 }
@@ -94,6 +153,13 @@ public static IntProviderFluidIngredient of(FluidStack inner, int min, int max)
94153 return IntProviderFluidIngredient .of (FluidIngredient .of (inner ), UniformInt .of (min , max ));
95154 }
96155
156+ /**
157+ * Properties:
158+ * <ul>
159+ * <li>{@code count_provider}</li>
160+ * <li>{@code inner}</li>
161+ * </ul>
162+ */
97163 @ Override
98164 public @ NotNull JsonElement toJson () {
99165 JsonObject json = new JsonObject ();
@@ -103,6 +169,13 @@ public static IntProviderFluidIngredient of(FluidStack inner, int min, int max)
103169 return json ;
104170 }
105171
172+ /**
173+ * @param json containing
174+ * <ul>
175+ * <li>{@code count_provider}</li>
176+ * <li>{@code inner}</li>
177+ * </ul>
178+ */
106179 public static IntProviderFluidIngredient fromJson (JsonElement json ) {
107180 if (json == null || json .isJsonNull ()) {
108181 throw new JsonSyntaxException ("Fluid ingredient cannot be null" );
0 commit comments