-
Notifications
You must be signed in to change notification settings - Fork 754
/
IToolContext.java
128 lines (103 loc) · 4.22 KB
/
IToolContext.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
package slimeknights.tconstruct.library.tools.nbt;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import slimeknights.tconstruct.library.materials.definition.MaterialVariant;
import slimeknights.tconstruct.library.modifiers.Modifier;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
import slimeknights.tconstruct.library.modifiers.ModifierHook;
import slimeknights.tconstruct.library.modifiers.ModifierId;
import slimeknights.tconstruct.library.tools.definition.ToolDefinition;
import slimeknights.tconstruct.library.tools.definition.ToolDefinitionData;
import java.util.List;
/**
* Provides partial access to tool data, essentially a bridge between {@link IToolStackView} and {@link slimeknights.tconstruct.library.tools.context.ToolRebuildContext}
*/
public interface IToolContext {
/** Gets the item contained in this tool */
Item getItem();
/** Gets the tool definition */
ToolDefinition getDefinition();
/** On built tools, contains the full tool stats. During tool rebuild, contains the base stats before considering modifiers. */
StatsNBT getStats();
/** Gets the tool definition data */
default ToolDefinitionData getDefinitionData() {
return getDefinition().getData();
}
/** Checks if the tool has the given tag */
@SuppressWarnings("deprecation")
default boolean hasTag(TagKey<Item> tag) {
return getItem().builtInRegistryHolder().containsTag(tag);
}
/** Gets the given hook from the tool */
default <T> T getHook(ModifierHook<T> hook) {
return getDefinition().getData().getHook(hook);
}
/* Materials */
/** Gets the list of current materials making this tool */
MaterialNBT getMaterials();
/**
* Gets the material at the given index
* @param index Index
* @return Material, or unknown if index is invalid
*/
default MaterialVariant getMaterial(int index) {
return getMaterials().get(index);
}
/* Modifiers */
/** Gets a list of modifiers that are specifically added to this tool. Unlike {@link #getModifiers()}, does not include modifiers from the tool or materials */
ModifierNBT getUpgrades();
/** Gets a full list of effective modifiers on this tool, from both upgrades/abilities and material traits */
ModifierNBT getModifiers();
/**
* Helper to get a list of all modifiers on the tool. Note this list is already sorted by priority
* @return List of all modifiers
*/
default List<ModifierEntry> getModifierList() {
return getModifiers().getModifiers();
}
/**
* Gets the modifier entry for the given modifier ID
* @param modifier Modifier
* @return Modifier entry, or {@link ModifierEntry#EMPTY} if missing.
*/
default ModifierEntry getModifier(ModifierId modifier) {
return getModifiers().getEntry(modifier);
}
/**
* Gets the modifier entry for the given modifier ID
* @param modifier Modifier
* @return Modifier entry, or {@link ModifierEntry#EMPTY} if missing.
*/
default ModifierEntry getModifier(Modifier modifier) {
return getModifiers().getEntry(modifier.getId());
}
/**
* Gets the level of a modifier on this tool. Will consider both raw modifiers and material traits
* @param modifier Modifier
* @return Level of modifier, 0 if the modifier is not on the tool
*/
default int getModifierLevel(ModifierId modifier) {
return getModifiers().getLevel(modifier);
}
/**
* Gets the level of a modifier on this tool. Will consider both raw modifiers and material traits
* @param modifier Modifier
* @return Level of modifier, 0 if the modifier is not on the tool
*/
default int getModifierLevel(Modifier modifier) {
return getModifiers().getLevel(modifier.getId());
}
/* Tool data */
/**
* Gets persistent modifier data from the tool.
* This data may be edited by modifiers and will persist when stats rebuild
* TODO 1.19: change return type to INamespacedNBTView as modifiers should not be slot sensitive
*/
IModDataView getPersistentData();
/**
* Gets volatile modifier data from the tool.
* This data will be reset whenever modifiers reload and should not be edited.
* TODO 1.19: change return type to INamespacedNBTView as modifiers should not be slot sensitive
*/
IModDataView getVolatileData();
}