Skip to content

Commit d792b30

Browse files
Add wiki and javadocs to IntProviderIngredient and IntProviderFluidIngredient (#3539)
1 parent e5cac4e commit d792b30

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed

docs/content/Modpacks/Other-Topics/Adding-and-Removing-Recipes.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ ServerEvents.recipes(event => {
9898
- `.itemOutput()`
9999
- `.itemOutputs()`
100100
- `.chancedOutput()`
101+
- `.outputItemsRanged()`
101102
- Fluids:
102103
- `.outputFluids()`
103104
- `.chancedFluidOutput()`
105+
- `.outputFluidsRanged()`
104106
- Energy:
105107
- `.inputEU()`:
106108
Makes the recipe consume a lump sum of EU to start the recipe. Most often seen in fusion reactor recipes.
@@ -109,6 +111,26 @@ ServerEvents.recipes(event => {
109111
- `.EUt()`:
110112
Takes a numerical value representing an EU amount. Positive values will make the recipe consume energy per tick,
111113
negative ones will make it generate energy per tick.
114+
- Chanced Ingredients:
115+
- Ingredients that are not consumed/produced on every run of a recipe. Can be expressed as either a fraction, or as an
116+
integer chance out of 10,000.
117+
- Assigning an Input ingredient with a Chance of `0` causes that ingredient to be flagged as `Non-Consumed` in EMI.
118+
This can also be done more easily using `.notConsumable()`.
119+
- Recipes with chanced ingredients can also have a Chance Logic designated for each of their input/output sets, using
120+
one or more of the functions `.chancedItemInputLogic()`, `.chancedFluidInputLogic()`, `.chancedTickInputLogic()`,
121+
`.chancedItemOutputLogic()`, `.chancedFluidOutputLogic()`, `.chancedTickOutputLogic()`
122+
- Valid options for chanced logic are:
123+
- `or` - (default) Any item/fluid which succeeds on its chance roll is produced/consumed.
124+
- `and` - If _all_ items/fluids succeed on their chance roll, all are produced/consumed together. Otherwise, none are.
125+
- `xor` - Guarantees that exactly one of the chanced items/fluids will be produced/consumed on every run.
126+
Behavior was changed in 7.0.0.
127+
- `first` - Makes a chance roll for each item/fluid, in order of registration. Only the first item which succeeds
128+
on its roll is returned. Prior to 7.0.0, this was the behavior of `xor` logic.
129+
- Ranged Outputs:
130+
- Item or Fluid outputs that will produce a random amount within a `min, max` range (inclusive).
131+
- Circuits
132+
- Many GT recipes use a `Programmed Circuit` item with a Configuration value of `1-32` as a `Non-Consumed` input,
133+
to distinguish them from other recipes in the same machine with similar ingredients. `.circuit()` adds one to a recipe.
112134
- More granular functionality:
113135
- `.perTick()`:
114136
Using this will enable you to control whether a recipe input/output is consumed/produced per tick the recipe is

src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/IntProviderFluidIngredient.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,37 @@
1212
import net.minecraft.util.valueproviders.UniformInt;
1313
import net.minecraftforge.fluids.FluidStack;
1414

15+
import com.google.errorprone.annotations.DoNotCall;
1516
import com.google.gson.*;
1617
import com.mojang.serialization.Codec;
1718
import com.mojang.serialization.JsonOps;
1819
import lombok.Getter;
1920
import lombok.Setter;
2021
import 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+
*/
2231
public 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");

src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/IntProviderIngredient.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,29 @@
2626

2727
import java.util.stream.Stream;
2828

29+
/**
30+
* Allows an {@link Ingredient} to be created with a ranged {@code count}, which will be randomly rolled upon recipe
31+
* completion.
32+
* Only valid as a recipe item {@code output}.
33+
* Instantiated using {@link IntProviderIngredient#of()}, with a {@link Ingredient} or {@link ItemStack},
34+
* and an {@link IntProvider}.
35+
* Functions similarly to {@link IntProviderFluidIngredient}.
36+
*/
2937
public class IntProviderIngredient extends Ingredient {
3038

3139
public static final ResourceLocation TYPE = GTCEu.id("int_provider");
3240
public static final ItemStack[] EMPTY_STACK_ARRAY = new ItemStack[0];
3341

3442
@Getter
3543
protected final IntProvider countProvider;
44+
/**
45+
* The last result of {@link IntProviderIngredient#getSampledCount(RandomSource)}. -1 if not rolled.
46+
*/
3647
@Setter
3748
protected int sampledCount = -1;
49+
/**
50+
* The {@link Ingredient} to have a ranged amount.
51+
*/
3852
@Getter
3953
protected final Ingredient inner;
4054
@Setter
@@ -46,12 +60,20 @@ protected IntProviderIngredient(Ingredient inner, IntProvider countProvider) {
4660
this.countProvider = countProvider;
4761
}
4862

63+
/**
64+
* @param inner {@link Ingredient}
65+
* @param countProvider usually as {@link net.minecraft.util.valueproviders.UniformInt#of(int, int)}
66+
*/
4967
public static IntProviderIngredient of(Ingredient inner, IntProvider countProvider) {
5068
Preconditions.checkArgument(countProvider.getMinValue() >= 0,
5169
"IntProviderIngredient must have a min value of at least 0.");
5270
return new IntProviderIngredient(inner, countProvider);
5371
}
5472

73+
/**
74+
* @param stack {@link ItemStack}
75+
* @param countProvider usually as {@link net.minecraft.util.valueproviders.UniformInt#of(int, int)}
76+
*/
5577
public static IntProviderIngredient of(ItemStack stack, IntProvider countProvider) {
5678
Ingredient inner = stack.hasTag() ? StrictNBTIngredient.of(stack) : Ingredient.of(stack);
5779
return of(inner, countProvider);
@@ -62,6 +84,12 @@ public boolean test(@Nullable ItemStack stack) {
6284
return inner.test(stack);
6385
}
6486

87+
/**
88+
* Gets a usable {@link ItemStack ItemStack[]} from this {@link IntProviderIngredient}.
89+
* If this ingredient has not yet had its {@link IntProviderIngredient#sampledCount} rolled, rolls it.
90+
*
91+
* @return a {@link ItemStack ItemStack[]} with count {@link IntProviderIngredient#sampledCount}
92+
*/
6593
@Override
6694
public ItemStack @NotNull [] getItems() {
6795
if (itemStacks == null) {
@@ -78,11 +106,26 @@ public boolean test(@Nullable ItemStack stack) {
78106
return itemStacks;
79107
}
80108

109+
/**
110+
* Gets a {@link ItemStack} containing the maximum possible output from this {@link IntProviderIngredient}.
111+
* Mainly used for things like Recipe provider simulations to see if there is enough inventory space to handle
112+
* the recipe output.
113+
*
114+
* @return a {@link ItemStack} with count {@link IntProvider#getMaxValue()}
115+
*/
81116
public @NotNull ItemStack getMaxSizeStack() {
82117
if (inner.getItems().length == 0) return ItemStack.EMPTY;
83118
else return inner.getItems()[0].copyWithCount(countProvider.getMaxValue());
84119
}
85120

121+
/**
122+
* If this ingredient has not yet had its {@link IntProviderIngredient#sampledCount} rolled, rolls it and returns
123+
* the roll.
124+
* If it has, returns the existing roll.
125+
*
126+
* @param random {@link RandomSource}, must be threadsafe, usually called using {@link GTValues#RNG}.
127+
* @return the count rolled
128+
*/
86129
public int getSampledCount(@NotNull RandomSource random) {
87130
if (sampledCount == -1) {
88131
sampledCount = countProvider.sample(random);
@@ -106,10 +149,26 @@ public IIngredientSerializer<? extends Ingredient> getSerializer() {
106149
return SERIALIZER;
107150
}
108151

152+
/**
153+
* @param json containing
154+
* <ul>
155+
* <li>{@code type}</li>
156+
* <li>{@code count_provider}</li>
157+
* <li>{@code ingredient}</li>
158+
* </ul>
159+
*/
109160
public static IntProviderIngredient fromJson(JsonObject json) {
110161
return SERIALIZER.parse(json);
111162
}
112163

164+
/**
165+
* Properties:
166+
* <ul>
167+
* <li>{@code type}</li>
168+
* <li>{@code count_provider}</li>
169+
* <li>{@code ingredient}</li>
170+
* </ul>
171+
*/
113172
@Override
114173
public @NotNull JsonElement toJson() {
115174
JsonObject json = new JsonObject();

0 commit comments

Comments
 (0)