/
IModifyableCauldronInventory.java
64 lines (54 loc) · 1.61 KB
/
IModifyableCauldronInventory.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
package knightminer.inspirations.library.recipe.cauldron.inventory;
import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents;
import net.minecraft.item.ItemStack;
import java.util.function.IntUnaryOperator;
/**
* Inventory for handling the results of a cauldron recipe
*/
public interface IModifyableCauldronInventory extends ICauldronInventory {
/**
* Updates the held item stack used to interact with the cauldron
* @param stack New stack to hold
*/
void setStack(ItemStack stack);
/**
* Gives an item to the player. Does not effect the existing stack
* @param stack New player stack
*/
void giveStack(ItemStack stack);
/**
* Sets the contents of the cauldron
* @param contents New cauldron contents
*/
void setContents(ICauldronContents contents);
/**
* Sets the cauldron level to a new value
* @param level New cauldron level
*/
void setLevel(int level);
/* Helper methods */
/**
* Decreases the size of the held stack
* @param amount Amount to shrink by
* @return updated stack
*/
default ItemStack shrinkStack(int amount) {
ItemStack stack = getStack();
stack.shrink(amount);
if (stack.isEmpty()) {
stack = ItemStack.EMPTY;
}
setStack(stack);
return stack;
}
/**
* Updates the cauldron level based on the given function
* @param updater Int to int function
* @return True if the cauldron is now empty, false otherwise
*/
default boolean updateLevel(IntUnaryOperator updater) {
int newLevel = updater.applyAsInt(getLevel());
setLevel(newLevel);
return newLevel == 0;
}
}