Search in sources :

Example 21 with MaterialId

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

the class MaterialRegistryExtension method beforeEach.

@Override
public void beforeEach(ExtensionContext context) {
    Map<IMaterial, List<IMaterialStats>> materialSetup = MaterialFixture.ALL_MATERIAL_FIXTURES;
    Map<MaterialId, IMaterial> materials = materialSetup.keySet().stream().collect(Collectors.toMap(IMaterial::getIdentifier, Function.identity()));
    Map<MaterialId, Map<MaterialStatsId, IMaterialStats>> stats = materialSetup.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey().getIdentifier(), entry -> entry.getValue().stream().collect(Collectors.toMap(IMaterialStats::getIdentifier, Function.identity()))));
    Map<MaterialStatsId, IMaterialStats> defaultStats = MaterialStatsFixture.TIC_DEFAULT_STATS.stream().collect(Collectors.toMap(IMaterialStats::getIdentifier, Function.identity()));
    // empty map as nothing using the extension uses traits
    materialRegistry = new MaterialRegistryFixture(materials, stats, defaultStats, Collections.emptyMap());
    MaterialRegistry.INSTANCE = new MaterialRegistry(materialRegistry);
}
Also used : MaterialStatsId(slimeknights.tconstruct.library.materials.stats.MaterialStatsId) MaterialFixture(slimeknights.tconstruct.fixture.MaterialFixture) ParameterResolutionException(org.junit.jupiter.api.extension.ParameterResolutionException) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ParameterContext(org.junit.jupiter.api.extension.ParameterContext) MaterialRegistryFixture(slimeknights.tconstruct.fixture.MaterialRegistryFixture) List(java.util.List) MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) AfterAllCallback(org.junit.jupiter.api.extension.AfterAllCallback) Map(java.util.Map) BeforeEachCallback(org.junit.jupiter.api.extension.BeforeEachCallback) IMaterialStats(slimeknights.tconstruct.library.materials.stats.IMaterialStats) ParameterResolver(org.junit.jupiter.api.extension.ParameterResolver) MaterialStatsFixture(slimeknights.tconstruct.fixture.MaterialStatsFixture) Collections(java.util.Collections) IMaterial(slimeknights.tconstruct.library.materials.definition.IMaterial) Mockito.mock(org.mockito.Mockito.mock) IMaterial(slimeknights.tconstruct.library.materials.definition.IMaterial) MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) MaterialRegistryFixture(slimeknights.tconstruct.fixture.MaterialRegistryFixture) MaterialStatsId(slimeknights.tconstruct.library.materials.stats.MaterialStatsId) IMaterialStats(slimeknights.tconstruct.library.materials.stats.IMaterialStats) List(java.util.List) Map(java.util.Map)

Example 22 with MaterialId

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

the class MaterialStatsManagerTest method testLoadFileWithEmptyStats_ok.

@Test
void testLoadFileWithEmptyStats_ok() {
    MaterialId material = new MaterialId(TConstruct.getResource("empty"));
    fileLoader.loadAndParseFiles(null, material);
    // ensure that we get this far and that querying the missing material causes no errors
    Optional<ComplexTestStats> optionalStats = materialStatsManager.getStats(material, STATS_ID_DONT_CARE);
    assertThat(optionalStats).isEmpty();
}
Also used : MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) Test(org.junit.jupiter.api.Test) BaseMcTest(slimeknights.tconstruct.test.BaseMcTest)

Example 23 with MaterialId

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

the class MaterialStatsManagerTest method testLoadFile_statsExist.

@Test
void testLoadFile_statsExist() {
    materialStatsManager.registerMaterialStat(DEFAULT, ComplexTestStats.class, ComplexTestStats::new);
    MaterialId material = new MaterialId(TConstruct.getResource("teststat"));
    fileLoader.loadAndParseFiles(null, material);
    Optional<BaseMaterialStats> optionalStats = materialStatsManager.getStats(material, STATS_ID_SIMPLE);
    assertThat(optionalStats).isPresent();
}
Also used : MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) Test(org.junit.jupiter.api.Test) BaseMcTest(slimeknights.tconstruct.test.BaseMcTest)

Example 24 with MaterialId

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

the class MaterialStatsManagerTest method testLoadFile_complexStats.

@Test
void testLoadFile_complexStats() {
    materialStatsManager.registerMaterialStat(DEFAULT, ComplexTestStats.class, ComplexTestStats::new);
    MaterialId material = new MaterialId(TConstruct.getResource("teststat"));
    fileLoader.loadAndParseFiles(null, material);
    Optional<ComplexTestStats> optionalStats = materialStatsManager.getStats(material, STATS_ID_SIMPLE);
    assertThat(optionalStats).isPresent();
    ComplexTestStats stats = optionalStats.get();
    assertThat(stats.getNum()).isEqualTo(123);
    assertThat(stats.getFloating()).isEqualTo(12.34f);
    assertThat(stats.getText()).isEqualTo("why would you ever do this for stats");
}
Also used : MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) Test(org.junit.jupiter.api.Test) BaseMcTest(slimeknights.tconstruct.test.BaseMcTest)

Example 25 with MaterialId

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

the class MaterialStatsManagerTest method testLoadMultipleFiles_addDifferentStatsToSameMaterial.

@Test
void testLoadMultipleFiles_addDifferentStatsToSameMaterial() {
    MaterialStatsId otherStatId = new MaterialStatsId("test", "otherstat");
    materialStatsManager.registerMaterialStat(DEFAULT, ComplexTestStats.class, ComplexTestStats::new);
    materialStatsManager.registerMaterialStat(new ComplexTestStats(otherStatId, 5, 8, "other"), ComplexTestStats.class, ComplexTestStats::new);
    MaterialId material = new MaterialId(TConstruct.getResource("teststat"));
    fileLoader.loadAndParseFiles("extrastats", material);
    assertThat(materialStatsManager.getStats(material, STATS_ID_SIMPLE)).isNotEmpty();
    assertThat(materialStatsManager.getStats(material, otherStatId)).isNotEmpty();
}
Also used : MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) Test(org.junit.jupiter.api.Test) BaseMcTest(slimeknights.tconstruct.test.BaseMcTest)

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