use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class MaterialTraitsManager method finishLoad.
@Override
protected void finishLoad(Map<ResourceLocation, MaterialTraits.Builder> map, ResourceManager manager) {
ImmutableMap.Builder<MaterialId, MaterialTraits> builder = ImmutableMap.builder();
for (Entry<ResourceLocation, MaterialTraits.Builder> entry : map.entrySet()) {
MaterialTraits traits = entry.getValue().build();
builder.put(new MaterialId(entry.getKey()), traits);
log.debug("Loaded traits for material '{}': \n\tDefault - {}{}", entry.getKey(), Arrays.toString(traits.getDefaultTraits().toArray()), Util.toIndentedStringList(traits.getTraitsPerStats().entrySet().stream().map(entry2 -> String.format("%s - %s", entry2.getKey(), Arrays.toString(entry2.getValue().toArray()))).collect(Collectors.toList())));
}
materialTraits = builder.build();
onLoaded.run();
}
use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class UpdateMaterialTraitsPacketTest method testGenericEncodeDecode.
@Test
void testGenericEncodeDecode() {
List<ModifierEntry> defaultTraits1 = Arrays.asList(new ModifierEntry(ModifierFixture.TEST_MODIFIER_1, 1), new ModifierEntry(ModifierFixture.TEST_MODIFIER_2, 2));
MaterialTraits materialTraits1 = new MaterialTraits(defaultTraits1, Collections.emptyMap());
List<ModifierEntry> defaultTraits2 = Collections.singletonList(new ModifierEntry(ModifierFixture.TEST_MODIFIER_1, 3));
Map<MaterialStatsId, List<ModifierEntry>> statsTraits2 = new HashMap<>();
statsTraits2.put(MaterialStatsFixture.STATS_TYPE, Arrays.asList(new ModifierEntry(ModifierFixture.TEST_MODIFIER_1, 4), new ModifierEntry(ModifierFixture.TEST_MODIFIER_2, 5)));
statsTraits2.put(MaterialStatsFixture.STATS_TYPE_2, Collections.singletonList(new ModifierEntry(ModifierFixture.TEST_MODIFIER_2, 6)));
MaterialTraits materialTraits2 = new MaterialTraits(defaultTraits2, statsTraits2);
Map<MaterialId, MaterialTraits> map = new HashMap<>();
map.put(MATERIAL_ID_1, materialTraits1);
map.put(MATERIAL_ID_2, materialTraits2);
// send a packet over the buffer
FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer());
UpdateMaterialTraitsPacket packetToEncode = new UpdateMaterialTraitsPacket(map);
packetToEncode.encode(buffer);
UpdateMaterialTraitsPacket decoded = new UpdateMaterialTraitsPacket(buffer);
// parse results
Map<MaterialId, MaterialTraits> parsed = decoded.getMaterialToTraits();
assertThat(parsed).hasSize(2);
// material traits 1
MaterialTraits parsedTraits1 = parsed.get(MATERIAL_ID_1);
assertThat(parsedTraits1).isNotNull();
// default
assertThat(parsedTraits1.getDefaultTraits()).hasSize(2);
ModifierEntry trait1 = parsedTraits1.getDefaultTraits().get(0);
assertThat(trait1.getModifier()).isEqualTo(ModifierFixture.TEST_MODIFIER_1);
assertThat(trait1.getLevel()).isEqualTo(1);
ModifierEntry trait2 = parsedTraits1.getDefaultTraits().get(1);
assertThat(trait2.getModifier()).isEqualTo(ModifierFixture.TEST_MODIFIER_2);
assertThat(trait2.getLevel()).isEqualTo(2);
// per stat
assertThat(parsedTraits1.getTraitsPerStats()).isEmpty();
// material traits 2
MaterialTraits parsedTraits2 = parsed.get(MATERIAL_ID_2);
assertThat(parsedTraits2).isNotNull();
// default
assertThat(parsedTraits2.getDefaultTraits()).hasSize(1);
trait1 = parsedTraits2.getDefaultTraits().get(0);
assertThat(trait1.getModifier()).isEqualTo(ModifierFixture.TEST_MODIFIER_1);
assertThat(trait1.getLevel()).isEqualTo(3);
// per stat type
assertThat(parsedTraits2.getTraitsPerStats()).hasSize(2);
// stat type 1
List<ModifierEntry> traitsForStats1 = parsedTraits2.getTraits(MaterialStatsFixture.STATS_TYPE);
assertThat(traitsForStats1).isNotNull();
assertThat(traitsForStats1).hasSize(2);
trait1 = traitsForStats1.get(0);
assertThat(trait1.getModifier()).isEqualTo(ModifierFixture.TEST_MODIFIER_1);
assertThat(trait1.getLevel()).isEqualTo(4);
trait2 = traitsForStats1.get(1);
assertThat(trait2.getModifier()).isEqualTo(ModifierFixture.TEST_MODIFIER_2);
assertThat(trait2.getLevel()).isEqualTo(5);
// stat type 2
List<ModifierEntry> traitsForStats2 = parsedTraits2.getTraits(MaterialStatsFixture.STATS_TYPE_2);
assertThat(traitsForStats2).isNotNull();
assertThat(traitsForStats2).hasSize(1);
trait1 = traitsForStats2.get(0);
assertThat(trait1.getModifier()).isEqualTo(ModifierFixture.TEST_MODIFIER_2);
assertThat(trait1.getLevel()).isEqualTo(6);
}
use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class MaterialStatsManagerTest method loadMissingFile_ignored.
@Test
void loadMissingFile_ignored() {
MaterialId material = new MaterialId(TConstruct.getResource("nonexistant"));
fileLoader.loadAndParseFiles(null);
// 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();
}
use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class MaterialStatsManagerTest method testLoadFileWithoutStats_ok.
@Test
void testLoadFileWithoutStats_ok() {
MaterialId material = new MaterialId(TConstruct.getResource("missing_stats"));
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();
}
use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class MaterialStatsManagerTest method testLoadMultipleFiles_addSameStatsFromDifferentSources_useFirst.
// Tests the behaviour when multiple mods try to add the same material
// the top data pack should override lower ones, meaning the duplicate stats are kept
@Test
void testLoadMultipleFiles_addSameStatsFromDifferentSources_useFirst() {
materialStatsManager.registerMaterialStat(DEFAULT, ComplexTestStats.class, ComplexTestStats::new);
MaterialId material = new MaterialId(TConstruct.getResource("teststat"));
fileLoader.loadAndParseFiles("duplicate", material);
Optional<ComplexTestStats> stats = materialStatsManager.getStats(material, STATS_ID_SIMPLE);
assertThat(stats).isNotEmpty();
// top pack value replaces the bottom one
assertThat(stats.get().getNum()).isEqualTo(321);
// top pack unspecified value defaults to the bottom one
assertThat(stats.get().getFloating()).isCloseTo(12.34f, Offset.strictOffset(0.01f));
}
Aggregations