use of slimeknights.tconstruct.library.tools.definition.ToolDefinitionDataBuilder in project TinkersConstruct by SlimeKnights.
the class AbstractToolDefinitionDataProvider method run.
@Override
public void run(HashCache cache) throws IOException {
addToolDefinitions();
Map<ResourceLocation, ToolDefinition> relevantDefinitions = ToolDefinitionLoader.getInstance().getRegisteredToolDefinitions().stream().filter(def -> def.getId().getNamespace().equals(modId)).collect(Collectors.toMap(ToolDefinition::getId, Function.identity()));
// ensure all required definitions are included
for (ToolDefinition definition : relevantDefinitions.values()) {
ResourceLocation name = definition.getId();
if (!allTools.containsKey(name)) {
throw new IllegalStateException(String.format("Missing tool definition for '%s'", name));
}
}
// ensure all included ones are required, and the built ones are valid
for (Entry<ResourceLocation, ToolDefinitionDataBuilder> entry : allTools.entrySet()) {
ResourceLocation id = entry.getKey();
ToolDefinition definition = relevantDefinitions.get(id);
if (definition == null) {
throw new IllegalStateException("Unknown tool definition with ID " + id);
}
ToolDefinitionData data = entry.getValue().build();
definition.validate(data);
saveThing(cache, id, data);
}
}
Aggregations