/
CauldronPotionRecipe.java
105 lines (89 loc) · 2.94 KB
/
CauldronPotionRecipe.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
package knightminer.inspirations.library.recipe.cauldron;
import java.util.List;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import knightminer.inspirations.library.Util;
import net.minecraft.init.PotionTypes;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionType;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundEvent;
import net.minecraftforge.fluids.FluidRegistry;
import slimeknights.mantle.util.RecipeMatch;
/**
* Recipe to transform an item stack using a fluid
*/
@ParametersAreNonnullByDefault
public class CauldronPotionRecipe implements ISimpleCauldronRecipe {
private RecipeMatch input;
private ItemStack result;
protected PotionType potion;
private int levels;
@Nullable
private Boolean boiling;
/**
* @param input Input recipe match entry
* @param potion Required potion in the cauldron
* @param result Resulting item stack
* @param levels Amount of levels consumed by the recipe, also determines how many levels are required to perform the recipe
* @param boiling If true, the cauldron must be above fire, if false it must not be above fire. Set to null to ignore fire
*/
public CauldronPotionRecipe(RecipeMatch input, PotionType potion, ItemStack result, int levels, @Nullable Boolean boiling) {
this.input = input;
this.result = result;
this.potion = potion;
this.levels = levels;
this.boiling = boiling;
}
@Override
public boolean matches(ItemStack stack, boolean boiling, int level, CauldronState state) {
// if boiling is required, ensure it is set
if(level < levels || state.getPotion() != potion || (this.boiling != null && boiling != this.boiling.booleanValue())) {
return false;
}
return this.input.matches(Util.createNonNullList(stack)).isPresent();
}
@Override
public ItemStack transformInput(ItemStack stack, boolean boiling, int level, CauldronState state) {
NonNullList<ItemStack> list = Util.createNonNullList(stack);
RecipeMatch.removeMatch(list, input.matches(list).get());
return stack;
}
@Override
public List<ItemStack> getInput() {
return input.getInputs();
}
@Override
public ItemStack getResult() {
return result;
}
@Override
public int getLevel(int level) {
return level - levels;
}
@Override
public int getInputLevel() {
return levels == 0 ? 1 : levels;
}
@Override
public boolean isBoiling() {
return boiling == Boolean.TRUE;
}
@Override
public Object getInputState() {
return potion == PotionTypes.WATER ? FluidRegistry.WATER : potion;
}
/**
* Gets the sound to play when performing this recipe
* @return Sound event
*/
@Override
public SoundEvent getSound(ItemStack stack, boolean boiling, int level, CauldronState state) {
return SoundEvents.ENTITY_BOBBER_SPLASH;
}
@Override
public String toString() {
return String.format("CauldronFluidRecipe: %s from %s", result.toString(), potion.getRegistryName());
}
}