Skip to content

Commit 58a6ea2

Browse files
committed
Initial pass at reworking chemical ingredients to be extensible and closer in concept to fluid and item ingredients
1 parent 13fc4aa commit 58a6ea2

File tree

187 files changed

+4009
-1509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+4009
-1509
lines changed

build.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,17 +376,15 @@ runs {
376376
}
377377
}
378378

379-
void exclusiveRepo(RepositoryHandler handler, String url, String... groups) {
379+
static void exclusiveRepo(RepositoryHandler handler, String url, String... groups) {
380380
exclusiveRepo(handler, url, filter -> {
381381
for (def group : groups) {
382382
filter.includeGroup(group)
383383
}
384384
})
385385
}
386386

387-
//Note: This cannot be static so that fg.repository can be properly accessed
388-
@SuppressWarnings('GrMethodMayBeStatic')
389-
void exclusiveRepo(RepositoryHandler handler, String url, Consumer<InclusiveRepositoryContentDescriptor> filterSetup) {
387+
static void exclusiveRepo(RepositoryHandler handler, String url, Consumer<InclusiveRepositoryContentDescriptor> filterSetup) {
390388
handler.exclusiveContent {
391389
it.forRepositories(handler.maven {
392390
setUrl(url)

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ minecraft_version=1.20.6
88
previous_minecraft_version=1.20.1
99
previous_minor_minecraft_version=1.20.4
1010
loader_version_range=[2,)
11-
forge_version=20.6.84-beta-fork-feature-fluid-ingredients
11+
forge_version=20.6.86-beta-fork-feature-fluid-ingredients
1212
mod_version=10.5.20
1313
#This determines the minimum version of forge required to use Mekanism
1414
# Only bump it whenever we need access to a feature in forge that is not available in earlier versions

src/api/java/mekanism/api/IMekanismAccess.java

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111
import mekanism.api.chemical.slurry.SlurryStack;
1212
import mekanism.api.integration.emi.IMekanismEmiHelper;
1313
import mekanism.api.integration.jei.IMekanismJEIHelper;
14-
import mekanism.api.recipes.ingredients.ChemicalStackIngredient.GasStackIngredient;
15-
import mekanism.api.recipes.ingredients.ChemicalStackIngredient.InfusionStackIngredient;
16-
import mekanism.api.recipes.ingredients.ChemicalStackIngredient.PigmentStackIngredient;
17-
import mekanism.api.recipes.ingredients.ChemicalStackIngredient.SlurryStackIngredient;
14+
import mekanism.api.recipes.ingredients.GasStackIngredient;
15+
import mekanism.api.recipes.ingredients.InfusionStackIngredient;
16+
import mekanism.api.recipes.ingredients.PigmentStackIngredient;
17+
import mekanism.api.recipes.ingredients.SlurryStackIngredient;
18+
import mekanism.api.recipes.ingredients.chemical.IGasIngredient;
19+
import mekanism.api.recipes.ingredients.chemical.IInfusionIngredient;
20+
import mekanism.api.recipes.ingredients.chemical.IPigmentIngredient;
21+
import mekanism.api.recipes.ingredients.chemical.ISlurryIngredient;
22+
import mekanism.api.recipes.ingredients.creator.IChemicalIngredientCreator;
1823
import mekanism.api.recipes.ingredients.creator.IChemicalStackIngredientCreator;
1924
import mekanism.api.recipes.ingredients.creator.IFluidStackIngredientCreator;
2025
import mekanism.api.recipes.ingredients.creator.IItemStackIngredientCreator;
@@ -42,7 +47,6 @@ public interface IMekanismAccess {
4247
* Gets a helper to interact with some of Mekanism's EMI integration internals. This should only be called if EMI is loaded.
4348
*
4449
* @throws IllegalStateException if EMI is not loaded.
45-
*
4650
* @since 10.5.10
4751
*/
4852
IMekanismEmiHelper emiHelper();
@@ -66,26 +70,58 @@ public interface IMekanismAccess {
6670
*
6771
* @apiNote Use {@link mekanism.api.recipes.ingredients.creator.IngredientCreatorAccess#gas()} instead.
6872
*/
69-
IChemicalStackIngredientCreator<Gas, GasStack, GasStackIngredient> gasStackIngredientCreator();
73+
IChemicalStackIngredientCreator<Gas, GasStack, IGasIngredient, GasStackIngredient> gasStackIngredientCreator();
74+
75+
/**
76+
* Gets the gas ingredient creator.
77+
*
78+
* @apiNote Use {@link mekanism.api.recipes.ingredients.creator.IngredientCreatorAccess#basicGas()} instead.
79+
* @since 10.6.0
80+
*/
81+
IChemicalIngredientCreator<Gas, IGasIngredient> gasIngredientCreator();
7082

7183
/**
7284
* Gets the infusion stack ingredient creator.
7385
*
7486
* @apiNote Use {@link mekanism.api.recipes.ingredients.creator.IngredientCreatorAccess#infusion()} instead.
7587
*/
76-
IChemicalStackIngredientCreator<InfuseType, InfusionStack, InfusionStackIngredient> infusionStackIngredientCreator();
88+
IChemicalStackIngredientCreator<InfuseType, InfusionStack, IInfusionIngredient, InfusionStackIngredient> infusionStackIngredientCreator();
89+
90+
/**
91+
* Gets the infusion ingredient creator.
92+
*
93+
* @apiNote Use {@link mekanism.api.recipes.ingredients.creator.IngredientCreatorAccess#basicInfusion()} instead.
94+
* @since 10.6.0
95+
*/
96+
IChemicalIngredientCreator<InfuseType, IInfusionIngredient> infusionIngredientCreator();
7797

7898
/**
7999
* Gets the pigment stack ingredient creator.
80100
*
81101
* @apiNote Use {@link mekanism.api.recipes.ingredients.creator.IngredientCreatorAccess#pigment()} instead.
82102
*/
83-
IChemicalStackIngredientCreator<Pigment, PigmentStack, PigmentStackIngredient> pigmentStackIngredientCreator();
103+
IChemicalStackIngredientCreator<Pigment, PigmentStack, IPigmentIngredient, PigmentStackIngredient> pigmentStackIngredientCreator();
104+
105+
/**
106+
* Gets the pigment ingredient creator.
107+
*
108+
* @apiNote Use {@link mekanism.api.recipes.ingredients.creator.IngredientCreatorAccess#basicPigment()} instead.
109+
* @since 10.6.0
110+
*/
111+
IChemicalIngredientCreator<Pigment, IPigmentIngredient> pigmentIngredientCreator();
84112

85113
/**
86114
* Gets the slurry stack ingredient creator.
87115
*
88116
* @apiNote Use {@link mekanism.api.recipes.ingredients.creator.IngredientCreatorAccess#slurry()} instead.
89117
*/
90-
IChemicalStackIngredientCreator<Slurry, SlurryStack, SlurryStackIngredient> slurryStackIngredientCreator();
118+
IChemicalStackIngredientCreator<Slurry, SlurryStack, ISlurryIngredient, SlurryStackIngredient> slurryStackIngredientCreator();
119+
120+
/**
121+
* Gets the slurry ingredient creator.
122+
*
123+
* @apiNote Use {@link mekanism.api.recipes.ingredients.creator.IngredientCreatorAccess#basicSlurry()} instead.
124+
* @since 10.6.0
125+
*/
126+
IChemicalIngredientCreator<Slurry, ISlurryIngredient> slurryIngredientCreator();
91127
}

src/api/java/mekanism/api/JsonConstants.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ private JsonConstants() {
1010

1111
//Ingredients
1212
public static final String INGREDIENT = "ingredient";
13+
/**
14+
* @since 10.6.0
15+
*/
16+
public static final String INGREDIENTS = "ingredients";
1317
public static final String AMOUNT = "amount";
18+
/**
19+
* @since 10.6.0
20+
*/
21+
public static final String CHILDREN = "children";
1422
public static final String COUNT = "count";
1523
public static final String TAG = "tag";
1624
public static final String NBT = "nbt";
@@ -21,6 +29,10 @@ private JsonConstants() {
2129
public static final String SLURRY = "slurry";
2230
public static final String FLUID = "fluid";
2331
public static final String BASE = "base";
32+
/**
33+
* @since 10.6.0
34+
*/
35+
public static final String SUBTRACTED = "subtracted";
2436

2537
//Recipes
2638
public static final String TYPE = "type";

src/api/java/mekanism/api/MekanismAPI.java

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import mekanism.api.chemical.slurry.Slurry;
1313
import mekanism.api.chemical.slurry.SlurryBuilder;
1414
import mekanism.api.gear.ModuleData;
15+
import mekanism.api.recipes.ingredients.chemical.IGasIngredient;
16+
import mekanism.api.recipes.ingredients.chemical.IInfusionIngredient;
17+
import mekanism.api.recipes.ingredients.chemical.IPigmentIngredient;
18+
import mekanism.api.recipes.ingredients.chemical.ISlurryIngredient;
1519
import mekanism.api.robit.RobitSkin;
1620
import net.minecraft.core.Registry;
1721
import net.minecraft.resources.ResourceKey;
@@ -58,35 +62,63 @@ private static <T> ResourceKey<Registry<MapCodec<? extends T>>> codecRegistryKey
5862
/**
5963
* Gets the {@link ResourceKey} representing the name of the Registry for {@link Gas gases}.
6064
*
61-
* @apiNote When registering {@link Gas gases} using {@link DeferredRegister <Gas>}, use this field to get access to the {@link ResourceKey}.
65+
* @apiNote When registering {@link Gas gases} using {@link DeferredRegister}, use this field to get access to the {@link ResourceKey}.
6266
* @since 10.4.0
6367
*/
6468
public static final ResourceKey<Registry<Gas>> GAS_REGISTRY_NAME = registryKey(Gas.class, "gas");
69+
/**
70+
* Gets the {@link ResourceKey} representing the name of the Registry for {@link IGasIngredient} ingredient type serializers.
71+
*
72+
* @apiNote When registering gas ingredient types using {@link DeferredRegister}, use this field to get access to the {@link ResourceKey}.
73+
* @since 10.6.0
74+
*/
75+
public static final ResourceKey<Registry<MapCodec<? extends IGasIngredient>>> GAS_INGREDIENT_TYPE_REGISTRY_NAME = codecRegistryKey(IGasIngredient.class, "gas_ingredient_type");
6576
/**
6677
* Gets the {@link ResourceKey} representing the name of the Registry for {@link InfuseType infuse types}.
6778
*
68-
* @apiNote When registering {@link InfuseType infuse types} using {@link DeferredRegister <InfuseType>}, use this field to get access to the {@link ResourceKey}.
79+
* @apiNote When registering {@link InfuseType infuse types} using {@link DeferredRegister}, use this field to get access to the {@link ResourceKey}.
6980
* @since 10.4.0
7081
*/
7182
public static final ResourceKey<Registry<InfuseType>> INFUSE_TYPE_REGISTRY_NAME = registryKey(InfuseType.class, "infuse_type");
83+
/**
84+
* Gets the {@link ResourceKey} representing the name of the Registry for {@link IInfusionIngredient} ingredient type serializers.
85+
*
86+
* @apiNote When registering infusion ingredient types using {@link DeferredRegister}, use this field to get access to the {@link ResourceKey}.
87+
* @since 10.6.0
88+
*/
89+
public static final ResourceKey<Registry<MapCodec<? extends IInfusionIngredient>>> INFUSION_INGREDIENT_TYPE_REGISTRY_NAME = codecRegistryKey(IInfusionIngredient.class, "infusion_ingredient_type");
7290
/**
7391
* Gets the {@link ResourceKey} representing the name of the Registry for {@link Pigment pigments}.
7492
*
75-
* @apiNote When registering {@link Pigment pigments} using {@link DeferredRegister <Pigment>}, use this field to get access to the {@link ResourceKey}.
93+
* @apiNote When registering {@link Pigment pigments} using {@link DeferredRegister}, use this field to get access to the {@link ResourceKey}.
7694
* @since 10.4.0
7795
*/
7896
public static final ResourceKey<Registry<Pigment>> PIGMENT_REGISTRY_NAME = registryKey(Pigment.class, "pigment");
97+
/**
98+
* Gets the {@link ResourceKey} representing the name of the Registry for {@link IPigmentIngredient} ingredient type serializers.
99+
*
100+
* @apiNote When registering pigment ingredient types using {@link DeferredRegister}, use this field to get access to the {@link ResourceKey}.
101+
* @since 10.6.0
102+
*/
103+
public static final ResourceKey<Registry<MapCodec<? extends IPigmentIngredient>>> PIGMENT_INGREDIENT_TYPE_REGISTRY_NAME = codecRegistryKey(IPigmentIngredient.class, "pigment_ingredient_type");
79104
/**
80105
* Gets the {@link ResourceKey} representing the name of the Registry for {@link Slurry sluries}.
81106
*
82-
* @apiNote When registering {@link Slurry sluries} using {@link DeferredRegister <Slurry>}, use this field to get access to the {@link ResourceKey}.
107+
* @apiNote When registering {@link Slurry sluries} using {@link DeferredRegister}, use this field to get access to the {@link ResourceKey}.
83108
* @since 10.4.0
84109
*/
85110
public static final ResourceKey<Registry<Slurry>> SLURRY_REGISTRY_NAME = registryKey(Slurry.class, "slurry");
111+
/**
112+
* Gets the {@link ResourceKey} representing the name of the Registry for {@link ISlurryIngredient} ingredient type serializers.
113+
*
114+
* @apiNote When registering slurry ingredient types using {@link DeferredRegister}, use this field to get access to the {@link ResourceKey}.
115+
* @since 10.6.0
116+
*/
117+
public static final ResourceKey<Registry<MapCodec<? extends ISlurryIngredient>>> SLURRY_INGREDIENT_TYPE_REGISTRY_NAME = codecRegistryKey(ISlurryIngredient.class, "slurry_ingredient_type");
86118
/**
87119
* Gets the {@link ResourceKey} representing the name of the Registry for {@link ModuleData modules}.
88120
*
89-
* @apiNote When registering {@link ModuleData modules} using {@link DeferredRegister <ModuleData>}, use this field to get access to the {@link ResourceKey}.
121+
* @apiNote When registering {@link ModuleData modules} using {@link DeferredRegister}, use this field to get access to the {@link ResourceKey}.
90122
* @since 10.4.0
91123
*/
92124
@SuppressWarnings({"rawtypes", "unchecked"})
@@ -100,8 +132,7 @@ private static <T> ResourceKey<Registry<MapCodec<? extends T>>> codecRegistryKey
100132
/**
101133
* Gets the {@link ResourceKey} representing the name of the Registry for {@link RobitSkin robit skin} serializers.
102134
*
103-
* @apiNote When registering {@link RobitSkin robit skin} serializers using {@link DeferredRegister DeferredRegister< Codec<? extends RobitSkin>>}, use this field to
104-
* get access to the {@link ResourceKey}.
135+
* @apiNote When registering {@link RobitSkin robit skin} serializers using {@link DeferredRegister}, use this field to get access to the {@link ResourceKey}.
105136
* @since 10.4.0
106137
*/
107138
public static final ResourceKey<Registry<MapCodec<? extends RobitSkin>>> ROBIT_SKIN_SERIALIZER_REGISTRY_NAME = codecRegistryKey(RobitSkin.class, "robit_skin_serializer");
@@ -116,6 +147,15 @@ private static <T> ResourceKey<Registry<MapCodec<? extends T>>> codecRegistryKey
116147
.defaultKey(rl("empty"))
117148
.sync(true)
118149
.create();
150+
/**
151+
* Gets the Registry for {@link IGasIngredient} type serializers.
152+
*
153+
* @see #GAS_INGREDIENT_TYPE_REGISTRY_NAME
154+
* @since 10.6.0
155+
*/
156+
public static final Registry<MapCodec<? extends IGasIngredient>> GAS_INGREDIENT_TYPES = new RegistryBuilder<>(GAS_INGREDIENT_TYPE_REGISTRY_NAME)
157+
.sync(true)
158+
.create();
119159
/**
120160
* Gets the Registry for {@link InfuseType}.
121161
*
@@ -126,6 +166,15 @@ private static <T> ResourceKey<Registry<MapCodec<? extends T>>> codecRegistryKey
126166
.defaultKey(rl("empty"))
127167
.sync(true)
128168
.create();
169+
/**
170+
* Gets the Registry for {@link IInfusionIngredient} type serializers.
171+
*
172+
* @see #INFUSION_INGREDIENT_TYPE_REGISTRY_NAME
173+
* @since 10.6.0
174+
*/
175+
public static final Registry<MapCodec<? extends IInfusionIngredient>> INFUSION_INGREDIENT_TYPES = new RegistryBuilder<>(INFUSION_INGREDIENT_TYPE_REGISTRY_NAME)
176+
.sync(true)
177+
.create();
129178
/**
130179
* Gets the Registry for {@link Pigment}.
131180
*
@@ -136,6 +185,15 @@ private static <T> ResourceKey<Registry<MapCodec<? extends T>>> codecRegistryKey
136185
.defaultKey(rl("empty"))
137186
.sync(true)
138187
.create();
188+
/**
189+
* Gets the Registry for {@link IPigmentIngredient} type serializers.
190+
*
191+
* @see #PIGMENT_INGREDIENT_TYPE_REGISTRY_NAME
192+
* @since 10.6.0
193+
*/
194+
public static final Registry<MapCodec<? extends IPigmentIngredient>> PIGMENT_INGREDIENT_TYPES = new RegistryBuilder<>(PIGMENT_INGREDIENT_TYPE_REGISTRY_NAME)
195+
.sync(true)
196+
.create();
139197
/**
140198
* Gets the Registry for {@link Slurry}.
141199
*
@@ -146,6 +204,15 @@ private static <T> ResourceKey<Registry<MapCodec<? extends T>>> codecRegistryKey
146204
.defaultKey(rl("empty"))
147205
.sync(true)
148206
.create();
207+
/**
208+
* Gets the Registry for {@link ISlurryIngredient} type serializers.
209+
*
210+
* @see #SLURRY_INGREDIENT_TYPE_REGISTRY_NAME
211+
* @since 10.6.0
212+
*/
213+
public static final Registry<MapCodec<? extends ISlurryIngredient>> SLURRY_INGREDIENT_TYPES = new RegistryBuilder<>(SLURRY_INGREDIENT_TYPE_REGISTRY_NAME)
214+
.sync(true)
215+
.create();
149216
/**
150217
* Gets the Registry for {@link ModuleData}.
151218
*
@@ -163,6 +230,9 @@ private static <T> ResourceKey<Registry<MapCodec<? extends T>>> codecRegistryKey
163230
*/
164231
public static final Registry<MapCodec<? extends RobitSkin>> ROBIT_SKIN_SERIALIZER_REGISTRY = new RegistryBuilder<>(ROBIT_SKIN_SERIALIZER_REGISTRY_NAME).create();
165232

233+
//TODO - 1.20.5: Docs
234+
public static final ResourceLocation EMPTY_CHEMICAL_NAME = new ResourceLocation(MEKANISM_MODID, "empty");
235+
166236
//TODO: Potentially define these with DeferredHolder for purposes of fully defining them outside of the API
167237
// would have some minor issues with how the empty stacks are declared
168238
/**

src/api/java/mekanism/api/chemical/Chemical.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313
import mekanism.api.annotations.NothingNullByDefault;
1414
import mekanism.api.chemical.attribute.ChemicalAttribute;
1515
import mekanism.api.chemical.attribute.IChemicalAttributeContainer;
16+
import mekanism.api.chemical.gas.Gas;
1617
import mekanism.api.chemical.gas.attribute.GasAttributes.Radiation;
18+
import mekanism.api.chemical.infuse.InfuseType;
19+
import mekanism.api.chemical.pigment.Pigment;
20+
import mekanism.api.chemical.slurry.Slurry;
1721
import mekanism.api.providers.IChemicalProvider;
1822
import mekanism.api.text.TextComponentUtil;
23+
import net.minecraft.core.Holder;
1924
import net.minecraft.core.Registry;
2025
import net.minecraft.network.RegistryFriendlyByteBuf;
2126
import net.minecraft.network.chat.Component;
22-
import net.minecraft.network.codec.ByteBufCodecs;
2327
import net.minecraft.network.codec.StreamCodec;
2428
import net.minecraft.resources.ResourceLocation;
2529
import net.minecraft.tags.TagKey;
@@ -59,10 +63,10 @@ public abstract class Chemical<CHEMICAL extends Chemical<CHEMICAL>> implements I
5963
*/
6064
public static final StreamCodec<RegistryFriendlyByteBuf, Chemical<?>> BOXED_OPTIONAL_STREAM_CODEC = ChemicalType.STREAM_CODEC.<RegistryFriendlyByteBuf>cast()
6165
.dispatch(ChemicalType::getTypeFor, type -> switch (type) {
62-
case GAS -> ByteBufCodecs.registry(MekanismAPI.GAS_REGISTRY_NAME);
63-
case INFUSION -> ByteBufCodecs.registry(MekanismAPI.INFUSE_TYPE_REGISTRY_NAME);
64-
case PIGMENT -> ByteBufCodecs.registry(MekanismAPI.PIGMENT_REGISTRY_NAME);
65-
case SLURRY -> ByteBufCodecs.registry(MekanismAPI.SLURRY_REGISTRY_NAME);
66+
case GAS -> Gas.STREAM_CODEC;
67+
case INFUSION -> InfuseType.STREAM_CODEC;
68+
case PIGMENT -> Pigment.STREAM_CODEC;
69+
case SLURRY -> Slurry.STREAM_CODEC;
6670
});
6771
/**
6872
* StreamCodec to get any kind of chemical (that does not accept the empty type), based on a "chemicalType" field.
@@ -239,7 +243,7 @@ public boolean isHidden() {
239243
* @return {@code true} if the chemical is in the tag, {@code false} otherwise.
240244
*/
241245
public boolean is(TagKey<CHEMICAL> tag) {
242-
return getRegistry().wrapAsHolder((CHEMICAL) this).is(tag);
246+
return getAsHolder().is(tag);
243247
}
244248

245249
/**
@@ -248,7 +252,12 @@ public boolean is(TagKey<CHEMICAL> tag) {
248252
* @return All the tags this chemical is a part of.
249253
*/
250254
public Stream<TagKey<CHEMICAL>> getTags() {
251-
return getRegistry().wrapAsHolder((CHEMICAL) this).tags();
255+
return getAsHolder().tags();
256+
}
257+
258+
//TODO - 1.20.5: Docs
259+
public Holder<CHEMICAL> getAsHolder() {
260+
return getRegistry().wrapAsHolder((CHEMICAL) this);
252261
}
253262

254263
/**

src/api/java/mekanism/api/chemical/ChemicalStack.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ protected static <CHEMICAL extends Chemical<CHEMICAL>> Codec<CHEMICAL> chemicalN
5656
: DataResult.success(chemical));
5757
}
5858

59+
/**
60+
* A standard codec for chemicals.
61+
*
62+
* @since 10.6.0
63+
*/
64+
protected static <CHEMICAL extends Chemical<CHEMICAL>> Codec<Holder<CHEMICAL>> chemicalNonEmptyHolderCodec(Registry<CHEMICAL> registry) {
65+
return registry.holderByNameCodec().validate(chemical -> chemical.value().isEmptyType() ? DataResult.error(() -> "Chemical must not be mekanism:empty")
66+
: DataResult.success(chemical));
67+
}
68+
5969
/**
6070
* A standard codec for chemical stacks that does not accept empty stacks.
6171
*
@@ -278,7 +288,7 @@ public final CHEMICAL getChemical() {
278288
* @since 10.6.0
279289
*/
280290
public Holder<CHEMICAL> getChemicalHolder() {
281-
return getRegistry().wrapAsHolder(getChemical());
291+
return getChemical().getAsHolder();
282292
}
283293

284294
/**

0 commit comments

Comments
 (0)