Search in sources :

Example 1 with ToolDefinitionDataBuilder

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);
    }
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) MaterialStatsId(slimeknights.tconstruct.library.materials.stats.MaterialStatsId) ToolDefinitionLoader(slimeknights.tconstruct.library.tools.definition.ToolDefinitionLoader) IToolPart(slimeknights.tconstruct.library.tools.part.IToolPart) ToolStats(slimeknights.tconstruct.library.tools.stat.ToolStats) HashMap(java.util.HashMap) PackType(net.minecraft.server.packs.PackType) Function(java.util.function.Function) Supplier(java.util.function.Supplier) SlotType(slimeknights.tconstruct.library.tools.SlotType) ImmutableList(com.google.common.collect.ImmutableList) ArmorSlotType(slimeknights.tconstruct.tools.item.ArmorSlotType) ItemLike(net.minecraft.world.level.ItemLike) ToolDefinitionData(slimeknights.tconstruct.library.tools.definition.ToolDefinitionData) ToolDefinition(slimeknights.tconstruct.library.tools.definition.ToolDefinition) Map(java.util.Map) GenericDataProvider(slimeknights.mantle.data.GenericDataProvider) FloatToolStat(slimeknights.tconstruct.library.tools.stat.FloatToolStat) DataGenerator(net.minecraft.data.DataGenerator) ToolDefinitionDataBuilder(slimeknights.tconstruct.library.tools.definition.ToolDefinitionDataBuilder) HashCache(net.minecraft.data.HashCache) ModifiableArmorMaterial(slimeknights.tconstruct.library.tools.definition.ModifiableArmorMaterial) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Modifier(slimeknights.tconstruct.library.modifiers.Modifier) IToolStat(slimeknights.tconstruct.library.tools.stat.IToolStat) Entry(java.util.Map.Entry) ToolDefinitionData(slimeknights.tconstruct.library.tools.definition.ToolDefinitionData) ToolDefinitionDataBuilder(slimeknights.tconstruct.library.tools.definition.ToolDefinitionDataBuilder) ResourceLocation(net.minecraft.resources.ResourceLocation) ToolDefinition(slimeknights.tconstruct.library.tools.definition.ToolDefinition)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 DataGenerator (net.minecraft.data.DataGenerator)1 HashCache (net.minecraft.data.HashCache)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 PackType (net.minecraft.server.packs.PackType)1 ItemLike (net.minecraft.world.level.ItemLike)1 GenericDataProvider (slimeknights.mantle.data.GenericDataProvider)1 MaterialStatsId (slimeknights.tconstruct.library.materials.stats.MaterialStatsId)1 Modifier (slimeknights.tconstruct.library.modifiers.Modifier)1 SlotType (slimeknights.tconstruct.library.tools.SlotType)1 ModifiableArmorMaterial (slimeknights.tconstruct.library.tools.definition.ModifiableArmorMaterial)1