-
Notifications
You must be signed in to change notification settings - Fork 18
/
TileCauldronInventory.java
83 lines (66 loc) · 2.24 KB
/
TileCauldronInventory.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
package knightminer.inspirations.recipes.recipe.inventory;
import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents;
import knightminer.inspirations.library.recipe.cauldron.recipe.ICauldronRecipe;
import knightminer.inspirations.recipes.tileentity.CauldronTileEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.MathHelper;
import javax.annotation.Nullable;
import java.util.function.Consumer;
/**
* Inventory used in a cauldron tile entity that supports generic contexts for interaction
*/
public class TileCauldronInventory extends CauldronItemInventory {
private final CauldronTileEntity tile;
private int newLevel = -1;
public TileCauldronInventory(CauldronTileEntity tile) {
this.tile = tile;
}
/* Item handling */
/**
* Sets the context for item stack handling
* @param stack Stack to match for recipes
* @param itemSetter Logic to update the stack in the context. If null, will assume {@link #getStack()} will be used for updates
* @param itemAdder Logic to add a new stack to the context
*/
public void setItemContext(ItemStack stack, @Nullable Consumer<ItemStack> itemSetter, Consumer<ItemStack> itemAdder) {
this.stack = stack;
this.itemSetter = itemSetter == null ? EMPTY_CONSUMER : itemSetter;
this.itemAdder = itemAdder;
// also clear new level so we do not set to the wrong new value
this.newLevel = -1;
}
/**
* Clears any context specific data from the wrapper
*/
public void clearContext() {
this.stack = ItemStack.EMPTY;
this.itemSetter = EMPTY_CONSUMER;
this.itemAdder = EMPTY_CONSUMER;
}
/* Level */
@Override
public int getLevel() {
if (newLevel != -1) {
return newLevel;
}
return tile.getLevel();
}
@Override
public void setLevel(int level) {
// set variable so we can just run updates at the end
newLevel = MathHelper.clamp(level, 0, ICauldronRecipe.MAX);
}
/* Contents */
@Override
public ICauldronContents getContents() {
return tile.getContents();
}
@Override
public void setContents(ICauldronContents contents) {
tile.setContents(contents);
}
@Override
public boolean isBoiling() {
return tile.getBlock().isBoiling(tile.getBlockState());
}
}