Search in sources :

Example 31 with MaterialId

use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.

the class TinkerStationRepairRecipe method updateInputs.

@Override
public void updateInputs(ItemStack result, IMutableTinkerStationContainer inv, boolean isServer) {
    ToolStack inputTool = ToolStack.from(inv.getTinkerableStack());
    ToolStack resultTool = ToolStack.from(result);
    // iterate stacks, removing items as we repair
    int repairRemaining = inputTool.getDamage() - resultTool.getDamage();
    MaterialId primaryMaterial = getPrimaryMaterial(inputTool);
    for (int i = 0; i < inv.getInputCount() && repairRemaining > 0; i++) {
        final int slot = i;
        repairRemaining -= repairFromSlot(inputTool, primaryMaterial, inv, repairRemaining, i, count -> inv.shrinkInput(slot, count));
    }
    if (repairRemaining > 0) {
        TConstruct.LOG.error("Recipe repair on {} consumed too few items. {} durability unaccounted for", result, repairRemaining);
    }
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) MaterialStatsId(slimeknights.tconstruct.library.materials.stats.MaterialStatsId) IntStream(java.util.stream.IntStream) Getter(lombok.Getter) IToolPart(slimeknights.tconstruct.library.tools.part.IToolPart) RequiredArgsConstructor(lombok.RequiredArgsConstructor) IntConsumer(java.util.function.IntConsumer) ToolDamageUtil(slimeknights.tconstruct.library.tools.helper.ToolDamageUtil) ToolDefinitionData(slimeknights.tconstruct.library.tools.definition.ToolDefinitionData) TinkerToolParts(slimeknights.tconstruct.tools.TinkerToolParts) ToolDefinition(slimeknights.tconstruct.library.tools.definition.ToolDefinition) ModifierEntry(slimeknights.tconstruct.library.modifiers.ModifierEntry) Nullable(javax.annotation.Nullable) IMaterial(slimeknights.tconstruct.library.materials.definition.IMaterial) TinkerTables(slimeknights.tconstruct.tables.TinkerTables) IToolStackView(slimeknights.tconstruct.library.tools.nbt.IToolStackView) RecipeSerializer(net.minecraft.world.item.crafting.RecipeSerializer) TinkerTags(slimeknights.tconstruct.common.TinkerTags) ValidatedResult(slimeknights.tconstruct.library.recipe.tinkerstation.ValidatedResult) ITinkerStationContainer(slimeknights.tconstruct.library.recipe.tinkerstation.ITinkerStationContainer) ITinkerStationRecipe(slimeknights.tconstruct.library.recipe.tinkerstation.ITinkerStationRecipe) TConstruct(slimeknights.tconstruct.TConstruct) MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) IMaterialItem(slimeknights.tconstruct.library.tools.part.IMaterialItem) MaterialRecipe(slimeknights.tconstruct.library.recipe.material.MaterialRecipe) IMutableTinkerStationContainer(slimeknights.tconstruct.library.recipe.tinkerstation.IMutableTinkerStationContainer) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) ToolStack(slimeknights.tconstruct.library.tools.nbt.ToolStack) MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) ToolStack(slimeknights.tconstruct.library.tools.nbt.ToolStack)

Example 32 with MaterialId

use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.

the class MaterialStatsManager method finishLoad.

@Override
protected void finishLoad(Map<ResourceLocation, Map<ResourceLocation, JsonObject>> map, ResourceManager manager) {
    // Take the final structure and actually load the different material stats. This drops all invalid stats
    materialToStatsPerType = map.entrySet().stream().collect(Collectors.toMap(entry -> new MaterialId(entry.getKey()), entry -> deserializeMaterialStatsFromContent(entry.getValue())));
    log.debug("Loaded stats for materials:{}", Util.toIndentedStringList(materialToStatsPerType.entrySet().stream().map(entry -> String.format("%s - %s", entry.getKey(), Arrays.toString(entry.getValue().keySet().toArray()))).collect(Collectors.toList())));
    onLoaded.run();
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) TinkerAPIMaterialException(slimeknights.tconstruct.library.exception.TinkerAPIMaterialException) HashMap(java.util.HashMap) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) Function(java.util.function.Function) GsonBuilder(com.google.gson.GsonBuilder) JsonElement(com.google.gson.JsonElement) Gson(com.google.gson.Gson) Map(java.util.Map) Nullable(javax.annotation.Nullable) MergingJsonDataLoader(slimeknights.mantle.data.MergingJsonDataLoader) ImmutableMap(com.google.common.collect.ImmutableMap) JsonSyntaxException(com.google.gson.JsonSyntaxException) Collection(java.util.Collection) ResourceManager(net.minecraft.server.packs.resources.ResourceManager) Collectors(java.util.stream.Collectors) Util(slimeknights.tconstruct.library.utils.Util) MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) Log4j2(lombok.extern.log4j.Log4j2) Entry(java.util.Map.Entry) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MaterialStatJson(slimeknights.tconstruct.library.materials.json.MaterialStatJson) Collections(java.util.Collections) MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId)

