-
Notifications
You must be signed in to change notification settings - Fork 18
/
RecipesRecipeProvider.java
287 lines (251 loc) · 13.6 KB
/
RecipesRecipeProvider.java
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package knightminer.inspirations.recipes.data;
import knightminer.inspirations.common.data.ConfigEnabledCondition;
import knightminer.inspirations.common.datagen.IInspirationsRecipeBuilder;
import knightminer.inspirations.common.datagen.NBTIngredient;
import knightminer.inspirations.library.InspirationsTags;
import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes;
import knightminer.inspirations.library.recipe.cauldron.CauldronIngredients;
import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents;
import knightminer.inspirations.library.recipe.cauldron.ingredient.ContentMatchIngredient;
import knightminer.inspirations.library.recipe.cauldron.ingredient.ContentTypeIngredient;
import knightminer.inspirations.library.recipe.cauldron.ingredient.FluidCauldronIngredient;
import knightminer.inspirations.library.recipe.cauldron.ingredient.ICauldronIngredient;
import knightminer.inspirations.library.recipe.cauldron.recipe.CauldronRecipeBuilder;
import knightminer.inspirations.library.recipe.cauldron.util.TemperaturePredicate;
import knightminer.inspirations.recipes.InspirationsRecipes;
import knightminer.inspirations.shared.InspirationsShared;
import knightminer.inspirations.utility.InspirationsUtility;
import net.minecraft.advancements.ICriterionInstance;
import net.minecraft.advancements.criterion.ItemPredicate;
import net.minecraft.block.Blocks;
import net.minecraft.data.CustomRecipeBuilder;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.IFinishedRecipe;
import net.minecraft.data.RecipeProvider;
import net.minecraft.data.ShapelessRecipeBuilder;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.DyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.potion.PotionUtils;
import net.minecraft.potion.Potions;
import net.minecraft.tags.ITag;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.IItemProvider;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.crafting.conditions.ICondition;
import net.minecraftforge.common.crafting.conditions.IConditionBuilder;
import net.minecraftforge.registries.IForgeRegistryEntry;
import slimeknights.mantle.registration.object.EnumObject;
import javax.annotation.Nullable;
import java.util.Objects;
import java.util.function.Consumer;
public class RecipesRecipeProvider extends RecipeProvider implements IConditionBuilder, IInspirationsRecipeBuilder {
private Consumer<IFinishedRecipe> consumer;
public RecipesRecipeProvider(DataGenerator generatorIn) {
super(generatorIn);
}
@Override
public String getName() {
return "Inspirations Recipes - Recipes";
}
@Override
public Consumer<IFinishedRecipe> getConsumer() {
return consumer;
}
@Override
public ICondition baseCondition() {
return ConfigEnabledCondition.MODULE_RECIPES;
}
@Override
protected void registerRecipes(Consumer<IFinishedRecipe> consumer) {
this.consumer = consumer;
String folder = "recipes/cauldron/";
ICauldronIngredient waterIngredient = ContentTypeIngredient.of(CauldronContentTypes.WATER);
Consumer<IFinishedRecipe> cauldronRecipes = withCondition(ConfigEnabledCondition.CAULDRON_RECIPES);
// vanilla recipes //
// fill containers
// bucket
CustomRecipeBuilder.customRecipe(InspirationsRecipes.fillBucketSerializer)
.build(withCondition(ConfigEnabledCondition.CAULDRON_RECIPES), resourceName(folder + "fill_bucket"));
// glass bottles
ItemStack waterBottle = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.WATER);
CauldronRecipeBuilder.cauldron(Ingredient.fromItems(Items.GLASS_BOTTLE), waterIngredient)
.minLevels(1)
.addLevels(-1)
.setOutput(waterBottle.copy())
.addCriterion("has_item", hasItem(Items.GLASS_BOTTLE))
.build(cauldronRecipes, resource(folder + "fill_water_bottle"));
// empty container
// bucket
CustomRecipeBuilder.customRecipe(InspirationsRecipes.emptyBucketSerializer)
.build(cauldronRecipes, resourceName(folder + "empty_bucket"));
// water bottle
CauldronRecipeBuilder.cauldron(new NBTIngredient(waterBottle), waterIngredient)
.maxLevels(2)
.addLevels(1)
.setOutput(Items.GLASS_BOTTLE)
.noContainer()
.addCriterion("has_item", hasItem(
ItemPredicate.Builder.create()
.item(Items.POTION)
.nbt(Objects.requireNonNull(waterBottle.getTag()))
.build()))
.build(cauldronRecipes, resource(folder + "empty_water_bottle"));
// TODO: remove dye recipe
// TODO: remove banner pattern
// TODO: clean shulker box
// custom recipes //
// sponge dry cauldron
CauldronRecipeBuilder.cauldron(Ingredient.fromItems(Blocks.SPONGE), waterIngredient)
.minLevels(1)
.setEmpty()
.setOutput(Blocks.WET_SPONGE)
.addCriterion("has_item", hasItem(Blocks.SPONGE))
.build(cauldronRecipes, resource(folder + "dry_cauldron"));
// melt ice if boiling
CauldronRecipeBuilder.cauldron(Ingredient.fromItems(Blocks.ICE), waterIngredient)
.maxLevels(2)
.setFull()
.setOutput(CauldronContentTypes.WATER.get())
.addCriterion("has_item", hasItem(Blocks.ICE))
.build(cauldronRecipes, wrapE(Fluids.WATER, folder, "_from_ice"));
// clean sticky pistons
CauldronRecipeBuilder.cauldron(Ingredient.fromItems(Blocks.STICKY_PISTON), waterIngredient)
.minLevels(1)
.addLevels(-1)
.setOutput(Blocks.PISTON)
.addCriterion("has_item", hasItem(Blocks.STICKY_PISTON))
.build(cauldronRecipes, wrap(Blocks.STICKY_PISTON, folder, "_cleaning"));
// concrete powder
String concreteFolder = folder + "concrete/";
Consumer<IFinishedRecipe> concrete = withCondition(ConfigEnabledCondition.CAULDRON_CONCRETE);
VanillaEnum.CONCRETE_POWDER.forEach((color, powder) -> {
CauldronRecipeBuilder.cauldron(Ingredient.fromItems(powder), waterIngredient)
.minLevels(1)
.addLevels(-1)
.setOutput(VanillaEnum.CONCRETE.get(color))
.addCriterion("has_item", hasItem(powder))
.build(concrete, resource(concreteFolder + color.getString()));
});
// dyes //
// undye and dye vanilla blocks
addColoredRecipes(ItemTags.WOOL, VanillaEnum.WOOL, folder + "wool/", null);
addColoredRecipes(ItemTags.BEDS, VanillaEnum.BED, folder + "bed/", null);
addColoredRecipes(ItemTags.CARPETS, InspirationsShared.VANILLA_CARPETS, folder + "carpet/", null);
// Inspirations blocks
addColoredRecipes(InspirationsTags.Items.CARPETED_TRAPDOORS, InspirationsUtility.carpetedTrapdoors, folder + "carpeted_trapdoor/", ConfigEnabledCondition.CARPETED_TRAPDOOR);
// TODO: armor dyeing
// TODO: banners
// TODO: shulker boxes
// potions //
// TODO: potion bottling
// TODO: tipped arrow recipe (might be same internal logic, just uses a stack of 16)
// fluid recipes //
// beetroot is just water based
addStewRecipe(Items.BEETROOT_SOUP, Ingredient.fromTag(Tags.Items.CROPS_BEETROOT), 6, InspirationsRecipes.beetrootSoup, waterIngredient, folder + "beetroot_soup/");
// mushroom water based
addStewRecipe(Items.MUSHROOM_STEW, Ingredient.fromTag(Tags.Items.MUSHROOMS), 2, InspirationsRecipes.mushroomStew, waterIngredient, folder + "mushroom_stew/");
// potato comes from mushroom
addStewRecipe(InspirationsRecipes.potatoSoupItem, Ingredient.fromItems(Items.BAKED_POTATO), 2, InspirationsRecipes.potatoSoup, FluidCauldronIngredient.of(InspirationsRecipes.mushroomStew), folder + "potato_soup/");
// add in some rabbit for rabbit stew
addStewRecipe(Items.RABBIT_STEW, Ingredient.fromItems(Items.RABBIT_STEW), 1, InspirationsRecipes.rabbitStew, FluidCauldronIngredient.of(InspirationsRecipes.potatoSoup), folder + "rabbit_stew/");
// normal potato soup crafting
ShapelessRecipeBuilder.shapelessRecipe(InspirationsRecipes.potatoSoupItem)
.addIngredient(Items.BOWL)
.addIngredient(Items.BAKED_POTATO)
.addIngredient(Items.BAKED_POTATO)
.addIngredient(Tags.Items.MUSHROOMS)
.addCriterion("has_item", hasItem(Items.BAKED_POTATO))
.build(withCondition(), resource(folder + "potato_soup/item"));
}
/**
* Adds cauldron recipes to dye and undye colored blocks
* @param tag Tag for colored block
* @param enumObject Object of items
* @param folder Folder for output
* @param condition Extra condition to add, if null uses base conditions
*/
private void addColoredRecipes(ITag<Item> tag, EnumObject<DyeColor,? extends IItemProvider> enumObject, String folder, @Nullable ICondition condition) {
// add condition if present
Consumer<IFinishedRecipe> dyed, undyed;
if (condition == null) {
undyed = withCondition(ConfigEnabledCondition.CAULDRON_RECIPES);
dyed = withCondition(ConfigEnabledCondition.CAULDRON_DYEING);
} else {
undyed = withCondition(ConfigEnabledCondition.CAULDRON_RECIPES, condition);
dyed = withCondition(ConfigEnabledCondition.CAULDRON_DYEING, condition);
}
// undyed
Ingredient ingredient = Ingredient.fromTag(tag);
ICriterionInstance criteria = hasItem(tag);
CauldronRecipeBuilder.cauldron(ingredient, ContentTypeIngredient.of(CauldronContentTypes.WATER))
.minLevels(1)
.addLevels(-1)
.setOutput(enumObject.get(DyeColor.WHITE))
.addCriterion("has_item", criteria)
.build(undyed, resource(folder + "undye"));
// dyed recipes need one more condition
enumObject.forEach((color, block) ->
CauldronRecipeBuilder.cauldron(ingredient, ContentMatchIngredient.of(CauldronIngredients.DYE, color))
.minLevels(1)
.addLevels(-1)
.setOutput(block)
.addCriterion("has_item", criteria)
.build(dyed, resource(folder + color.getString())));
}
/**
* Adds recipes for making stew
* @param stewItem Item of filled stew
* @param ingredient Ingredient to make stew
* @param amount Amount of stew ingredient
* @param stewFluid Fluid for making stew
* @param base Base fluid for stew
* @param folder Folder for recipes
*/
private void addStewRecipe(IItemProvider stewItem, Ingredient ingredient, int amount, Fluid stewFluid, ICauldronIngredient base, String folder) {
Consumer<IFinishedRecipe> consumer = withCondition(ConfigEnabledCondition.CAULDRON_FLUIDS);
ICauldronIngredient stewIngredient = FluidCauldronIngredient.of(stewFluid);
ICauldronContents stewContents = CauldronContentTypes.FLUID.of(stewFluid);
// fill the bowl
CauldronRecipeBuilder.cauldron(Ingredient.fromItems(Items.BOWL), stewIngredient)
.minLevels(1)
.addLevels(-1)
.setOutput(stewItem)
.addCriterion("has_item", hasItem(Items.BOWL))
.build(consumer, resource(folder + "fill_bowl"));
// empty the bowl
CauldronRecipeBuilder.cauldron(Ingredient.fromItems(stewItem), stewIngredient)
.maxLevels(2)
.addLevels(1)
.setOutput(Items.BOWL)
.setOutput(stewContents)
.noContainer()
.addCriterion("has_item", hasItem(stewItem))
.build(consumer, resource(folder + "empty_bowl"));
// if the cauldron has 1 level, takes 1 item. If it has 2 or 3, take twice as many
ICriterionInstance criteria = hasItem(Blocks.CAULDRON);
CauldronRecipeBuilder.cauldron(ingredient, amount, base)
.levelRange(1, 1)
.setTemperature(TemperaturePredicate.HOT)
.setOutput(stewContents)
.addCriterion("has_item", criteria)
.build(consumer, resource(folder + "stew_small"));
CauldronRecipeBuilder.cauldron(ingredient, amount * 2, base)
.minLevels(2)
.setTemperature(TemperaturePredicate.HOT)
.setOutput(stewContents)
.addCriterion("has_item", criteria)
.build(consumer, resource(folder + "stew_large"));
}
private ResourceLocation prefixE(IForgeRegistryEntry<?> entry, String prefix) {
return this.resource(prefix + Objects.requireNonNull(entry.getRegistryName()).getPath());
}
private ResourceLocation wrapE(IForgeRegistryEntry<?> entry, String prefix, String suffix) {
return this.resource(prefix + Objects.requireNonNull(entry.getRegistryName()).getPath() + suffix);
}
}