Search in sources :

Example 26 with MaterialId

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

the class MaterialStatsManagerTest method testLoadFile_multipleStatsInOneFile.

@Test
void testLoadFile_multipleStatsInOneFile() {
    MaterialId material = new MaterialId(TConstruct.getResource("multiple"));
    MaterialStatsId statId1 = new MaterialStatsId("test", "stat1");
    materialStatsManager.registerMaterialStat(new ComplexTestStats(statId1, 1, 1f, "one"), ComplexTestStats.class, ComplexTestStats::new);
    MaterialStatsId statId2 = new MaterialStatsId("test", "stat2");
    materialStatsManager.registerMaterialStat(new ComplexTestStats(statId2, 2, 2f, "two"), ComplexTestStats.class, ComplexTestStats::new);
    fileLoader.loadAndParseFiles(null, material);
    assertThat(materialStatsManager.getStats(material, statId1)).isPresent();
    assertThat(materialStatsManager.getStats(material, statId2)).isPresent();
}
Also used : MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) Test(org.junit.jupiter.api.Test) BaseMcTest(slimeknights.tconstruct.test.BaseMcTest)

Example 27 with MaterialId

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

the class MaterialStatsManagerTest method loadFileWithOnlyUnregisteredStats_doNothing.

@Test
void loadFileWithOnlyUnregisteredStats_doNothing() {
    MaterialId material = new MaterialId(TConstruct.getResource("invalid"));
    fileLoader.loadAndParseFiles(null, material);
    Optional<ComplexTestStats> optionalStats = materialStatsManager.getStats(material, new MaterialStatsId("test", "fails"));
    assertThat(optionalStats).isEmpty();
}
Also used : MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) Test(org.junit.jupiter.api.Test) BaseMcTest(slimeknights.tconstruct.test.BaseMcTest)

Example 28 with MaterialId

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

the class SlimeskullArmorModel method setup.

/**
 * Called before the model is rendered to set the base model and the tool stack data
 */
private void setup(HumanoidModel<?> base, ItemStack stack) {
    this.base = base;
    this.hasGlint = stack.hasFoil();
    MaterialId materialId = MaterialIdNBT.from(stack).getMaterial(0).getId();
    if (!materialId.equals(IMaterial.UNKNOWN_ID)) {
        SkullModelBase model = getHeadModel(materialId);
        ResourceLocation texture = HEAD_TEXTURES.get(materialId);
        if (model != null && texture != null) {
            headModel = model;
            headTexture = texture;
            return;
        }
    }
    headTexture = null;
    headModel = null;
}
Also used : MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) ResourceLocation(net.minecraft.resources.ResourceLocation) SkullModelBase(net.minecraft.client.model.SkullModelBase)

Example 29 with MaterialId

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

the class SlimeskullArmorModel method getHeadModel.

/**
 * Gets the head model for the given material
 */
@Nullable
private static SkullModelBase getHeadModel(MaterialId materialId) {
    if (HEAD_MODELS == null) {
        // vanilla rebakes these a lot, so figure we should at least do it every resource reload
        EntityModelSet modelSet = Minecraft.getInstance().getEntityModels();
        ImmutableMap.Builder<MaterialId, SkullModelBase> models = ImmutableMap.builder();
        for (Entry<MaterialId, Function<EntityModelSet, ? extends SkullModelBase>> entry : HEAD_MODEL_FACTORIES.entrySet()) {
            models.put(entry.getKey(), entry.getValue().apply(modelSet));
        }
        HEAD_MODELS = models.build();
    }
    return HEAD_MODELS.get(materialId);
}
Also used : Function(java.util.function.Function) MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) EntityModelSet(net.minecraft.client.model.geom.EntityModelSet) SkullModelBase(net.minecraft.client.model.SkullModelBase) ImmutableMap(com.google.common.collect.ImmutableMap) Nullable(javax.annotation.Nullable)

Example 30 with MaterialId

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

the class TinkerStationRepairRecipe method getValidatedResult.

@Override
public ValidatedResult getValidatedResult(ITinkerStationContainer inv) {
    ToolStack tool = ToolStack.from(inv.getTinkerableStack());
    if (tool.getDefinition() == ToolDefinition.EMPTY) {
        return ValidatedResult.PASS;
    }
    // ensure input needs repair
    if (!tool.isBroken() && tool.getDamage() == 0) {
        return FULLY_REPAIRED;
    }
    // first, determine how much we can repair
    MaterialId primaryMaterial = getPrimaryMaterial(tool);
    int repairNeeded = tool.getDamage();
    int repairRemaining = repairNeeded;
    // iterate stacks, adding up amount we can repair, assumes the material is correct per #matches()
    for (int i = 0; i < inv.getInputCount() && repairRemaining > 0; i++) {
        repairRemaining -= repairFromSlot(tool, primaryMaterial, inv, repairRemaining, i, NO_ACTION);
    }
    // did we actually repair something?
    if (repairRemaining < repairNeeded) {
        tool = tool.copy();
        ToolDamageUtil.repair(tool, repairNeeded - repairRemaining);
        // repair remaining can be negative
        return ValidatedResult.success(tool.createStack());
    }
    // for some odd reason, did not repair anything
    return ValidatedResult.PASS;
}
Also used : MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) ToolStack(slimeknights.tconstruct.library.tools.nbt.ToolStack)

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