-
Notifications
You must be signed in to change notification settings - Fork 755
/
DefaultMaterialsModule.java
81 lines (66 loc) · 2.82 KB
/
DefaultMaterialsModule.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
package slimeknights.tconstruct.library.tools.definition.module.material;
import com.google.common.collect.ImmutableList;
import net.minecraft.util.RandomSource;
import slimeknights.mantle.data.loadable.record.RecordLoadable;
import slimeknights.tconstruct.library.materials.RandomMaterial;
import slimeknights.tconstruct.library.materials.definition.MaterialId;
import slimeknights.tconstruct.library.module.ModuleHook;
import slimeknights.tconstruct.library.module.HookProvider;
import slimeknights.tconstruct.library.tools.definition.ToolDefinition;
import slimeknights.tconstruct.library.tools.definition.module.ToolHooks;
import slimeknights.tconstruct.library.tools.definition.module.ToolModule;
import slimeknights.tconstruct.library.tools.nbt.MaterialNBT;
import java.util.List;
/** Module to fill missing materials on a tool */
public record DefaultMaterialsModule(List<RandomMaterial> materials) implements MissingMaterialsToolHook, ToolModule {
private static final List<ModuleHook<?>> DEFAULT_HOOKS = HookProvider.defaultHooks(ToolHooks.MISSING_MATERIALS);
/** Loader instance */
public static final RecordLoadable<DefaultMaterialsModule> LOADER = RecordLoadable.create(RandomMaterial.LOADER.list(1).requiredField("materials", m -> m.materials), DefaultMaterialsModule::new);
@Override
public RecordLoadable<DefaultMaterialsModule> getLoader() {
return LOADER;
}
@Override
public List<ModuleHook<?>> getDefaultHooks() {
return DEFAULT_HOOKS;
}
@Override
public MaterialNBT fillMaterials(ToolDefinition definition, RandomSource random) {
return RandomMaterial.build(ToolMaterialHook.stats(definition), materials, random);
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private final ImmutableList.Builder<RandomMaterial> materials = ImmutableList.builder();
private Builder() {}
/** Adds a material to the builder */
public Builder material(RandomMaterial material) {
this.materials.add(material);
return this;
}
/** Adds a material to the builder */
public Builder material(RandomMaterial... materials) {
for (RandomMaterial material : materials) {
material(material);
}
return this;
}
/** Adds a material to the builder */
public Builder material(MaterialId material) {
return material(RandomMaterial.fixed(material));
}
/** Adds a material to the builder */
public Builder firstWithStat() {
return material(RandomMaterial.firstWithStat());
}
/** Builds the final module */
public DefaultMaterialsModule build() {
List<RandomMaterial> materials = this.materials.build();
if (materials.isEmpty()) {
throw new IllegalArgumentException("Must have at least 1 material");
}
return new DefaultMaterialsModule(materials);
}
}
}