Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/com/hfstudio/guidenh/guide/GuidePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;
import java.util.Set;

import net.minecraft.client.resources.IResourcePack;
import net.minecraft.util.ResourceLocation;

import org.jetbrains.annotations.Nullable;
Expand All @@ -21,6 +22,8 @@
public class GuidePage {

private final String sourcePack;
@Nullable
private final IResourcePack sourceResourcePack;
private final ResourceLocation id;
private final LytDocument document;
private final List<LytGuidebookScene> scenes;
Expand All @@ -41,7 +44,13 @@ public GuidePage(String sourcePack, ResourceLocation id, LytDocument document, @

public GuidePage(String sourcePack, ResourceLocation id, LytDocument document, @Nullable LytHeading titleHeading,
@Nullable FrontmatterPageMeta pageMeta) {
this(sourcePack, null, id, document, titleHeading, pageMeta);
}

public GuidePage(String sourcePack, @Nullable IResourcePack sourceResourcePack, ResourceLocation id,
LytDocument document, @Nullable LytHeading titleHeading, @Nullable FrontmatterPageMeta pageMeta) {
this.sourcePack = sourcePack;
this.sourceResourcePack = sourceResourcePack;
this.id = id;
this.document = document;
this.titleHeading = titleHeading;
Expand All @@ -56,6 +65,10 @@ public String sourcePack() {
return sourcePack;
}

public @Nullable IResourcePack sourceResourcePack() {
return sourceResourcePack;
}

public ResourceLocation id() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.minecraft.client.resources.IResourcePack;
import net.minecraft.util.ResourceLocation;

import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -295,10 +296,16 @@ public static MdAstRoot buildErrorPage(String headingText, String errorText) {

public static GuidePage buildErrorGuidePage(PageCollection pages, ExtensionCollection extensions, String sourcePack,
ResourceLocation id, String pageContent, String headingText, String errorText) {
return buildErrorGuidePage(pages, extensions, sourcePack, null, id, pageContent, headingText, errorText);
}

public static GuidePage buildErrorGuidePage(PageCollection pages, ExtensionCollection extensions, String sourcePack,
@Nullable IResourcePack sourceResourcePack, ResourceLocation id, String pageContent, String headingText,
String errorText) {
var errorRoot = buildErrorPage(headingText, errorText);
var document = new PageCompiler(pages, extensions, sourcePack, id, pageContent).compile(errorRoot);
var titleHeading = extractPageTitleHeading(document);
return new GuidePage(sourcePack, id, document, titleHeading);
return new GuidePage(sourcePack, sourceResourcePack, id, document, titleHeading, null);
}

public static GuidePage compile(PageCollection pages, ExtensionCollection extensions, ParsedGuidePage parsedPage) {
Expand All @@ -314,7 +321,13 @@ public static GuidePage compile(PageCollection pages, ExtensionCollection extens
FrontmatterPageMeta pageMeta = parsedPage.getFrontmatter() != null ? parsedPage.getFrontmatter()
.parseMeta() : null;
if (pageMeta != null && pageMeta.isEmpty()) pageMeta = null;
return new GuidePage(parsedPage.getSourcePack(), parsedPage.getId(), document, titleHeading, pageMeta);
return new GuidePage(
parsedPage.getSourcePack(),
parsedPage.getSourceResourcePack(),
parsedPage.getId(),
document,
titleHeading,
pageMeta);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Objects;

import net.minecraft.client.resources.IResourcePack;
import net.minecraft.util.ResourceLocation;

import org.jetbrains.annotations.Nullable;
Expand All @@ -15,6 +16,16 @@ public class ParsedGuidePage {

@Getter
private final String sourcePack;
/**
* The exact resource pack selected while loading this page, when it originated from a resource pack.
*
* <p>
* The textual source identifier remains useful for compiler identity, but it only contains a namespace and
* cannot identify which of several packs supplied the page.
* </p>
*/
@Getter
private final @Nullable IResourcePack sourceResourcePack;
@Getter
private final ResourceLocation id;
@Getter
Expand Down Expand Up @@ -47,7 +58,25 @@ public ParsedGuidePage(String sourcePack, ResourceLocation id, String source, Md
public ParsedGuidePage(String sourcePack, ResourceLocation id, String source, MdAstRoot astRoot,
Frontmatter frontmatter, String language, @Nullable String parseFailureMessage,
@Nullable UnistPoint parseFailureFrom, @Nullable UnistPoint parseFailureTo) {
this(
sourcePack,
null,
id,
source,
astRoot,
frontmatter,
language,
parseFailureMessage,
parseFailureFrom,
parseFailureTo);
}

public ParsedGuidePage(String sourcePack, @Nullable IResourcePack sourceResourcePack, ResourceLocation id,
String source, MdAstRoot astRoot, Frontmatter frontmatter, String language,
@Nullable String parseFailureMessage, @Nullable UnistPoint parseFailureFrom,
@Nullable UnistPoint parseFailureTo) {
this.sourcePack = sourcePack;
this.sourceResourcePack = sourceResourcePack;
this.id = id;
this.source = source;
this.astRoot = astRoot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ private static ParsedGuidePage parsePageBytes(String sourcePack, String language
};
return new LazyParsedGuidePage(
sourcePack,
selected.pack(),
pageId,
frontmatter.getFrontmatter(),
frontmatter.getLanguage(),
Expand Down
39 changes: 14 additions & 25 deletions src/main/java/com/hfstudio/guidenh/guide/internal/GuideScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -4019,7 +4019,7 @@ private String buildBottomBarText(@Nullable FrontmatterPageMeta meta) {
FontRenderer fr = mc.fontRenderer;
int maxW = (int) (this.width * 0.8);

String sourceDisplay = getSourceDisplayName(currentPage.sourcePack());
String sourceDisplay = getSourceDisplayName(currentPage.sourcePack(), currentPage.sourceResourcePack());
List<String> authors = meta != null ? meta.authors() : List.of();
String dateVal = meta != null ? meta.date() : null;
String updatedVal = meta != null ? meta.updated() : null;
Expand Down Expand Up @@ -4109,33 +4109,15 @@ private static String truncateStringToWidth(FontRenderer fr, String text, int ma
return text;
}

private static String getSourceDisplayName(String sourcePack) {
private static String getSourceDisplayName(String sourcePack, @Nullable IResourcePack sourceResourcePack) {
if (sourceResourcePack != null) {
return formatResourcePackName(sourceResourcePack.getPackName());
}

int colon = sourcePack.indexOf(':');
String prefix = colon >= 0 ? sourcePack.substring(0, colon) : "";
String namespace = colon >= 0 ? sourcePack.substring(colon + 1) : sourcePack;

if ("resources".equals(prefix)) {
try {
var entries = Minecraft.getMinecraft()
.getResourcePackRepository()
.getRepositoryEntries();
for (int i = entries.size() - 1; i >= 0; i--) {
var pack = entries.get(i)
.getResourcePack();
if (pack != null && pack.getResourceDomains()
.contains(namespace)) {
String packName = pack.getPackName();
if (packName.length() > 4 && packName.substring(packName.length() - 4)
.equalsIgnoreCase(".zip")) {
packName = packName.substring(0, packName.length() - 4);
}
return packName;
}
}
} catch (Throwable ignored) {}
}

// For "development:" or no matching user resource pack: fall back to FML mod name
// Pages constructed outside a resource-pack load keep their existing mod-name fallback.
try {
var mod = Loader.instance()
.getIndexedModList()
Expand All @@ -4147,6 +4129,13 @@ private static String getSourceDisplayName(String sourcePack) {
return namespace;
}

private static String formatResourcePackName(String packName) {
if (packName.length() > 4 && packName.regionMatches(true, packName.length() - 4, ".zip", 0, 4)) {
return packName.substring(0, packName.length() - 4);
}
return packName;
}

private void drawPageTitle() {
if (currentAnchor == null && !isExactHomeRoute() || isSearchPage()) return;
if (pageTitle.isEmpty()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Objects;
import java.util.function.Supplier;

import net.minecraft.client.resources.IResourcePack;
import net.minecraft.util.ResourceLocation;

import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -60,7 +61,34 @@ public LazyParsedGuidePage(String sourcePack, ResourceLocation id, Frontmatter f
public LazyParsedGuidePage(String sourcePack, ResourceLocation id, Frontmatter frontmatter, String language,
@Nullable String parseFailureMessage, @Nullable UnistPoint parseFailureFrom,
@Nullable UnistPoint parseFailureTo, Supplier<String> sourceLoader, @Nullable String sourceFingerprint) {
super(sourcePack, id, "", null, frontmatter, language, parseFailureMessage, parseFailureFrom, parseFailureTo);
this(
sourcePack,
null,
id,
frontmatter,
language,
parseFailureMessage,
parseFailureFrom,
parseFailureTo,
sourceLoader,
sourceFingerprint);
}

public LazyParsedGuidePage(String sourcePack, @Nullable IResourcePack sourceResourcePack, ResourceLocation id,
Frontmatter frontmatter, String language, @Nullable String parseFailureMessage,
@Nullable UnistPoint parseFailureFrom, @Nullable UnistPoint parseFailureTo, Supplier<String> sourceLoader,
@Nullable String sourceFingerprint) {
super(
sourcePack,
sourceResourcePack,
id,
"",
null,
frontmatter,
language,
parseFailureMessage,
parseFailureFrom,
parseFailureTo);
this.sourceLoader = Objects.requireNonNull(sourceLoader, "sourceLoader");
this.sourceFingerprint = sourceFingerprint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ private GuidePage buildFailurePage(ParsedGuidePage parsedPage, @Nullable GuidePa
this,
extensions,
parsedPage.getSourcePack(),
parsedPage.getSourceResourcePack(),
parsedPage.getId(),
parsedPage.getSource(),
effectiveFailure.headingText,
Expand Down