/
NormalBrewingRecipe.java
72 lines (61 loc) · 1.86 KB
/
NormalBrewingRecipe.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
package knightminer.inspirations.tweaks.recipe;
import knightminer.inspirations.common.IHidable;
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.PotionUtils;
import net.minecraftforge.common.brewing.IBrewingRecipe;
import java.util.function.Supplier;
/**
* A brewing recipe type which can be applied to all three potion item types.
*/
public class NormalBrewingRecipe implements IHidable, IBrewingRecipe {
private final Supplier<Boolean> enabled;
private final Potion start;
private final Ingredient catalyst;
private final Potion output;
public NormalBrewingRecipe(Potion start, Ingredient catalyst, Potion output, Supplier<Boolean> enabledFunc) {
this.start = start;
this.catalyst = catalyst;
this.output = output;
this.enabled = enabledFunc;
}
@Override
public boolean isEnabled() {
return enabled.get();
}
public Ingredient getCatalyst() {
return catalyst;
}
public Potion getStart() {
return start;
}
public Potion getOutput() {
return output;
}
@Override
public boolean isInput(ItemStack input) {
Item item = input.getItem();
if (item == Items.POTION || item == Items.SPLASH_POTION || item == Items.LINGERING_POTION) {
return PotionUtils.getPotionFromItem(input) == start;
}
return false;
}
@Override
public boolean isIngredient(ItemStack ingredient) {
return catalyst.test(ingredient);
}
@Override
public ItemStack getOutput(ItemStack input, ItemStack ingredient) {
if (!catalyst.test(ingredient)) {
return ItemStack.EMPTY;
}
Item item = input.getItem();
if (item == Items.POTION || item == Items.SPLASH_POTION || item == Items.LINGERING_POTION) {
return PotionUtils.addPotionToItemStack(new ItemStack(item), output);
}
return ItemStack.EMPTY;
}
}