Search in sources :

Example 36 with MaterialId

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());
        }
    }
}
Also used : MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) MaterialVariantId(slimeknights.tconstruct.library.materials.definition.MaterialVariantId)

Example 37 with MaterialId

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;
                    }
                }
            }
        }
    }
}
Also used : IMaterial(slimeknights.tconstruct.library.materials.definition.IMaterial) MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) MaterialVariantId(slimeknights.tconstruct.library.materials.definition.MaterialVariantId)

Example 38 with MaterialId

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
}
Also used : IMaterial(slimeknights.tconstruct.library.materials.definition.IMaterial) MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) MaterialVariantId(slimeknights.tconstruct.library.materials.definition.MaterialVariantId) ModifierEntry(slimeknights.tconstruct.library.modifiers.ModifierEntry) TooltipKey(slimeknights.tconstruct.library.utils.TooltipKey)

Example 39 with MaterialId

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));
    }
}
Also used : MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) TextElement(slimeknights.mantle.client.screen.book.element.TextElement) MaterialVariantId(slimeknights.tconstruct.library.materials.definition.MaterialVariantId) TextData(slimeknights.mantle.client.book.data.element.TextData)

Example 40 with MaterialId

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();
        }
    }
}
Also used : ItemElement(slimeknights.mantle.client.screen.book.element.ItemElement) IMaterial(slimeknights.tconstruct.library.materials.definition.IMaterial) ContentPageIconList(slimeknights.tconstruct.library.client.book.content.ContentPageIconList) MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) PageData(slimeknights.mantle.client.book.data.PageData) SizedBookElement(slimeknights.mantle.client.screen.book.element.SizedBookElement) ContentMaterial(slimeknights.tconstruct.library.client.book.content.ContentMaterial)

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