/
ModifierSlotModule.java
60 lines (51 loc) · 2.34 KB
/
ModifierSlotModule.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
package slimeknights.tconstruct.library.modifiers.modules.build;
import slimeknights.mantle.data.loadable.primitive.IntLoadable;
import slimeknights.mantle.data.loadable.record.RecordLoadable;
import slimeknights.mantle.data.registry.GenericLoaderRegistry.IGenericLoader;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
import slimeknights.tconstruct.library.modifiers.ModifierHook;
import slimeknights.tconstruct.library.modifiers.TinkerHooks;
import slimeknights.tconstruct.library.modifiers.hook.build.VolatileDataModifierHook;
import slimeknights.tconstruct.library.modifiers.modules.ModifierModule;
import slimeknights.tconstruct.library.modifiers.modules.ModifierModuleCondition;
import slimeknights.tconstruct.library.modifiers.modules.ModifierModuleCondition.ConditionalModifierModule;
import slimeknights.tconstruct.library.tools.SlotType;
import slimeknights.tconstruct.library.tools.context.ToolRebuildContext;
import slimeknights.tconstruct.library.tools.nbt.ModDataNBT;
import java.util.List;
/**
* Module that adds extra modifier slots to a tool.
*/
public record ModifierSlotModule(SlotType type, int count, ModifierModuleCondition condition) implements VolatileDataModifierHook, ModifierModule, ConditionalModifierModule {
private static final List<ModifierHook<?>> DEFAULT_HOOKS = List.of(TinkerHooks.VOLATILE_DATA);
public static final RecordLoadable<ModifierSlotModule> LOADER = RecordLoadable.create(
SlotType.LOADABLE.field("name", ModifierSlotModule::type),
IntLoadable.ANY_SHORT.defaultField("count", 1, true, ModifierSlotModule::count),
ModifierModuleCondition.FIELD,
ModifierSlotModule::new);
public ModifierSlotModule(SlotType type, int count) {
this(type, count, ModifierModuleCondition.ANY);
}
public ModifierSlotModule(SlotType type) {
this(type, 1);
}
@Override
public Integer getPriority() {
// show lower priority so they group together
return 50;
}
@Override
public void addVolatileData(ToolRebuildContext context, ModifierEntry modifier, ModDataNBT volatileData) {
if (condition.matches(context, modifier)) {
volatileData.addSlots(type, count * modifier.getLevel());
}
}
@Override
public IGenericLoader<? extends ModifierModule> getLoader() {
return LOADER;
}
@Override
public List<ModifierHook<?>> getDefaultHooks() {
return DEFAULT_HOOKS;
}
}