Example 33 with MaterialId

use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.

the class MaterialTraitsManagerTest method empty.

@Test
void empty() {
    MaterialId empty = new MaterialId(TConstruct.getResource("empty"));
    fileLoader.loadAndParseFiles(null, empty);
    // ensure we got this far and there were no errors
    List<ModifierEntry> defaultTraits = traitsManager.getDefaultTraits(DEFAULT_TRAITS);
    assertThat(defaultTraits).isNotNull();
    assertThat(defaultTraits).isEmpty();
}
Also used : MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) ModifierEntry(slimeknights.tconstruct.library.modifiers.ModifierEntry) Test(org.junit.jupiter.api.Test) BaseMcTest(slimeknights.tconstruct.test.BaseMcTest)

Example 34 with MaterialId

use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.

the class SpecializedRepairRecipeSerializer method fromNetworkSafe.

@Nullable
@Override
protected T fromNetworkSafe(ResourceLocation id, FriendlyByteBuf buffer) {
    Ingredient tool = Ingredient.fromNetwork(buffer);
    MaterialId repairMaterial = new MaterialId(buffer.readUtf(Short.MAX_VALUE));
    return factory.create(id, tool, repairMaterial);
}
Also used : MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) Ingredient(net.minecraft.world.item.crafting.Ingredient) Nullable(javax.annotation.Nullable)

Example 35 with MaterialId

use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.

the class MaterialIdNBT method resolveRedirects.

/**
 * Resolves all redirects, replacing with material redirects
 */
public MaterialIdNBT resolveRedirects() {
    boolean changed = false;
    ImmutableList.Builder<MaterialVariantId> builder = ImmutableList.builder();
    IMaterialRegistry registry = MaterialRegistry.getInstance();
    for (MaterialVariantId id : materials) {
        MaterialId original = id.getId();
        MaterialId resolved = registry.resolve(original);
        if (resolved != original) {
            changed = true;
        }
        builder.add(MaterialVariantId.create(resolved, id.getVariant()));
    }
    // return a new instance only if things changed
    if (changed) {
        return new MaterialIdNBT(builder.build());
    }
    return this;
}
Also used : MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) ImmutableList(com.google.common.collect.ImmutableList) MaterialVariantId(slimeknights.tconstruct.library.materials.definition.MaterialVariantId) IMaterialRegistry(slimeknights.tconstruct.library.materials.IMaterialRegistry)

Aggregations

MaterialId (slimeknights.tconstruct.library.materials.definition.MaterialId)41 Test (org.junit.jupiter.api.Test)11 BaseMcTest (slimeknights.tconstruct.test.BaseMcTest)11 Nullable (javax.annotation.Nullable)9 ModifierEntry (slimeknights.tconstruct.library.modifiers.ModifierEntry)9 ResourceLocation (net.minecraft.resources.ResourceLocation)8 ItemStack (net.minecraft.world.item.ItemStack)7 Collections (java.util.Collections)6 List (java.util.List)6 IMaterial (slimeknights.tconstruct.library.materials.definition.IMaterial)6 ToolStack (slimeknights.tconstruct.library.tools.nbt.ToolStack)6 Collectors (java.util.stream.Collectors)5 MaterialVariantId (slimeknights.tconstruct.library.materials.definition.MaterialVariantId)5 JsonObject (com.google.gson.JsonObject)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 TConstruct (slimeknights.tconstruct.TConstruct)4 MaterialStatsId (slimeknights.tconstruct.library.materials.stats.MaterialStatsId)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 JsonElement (com.google.gson.JsonElement)3 Function (java.util.function.Function)3