-
Notifications
You must be signed in to change notification settings - Fork 18
/
InspirationsRecipes.java
349 lines (313 loc) · 14.6 KB
/
InspirationsRecipes.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
package knightminer.inspirations.recipes;
import knightminer.inspirations.common.Config;
import knightminer.inspirations.common.PulseBase;
import knightminer.inspirations.library.InspirationsRegistry;
import knightminer.inspirations.library.recipe.cauldron.BrewingCauldronRecipe;
import knightminer.inspirations.library.recipe.cauldron.FillCauldronRecipe;
import knightminer.inspirations.library.recipe.cauldron.FluidCauldronRecipe;
import knightminer.inspirations.library.recipe.cauldron.ICauldronRecipe;
import knightminer.inspirations.library.recipe.cauldron.MixCauldronRecipe;
import knightminer.inspirations.library.util.ReflectionUtil;
import knightminer.inspirations.recipes.block.EnhancedCauldronBlock;
import knightminer.inspirations.recipes.block.SmashingAnvilBlock;
import knightminer.inspirations.recipes.item.MixedDyedBottleItem;
import knightminer.inspirations.recipes.item.SimpleDyedBottleItem;
import knightminer.inspirations.recipes.recipe.cauldron.ArmorClearingCauldronRecipe;
import knightminer.inspirations.recipes.recipe.cauldron.ArmorDyeingCauldronRecipe;
import knightminer.inspirations.recipes.recipe.cauldron.BannerClearingCauldronRecipe;
import knightminer.inspirations.recipes.recipe.cauldron.DyeCauldronWater;
import knightminer.inspirations.recipes.recipe.cauldron.TippedArrowCauldronRecipe;
import knightminer.inspirations.recipes.recipe.cauldron.empty.ContainerEmptyCauldron;
import knightminer.inspirations.recipes.recipe.cauldron.empty.DyedBottleEmptyCauldron;
import knightminer.inspirations.recipes.recipe.cauldron.empty.PotionEmptyCauldron;
import knightminer.inspirations.recipes.recipe.cauldron.empty.SpongeEmptyCauldron;
import knightminer.inspirations.recipes.recipe.cauldron.fill.DyedBottleFillCauldron;
import knightminer.inspirations.recipes.recipe.cauldron.fill.FluidContainerFillCauldron;
import knightminer.inspirations.recipes.recipe.cauldron.fill.PotionFillCauldron;
import knightminer.inspirations.shared.InspirationsShared;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.material.Material;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ArmorMaterial;
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.Potion;
import net.minecraft.potion.PotionBrewing;
import net.minecraft.potion.PotionUtils;
import net.minecraft.potion.Potions;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvents;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.brewing.BrewingRecipe;
import net.minecraftforge.common.brewing.BrewingRecipeRegistry;
import net.minecraftforge.common.brewing.IBrewingRecipe;
import net.minecraftforge.event.RegistryEvent.Register;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.registries.IForgeRegistry;
import slimeknights.mantle.pulsar.pulse.Pulse;
import slimeknights.mantle.util.RecipeMatch;
import java.util.Map;
@Pulse(id = InspirationsRecipes.pulseID, description = "Adds additional recipe types, including cauldrons and anvil smashing")
public class InspirationsRecipes extends PulseBase {
public static final String pulseID = "InspirationsRecipes";
public static Object proxy = DistExecutor.callWhenOn(Dist.CLIENT, ()->()->new RecipesClientProxy());
// blocks
public static Block fullAnvil;
public static Block chippedAnvil;
public static Block damagedAnvil;
public static EnhancedCauldronBlock cauldron;
// items
public static Map<DyeColor,SimpleDyedBottleItem> simpleDyedWaterBottle;
public static MixedDyedBottleItem mixedDyedWaterBottle;
// fluids
public static Fluid mushroomStew;
public static Fluid beetrootSoup;
public static Fluid rabbitStew;
public static Fluid milk;
@SubscribeEvent
public void preInit(FMLCommonSetupEvent event) {
//TODO: reimplement
if(Config.enableCauldronFluids()) {
//mushroomStew = registerColoredFluid("mushroom_stew", 0xFFCD8C6F);
//beetrootSoup = registerColoredFluid("beetroot_soup", 0xFFB82A30);
//rabbitStew = registerColoredFluid("rabbit_stew", 0xFF984A2C);
if(Config.enableMilk()) {
///milk = registerFluid(new Fluid("milk", Util.getResource("blocks/milk"), Util.getResource("blocks/milk_flow")));
}
}
}
@SubscribeEvent
public void registerBlocks(Register<Block> event) {
IForgeRegistry<Block> r = event.getRegistry();
if(Config.enableAnvilSmashing.get()) {
fullAnvil = new SmashingAnvilBlock(Blocks.ANVIL);
chippedAnvil = new SmashingAnvilBlock(Blocks.CHIPPED_ANVIL);
damagedAnvil = new SmashingAnvilBlock(Blocks.DAMAGED_ANVIL);
r.registerAll(fullAnvil, chippedAnvil, damagedAnvil);
}
if(Config.enableExtendedCauldron()) {
cauldron = register(r, new EnhancedCauldronBlock(), Blocks.CAULDRON.getRegistryName());
}
}
@SubscribeEvent
public void registerItems(Register<Item> event) {
IForgeRegistry<Item> r = event.getRegistry();
for(DyeColor color: DyeColor.values()) {
simpleDyedWaterBottle.put(color, registerItem(r,
new SimpleDyedBottleItem(color),
color.getName() + "_dyed_bottle"
));
}
mixedDyedWaterBottle = registerItem(r, new MixedDyedBottleItem(), "mixed_dyed_bottle");
}
/* TODO: reimplement
@SubscribeEvent
public void registerRecipes(Register<IRecipe<ICraftingRecipe>> event) {
if(!Config.patchVanillaDyeRecipes()) {
return;
}
IForgeRegistry<IRecipe> r = event.getRegistry();
String[] recipes = {
"purple_dye",
"cyan_dye",
"light_gray_dye_from_ink_bonemeal",
"light_gray_dye_from_gray_bonemeal",
"gray_dye",
"pink_dye_from_red_bonemeal",
"lime_dye",
"light_blue_dye_from_lapis_bonemeal",
"magenta_dye_from_purple_and_pink",
"magenta_dye_from_lapis_red_pink",
"magenta_dye_from_lapis_ink_bonemeal",
"orange_dye_from_red_yellow"
};
for(String recipeName : recipes) {
IRecipe irecipe = r.getValue(new ResourceLocation(recipeName));
if(irecipe instanceof ShapelessRecipe) {
// simply find all current ingredients and wrap them in my class which removes bottles
ShapelessRecipe recipe = (ShapelessRecipe) irecipe;
NonNullList<Ingredient> newIngredients = NonNullList.create();
recipe.getIngredients().forEach(i->newIngredients.add(new DyeIngredientWrapper(i)));
recipe.getIngredients().clear();
recipe.getIngredients().addAll(newIngredients);
} else {
// another mod modified or removed recipe
String error = irecipe == null ? "recipe removed" : "recipe unexpected class " + irecipe.getClass();
Inspirations.log.warn("Error modifying dye recipe '{}', {}", recipeName, error);
}
}
}*/
@SubscribeEvent
public void init(FMLCommonSetupEvent event) {
InspirationsRegistry.registerAnvilBreaking(Material.GLASS);
if(Config.enableCauldronRecipes()) {
registerCauldronRecipes();
}
registerDispenserBehavior();
}
@SubscribeEvent
public void postInit(InterModProcessEvent event) {
MinecraftForge.EVENT_BUS.register(RecipesEvents.class);
registerPostCauldronRecipes();
}
private void registerCauldronRecipes() {
InspirationsRegistry.registerDefaultCauldron();
InspirationsRegistry.addCauldronRecipe(new FillCauldronRecipe(RecipeMatch.of(Blocks.ICE), Fluids.WATER, InspirationsRegistry.getCauldronMax(), ItemStack.EMPTY, true, SoundEvents.ITEM_BUCKET_EMPTY_LAVA));
if(Config.canSpongeEmptyCauldron()) {
InspirationsRegistry.addCauldronRecipe(SpongeEmptyCauldron.INSTANCE);
}
if(Config.cauldronObsidian.get()) {
ICauldronRecipe recipe;
// minor detail: if the cauldron can hold fluids, show the lava in the cauldron in JEI
// else show water in the cauldron as lava is not allowed
// in either case both are supported
if(Config.enableCauldronFluids()) {
recipe = new MixCauldronRecipe(Fluids.LAVA, Fluids.WATER, new ItemStack(Blocks.OBSIDIAN));
} else {
recipe = new MixCauldronRecipe(Fluids.WATER, Fluids.LAVA, new ItemStack(Blocks.OBSIDIAN));
}
InspirationsRegistry.addCauldronRecipe(recipe);
}
if(!Config.enableExtendedCauldron()) {
return;
}
// reimplemented vanilla recipes
InspirationsRegistry.addCauldronRecipe(new ArmorClearingCauldronRecipe(ArmorMaterial.LEATHER));
InspirationsRegistry.addCauldronRecipe(BannerClearingCauldronRecipe.INSTANCE);
// fill from water bottle, does not use the shortcut as we need NBT matching
ItemStack waterBottle = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.WATER);
InspirationsRegistry.addCauldronRecipe(new FluidCauldronRecipe(RecipeMatch.of(Items.GLASS_BOTTLE), Fluids.WATER, waterBottle, null, SoundEvents.ITEM_BOTTLE_FILL));
InspirationsRegistry.addCauldronRecipe(new FillCauldronRecipe(RecipeMatch.ofNBT(waterBottle), Fluids.WATER, 1, new ItemStack(Items.GLASS_BOTTLE)));
if(Config.enableCauldronDyeing()) {
InspirationsRegistry.addCauldronRecipe(DyedBottleEmptyCauldron.INSTANCE);
InspirationsRegistry.addCauldronRecipe(DyedBottleFillCauldron.INSTANCE);
InspirationsRegistry.addCauldronRecipe(new ArmorDyeingCauldronRecipe(ArmorMaterial.LEATHER));
for(DyeColor color : DyeColor.values()) {
InspirationsRegistry.addCauldronRecipe(new DyeCauldronWater(color));
/* TODO: reimplement
InspirationsRegistry.addCauldronRecipe(new DyeCauldronRecipe(
new ItemStack(Blocks.WOOL, 1, OreDictionary.WILDCARD_VALUE),
color,
new ItemStack(Blocks.WOOL, 1, color.getMetadata())
));
InspirationsRegistry.addCauldronRecipe(new DyeCauldronRecipe(
new ItemStack(Blocks.CARPET, 1, OreDictionary.WILDCARD_VALUE),
color,
new ItemStack(Blocks.CARPET, 1, color.getMetadata())
));
InspirationsRegistry.addCauldronRecipe(new DyeCauldronRecipe(
new ItemStack(Items.BED, 1, OreDictionary.WILDCARD_VALUE),
color,
new ItemStack(Items.BED, 1, color.getMetadata())
));*/
}
/* TODO: reimplement
if(InspirationsUtility.carpetedTrapdoors != null) {
RecipeMatch anyTrapdoor = RecipeMatch.of("trapdoorCarpeted");
for(DyeColor color : DyeColor.values()) {
InspirationsRegistry.addCauldronRecipe(new DyeCauldronRecipe(
anyTrapdoor, color,
new ItemStack(InspirationsUtility.carpetedTrapdoors[color.getId()])
));
}
}*/
}
if(Config.enableCauldronPotions()) {
addPotionBottle(Items.POTION, new ItemStack(Items.GLASS_BOTTLE), "bottles/normal");
addPotionBottle(Items.SPLASH_POTION, new ItemStack(InspirationsShared.splashBottle), "bottles/splash");
addPotionBottle(Items.LINGERING_POTION, new ItemStack(InspirationsShared.lingeringBottle), "bottles/lingering");
if (Config.cauldronTipArrows()) {
InspirationsRegistry.addCauldronRecipe(TippedArrowCauldronRecipe.INSTANCE);
}
}
if(Config.enableCauldronFluids()) {
InspirationsRegistry.addCauldronRecipe(ContainerEmptyCauldron.INSTANCE);
addStewRecipes(new ItemStack(Items.BEETROOT_SOUP), beetrootSoup, new ItemStack(Items.BEETROOT, 6));
//addStewRecipes(new ItemStack(Items.MUSHROOM_STEW), mushroomStew, new ItemStack(InspirationsShared.mushrooms));
//addStewRecipes(new ItemStack(Items.RABBIT_STEW), rabbitStew, new ItemStack(InspirationsShared.rabbitStewMix));
} else {
// above relied on for bucket filling cauldron
InspirationsRegistry.addCauldronFluidItem(new ItemStack(Items.WATER_BUCKET), new ItemStack(Items.BUCKET), Fluids.WATER, 3);
}
}
/**
* These recipes need to be registered later to prevent from conflicts or missing recipes
*/
private void registerPostCauldronRecipes() {
if(Config.enableCauldronBrewing()) {
for(Object recipe : PotionBrewing.POTION_TYPE_CONVERSIONS) {
Potion input = ReflectionUtil.getMixPredicateInput(recipe);
Ingredient reagent = ReflectionUtil.getMixPredicateReagent(recipe);
Potion output = ReflectionUtil.getMixPredicateOutput(recipe);
if(input != null && reagent != null && output != null) {
InspirationsRegistry.addCauldronRecipe(new BrewingCauldronRecipe(input, reagent, output));
}
}
findRecipesFromBrewingRegistry();
}
if(Config.enableCauldronFluids()) {
InspirationsRegistry.addCauldronRecipe(FluidContainerFillCauldron.INSTANCE);
}
}
private static void addPotionBottle(Item potion, ItemStack bottle, String bottleTag) {
InspirationsRegistry.addCauldronRecipe(new PotionFillCauldron(potion, bottle));
InspirationsRegistry.addCauldronRecipe(new PotionEmptyCauldron(potion,
new ItemTags.Wrapper(new ResourceLocation("forge", bottleTag))
));
}
private static void addStewRecipes(ItemStack stew, Fluid fluid, ItemStack ingredient) {
InspirationsRegistry.addCauldronScaledTransformRecipe(ingredient, Fluids.WATER, fluid, true);
// filling and emptying bowls
InspirationsRegistry.addCauldronRecipe(new FluidCauldronRecipe(RecipeMatch.of(Items.BOWL), fluid, stew, null, SoundEvents.ITEM_BOTTLE_FILL));
InspirationsRegistry.addCauldronRecipe(new FillCauldronRecipe(RecipeMatch.of(stew), fluid, 1, new ItemStack(Items.BOWL)));
}
private void findRecipesFromBrewingRegistry() {
for(IBrewingRecipe irecipe : BrewingRecipeRegistry.getRecipes()) {
if(irecipe instanceof BrewingRecipe) {
BrewingRecipe recipe = (BrewingRecipe) irecipe;
Ingredient inputIngredient = recipe.getInput();
ItemStack outputStack = recipe.getOutput();
Ingredient ingredient = recipe.getIngredient();
// null checks because some dumb mod is returning null for the input or output
if (ingredient == null || inputIngredient == null || outputStack == null){
continue;
}
ItemStack inputStack = ItemStack.EMPTY;
for (ItemStack validInput: inputIngredient.getMatchingStacks()) {
if (validInput.getItem() == Items.POTION) {
inputStack = validInput;
break;
}
}
if(!inputStack.isEmpty() && outputStack.getItem() == Items.POTION) {
Potion input = PotionUtils.getPotionFromItem(inputStack);
Potion output = PotionUtils.getPotionFromItem(outputStack);
if(input != Potions.EMPTY && output != Potions.EMPTY) {
InspirationsRegistry.addCauldronRecipe(new BrewingCauldronRecipe(input, ingredient, output));
}
}
}
}
}
private void registerDispenserBehavior() {
/* TODO: reimplement
if(Config.enableCauldronDispenser()) {
for(Item item : InspirationsRegistry.TAG_DISP_FLUID_TANKS.getAllElements()) {
registerDispenserBehavior(
item,
new DispenseCauldronRecipe(DispenserBlock.DISPENSE_BEHAVIOR_REGISTRY.get(item))
);
}
}*/
}
}