use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class MaterialItem method verifyTagAfterLoad.
@Override
public void verifyTagAfterLoad(CompoundTag nbt) {
// if the material exists and was changed, update it
MaterialVariantId id = getMaterialId(nbt);
if (!id.equals(IMaterial.UNKNOWN_ID)) {
MaterialId original = id.getId();
MaterialId resolved = MaterialRegistry.getInstance().resolve(original);
if (original != resolved) {
nbt.putString(NBTTags.PART_MATERIAL, MaterialVariantId.create(resolved, id.getVariant()).toString());
}
}
}
use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class MaterialItem method fillItemCategory.
@Override
public void fillItemCategory(CreativeModeTab group, NonNullList<ItemStack> items) {
if (this.allowdedIn(group) && MaterialRegistry.isFullyLoaded()) {
// if a specific material is set in the config, try adding that
String showOnlyId = Config.COMMON.showOnlyPartMaterial.get();
boolean added = false;
if (!showOnlyId.isEmpty()) {
MaterialVariantId materialId = MaterialVariantId.tryParse(showOnlyId);
if (materialId != null && canUseMaterial(materialId.getId())) {
items.add(this.withMaterialForDisplay(materialId));
added = true;
}
}
// if no material is set or we failed to find it, iterate all materials
if (!added) {
for (IMaterial material : MaterialRegistry.getInstance().getVisibleMaterials()) {
MaterialId id = material.getIdentifier();
if (this.canUseMaterial(id)) {
items.add(this.withMaterial(id));
// if a specific material was requested and not found, stop after first
if (!showOnlyId.isEmpty()) {
break;
}
}
}
}
}
}
use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class ToolPartItem method appendHoverText.
@Override
public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
if (TooltipUtil.isDisplay(stack)) {
return;
}
// add all traits to the info
MaterialVariantId materialVariant = this.getMaterial(stack);
MaterialId id = materialVariant.getId();
if (!materialVariant.equals(IMaterial.UNKNOWN_ID)) {
if (canUseMaterial(id)) {
for (ModifierEntry entry : MaterialRegistry.getInstance().getTraits(id, getStatType())) {
tooltip.add(entry.getModifier().getDisplayName(entry.getLevel()));
}
// add stats
if (Config.CLIENT.extraToolTips.get()) {
TooltipKey key = SafeClientAccess.getTooltipKey();
if (key == TooltipKey.SHIFT || key == TooltipKey.UNKNOWN) {
this.addStatInfoTooltip(id, tooltip);
} else {
// info tooltip for detailed and component info
tooltip.add(TextComponent.EMPTY);
tooltip.add(TooltipUtil.TOOLTIP_HOLD_SHIFT);
}
}
} else {
// is the material missing, or is it not valid for this stat type?
IMaterial material = MaterialRegistry.getMaterial(id);
if (material == IMaterial.UNKNOWN) {
tooltip.add(new TranslatableComponent(MISSING_MATERIAL_KEY, id));
} else {
tooltip.add(new TranslatableComponent(MISSING_STATS_KEY, materialStatId).withStyle(ChatFormatting.GRAY));
}
}
}
// mod handled by getCreatorModId
}
use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class ContentMaterialSkull method build.
@Override
public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) {
MaterialVariantId materialVariant = getMaterialVariant();
this.addTitle(list, getTitle(), true, MaterialTooltipCache.getColor(materialVariant).getValue());
// the cool tools to the left/right
this.addDisplayItems(list, rightSide ? BookScreen.PAGE_WIDTH - 18 : 0, materialVariant);
// align page
int top = getTitleHeight();
int left = rightSide ? 0 : 22;
int y = top + 5;
int x = left + 5;
int w = BookScreen.PAGE_WIDTH - 20;
// skull stats, full width
MaterialId materialId = materialVariant.getId();
int skullTraits = this.addStatsDisplay(x, y, w, list, materialId, SkullStats.ID);
y += 65;
// inspirational quote, or boring description text
String textKey = String.format(detailed ? "material.%s.%s.skull_encyclopedia" : "material.%s.%s.skull_flavor", materialId.getNamespace(), materialId.getPath());
if (I18n.exists(textKey)) {
// using forge instead of I18n.format as that prevents % from being interpreted as a format key
String translated = ForgeI18n.getPattern(textKey);
if (!detailed) {
translated = '"' + translated + '"';
}
TextData flavourData = new TextData(translated);
flavourData.italic = !detailed;
list.add(new TextElement(x, y + 10 * skullTraits, w, 60, flavourData));
}
}
use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class AbstractMaterialSectionTransformer method transform.
@Override
public void transform(BookData book, SectionData sectionData) {
sectionData.source = BookRepository.DUMMY;
sectionData.parent = book;
List<IMaterial> materialList = MaterialRegistry.getMaterials().stream().filter(this::isValidMaterial).toList();
if (materialList.isEmpty()) {
return;
}
// calculate pages needed
List<ContentPageIconList> listPages = ContentPageIconList.getPagesNeededForItemCount(materialList.size(), sectionData, book.translate(this.sectionName), book.strings.get(String.format("%s.subtext", this.sectionName)));
ListIterator<ContentPageIconList> iter = listPages.listIterator();
ContentPageIconList overview = iter.next();
for (IMaterial material : materialList) {
MaterialId materialId = material.getIdentifier();
ContentMaterial contentMaterial = this.getPageContent(materialId);
PageData page = this.addPage(sectionData, materialId.toString(), ContentMaterial.ID, contentMaterial);
SizedBookElement icon = new ItemElement(0, 0, 1f, contentMaterial.getDisplayStacks());
while (!overview.addLink(icon, contentMaterial.getTitleComponent(), page)) {
overview = iter.next();
}
}
}
Aggregations