use of slimeknights.tconstruct.library.materials.stats.IMaterialStats in project TinkersConstruct by SlimeKnights.
the class ToolBuildHandler method randomMaterials.
/**
* Gets a list of random materials consistent with the given tool definition data
* @param data Data, primarily used for part requirements
* @param maxTier Max tier of material allowed
* @param allowHidden If true, hidden materials may be used
* @return List of random materials
*/
public static MaterialNBT randomMaterials(ToolDefinitionData data, int maxTier, boolean allowHidden) {
// start by getting a list of materials for each stat type we need
List<PartRequirement> requirements = data.getParts();
// figure out which stat types we need
Map<MaterialStatsId, List<IMaterial>> materialChoices = requirements.stream().map(PartRequirement::getStatType).distinct().collect(Collectors.toMap(Function.identity(), t -> new ArrayList<>()));
IMaterialRegistry registry = MaterialRegistry.getInstance();
registry.getAllMaterials().stream().filter(mat -> (allowHidden || !mat.isHidden()) && mat.getTier() <= maxTier).forEach(mat -> {
for (IMaterialStats stats : registry.getAllStats(mat.getIdentifier())) {
List<IMaterial> list = materialChoices.get(stats.getIdentifier());
if (list != null) {
list.add(mat);
}
}
});
// then randomly choose a material from the lists for each part
MaterialNBT.Builder builder = MaterialNBT.builder();
for (PartRequirement requirement : requirements) {
// if the list has no materials for some reason, skip, null should be impossible but might as well be safe
List<IMaterial> choices = materialChoices.get(requirement.getStatType());
if (choices == null || choices.isEmpty()) {
builder.add(MaterialVariant.UNKNOWN);
TConstruct.LOG.error("Failed to find a {} material of type {} below tier {}", allowHidden ? "non-hidden " : "", requirement.getStatType(), maxTier);
} else {
builder.add(choices.get(TConstruct.RANDOM.nextInt(choices.size())));
}
}
return builder.build();
}
use of slimeknights.tconstruct.library.materials.stats.IMaterialStats in project TinkersConstruct by SlimeKnights.
the class PartBuilderScreen method setDisplayForMaterial.
/**
* Updates the data in the material display
* @param materialRecipe New material recipe
*/
private void setDisplayForMaterial(MaterialRecipe materialRecipe) {
MaterialVariant materialVariant = materialRecipe.getMaterial();
this.infoPanelScreen.setCaption(MaterialTooltipCache.getColoredDisplayName(materialVariant.getVariant()));
// determine how much material we have
// get exact number of material, rather than rounded
float value = materialRecipe.getMaterialValue(this.tile.getInventoryWrapper());
MutableComponent formatted = new TextComponent(Util.COMMA_FORMAT.format(value));
// if we have a part recipe, mark material red when not enough
IPartBuilderRecipe partRecipe = this.tile.getPartRecipe();
if (partRecipe != null && value < partRecipe.getCost()) {
formatted = formatted.withStyle(ChatFormatting.DARK_RED);
}
this.infoPanelScreen.setMaterialValue(formatted);
// update stats and traits
List<Component> stats = Lists.newLinkedList();
List<Component> tips = Lists.newArrayList();
// add warning that the material is uncraftable
if (!materialVariant.get().isCraftable()) {
stats.add(UNCRAFTABLE_MATERIAL);
stats.add(TextComponent.EMPTY);
tips.add(UNCRAFTABLE_MATERIAL_TOOLTIP);
tips.add(TextComponent.EMPTY);
}
MaterialId id = materialVariant.getId();
for (IMaterialStats stat : MaterialRegistry.getInstance().getAllStats(id)) {
List<Component> info = stat.getLocalizedInfo();
if (!info.isEmpty()) {
stats.add(stat.getLocalizedName().withStyle(ChatFormatting.UNDERLINE));
tips.add(TextComponent.EMPTY);
stats.addAll(info);
tips.addAll(stat.getLocalizedDescriptions());
List<ModifierEntry> traits = MaterialRegistry.getInstance().getTraits(id, stat.getIdentifier());
if (!traits.isEmpty()) {
for (ModifierEntry trait : traits) {
Modifier mod = trait.getModifier();
stats.add(mod.getDisplayName(trait.getLevel()));
tips.add(mod.getDescription(trait.getLevel()));
}
}
stats.add(TextComponent.EMPTY);
tips.add(TextComponent.EMPTY);
}
}
// remove last line if empty
if (!stats.isEmpty() && stats.get(stats.size() - 1).getString().isEmpty()) {
stats.remove(stats.size() - 1);
tips.remove(tips.size() - 1);
}
this.infoPanelScreen.setText(stats, tips);
}
use of slimeknights.tconstruct.library.materials.stats.IMaterialStats 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);
}
Aggregations