Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master-1.20-lts' into master-1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Jun 21, 2024
2 parents aef0f1f + bcdd368 commit 6b53115
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 15 deletions.
6 changes: 6 additions & 0 deletions resources/changelog/1.18.2-1.17.10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
As always, don't forget to backup your world before updating!

Fixes:
* Fix infobook sections from other mods linking to wrong URL
Closes CyclopsMC/IntegratedDynamics#1338

6 changes: 6 additions & 0 deletions resources/changelog/1.19.2-1.19.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
As always, don't forget to backup your world before updating!

Fixes:
* Fix infobook sections from other mods linking to wrong URL
Closes CyclopsMC/IntegratedDynamics#1338

6 changes: 6 additions & 0 deletions resources/changelog/1.20.1-1.19.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
As always, don't forget to backup your world before updating!

Fixes:
* Fix infobook sections from other mods linking to wrong URL
Closes CyclopsMC/IntegratedDynamics#1338

34 changes: 24 additions & 10 deletions src/main/java/org/cyclops/cyclopscore/infobook/InfoBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ public class InfoBookParser {
public InfoSection create(IInfoBook infoBook, InfoSection parent, int childIndex, String translationKey,
ArrayList<String> paragraphs, List<SectionAppendix> appendixes,
ArrayList<String> tagList) {
return new InfoSection(infoBook, parent, childIndex, translationKey, paragraphs, appendixes, tagList);
return this.create(infoBook, parent, childIndex, translationKey, paragraphs, appendixes, tagList, null);
}

@Override
public InfoSection create(IInfoBook infoBook, InfoSection parent, int childIndex, String translationKey,
ArrayList<String> paragraphs, List<SectionAppendix> appendixes,
ArrayList<String> tagList, ModBase<?> mod) {
return new InfoSection(infoBook, parent, childIndex, translationKey, paragraphs, appendixes, tagList, mod);
}

});
Expand Down Expand Up @@ -554,10 +561,10 @@ public static InfoSection initializeInfoBook(ModBase<?> mod, IInfoBook infoBook,
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(stream.getInputStream());
InfoSection root = buildSection(infoBook, parent, 0, doc.getDocumentElement());
InfoSection root = buildSection(infoBook, parent, 0, doc.getDocumentElement(), mod);
InfoSectionTagIndex tagIndex;
if (parent == null) {
tagIndex = new InfoSectionTagIndex(infoBook, root);
tagIndex = new InfoSectionTagIndex(infoBook, root, mod);
root.registerSection(tagIndex);
infoBook.putIndex(tagIndex);
} else {
Expand All @@ -571,8 +578,8 @@ public static InfoSection initializeInfoBook(ModBase<?> mod, IInfoBook infoBook,
throw new InfoBookException("Info Book XML is invalid.");
}

protected static InfoSection buildSection(IInfoBook infoBook, InfoSection parent, int childIndex, Element sectionElement) {
ModBase mod = infoBook.getMod();
protected static InfoSection buildSection(IInfoBook infoBook, InfoSection parent, int childIndex, Element sectionElement, ModBase<?> modSection) {
ModBase modBook = infoBook.getMod();
NodeList sections = sectionElement.getElementsByTagName("section");
NodeList tags = sectionElement.getElementsByTagName("tag");
NodeList paragraphs = sectionElement.getElementsByTagName("paragraph");
Expand All @@ -583,15 +590,15 @@ protected static InfoSection buildSection(IInfoBook infoBook, InfoSection parent
ArrayList<String> tagList = Lists.newArrayListWithCapacity(tags.getLength());
String sectionName = sectionElement.getAttribute("name");
InfoSection section = createSection(infoBook, parent, childIndex, sectionElement.getAttribute("type"),
sectionName, paragraphList, appendixList, tagList);
sectionName, paragraphList, appendixList, tagList, modSection);
infoBook.addSection(sectionName, section);

if(sections.getLength() > 0) {
int subChildIndex = 0;
for (int i = 0; i < sections.getLength(); i++) {
Element subsection = (Element) sections.item(i);
if(subsection.getParentNode() == sectionElement) {
InfoSection subsubsection = buildSection(infoBook, section, subChildIndex, subsection);
InfoSection subsubsection = buildSection(infoBook, section, subChildIndex, subsection, modSection);
if(subsubsection != null) {
section.registerSection(subsubsection);
subChildIndex++;
Expand All @@ -607,7 +614,7 @@ protected static InfoSection buildSection(IInfoBook infoBook, InfoSection parent
type = tag.getAttribute("type");
}

ModBase modRecipe = mod;
ModBase modRecipe = modBook;
if (tagString.contains(":")) {
String[] split = tagString.split(":");
modRecipe = ModBase.get(split[0]);
Expand Down Expand Up @@ -663,13 +670,13 @@ protected static InfoSection buildSection(IInfoBook infoBook, InfoSection parent

protected static InfoSection createSection(IInfoBook infoBook, InfoSection parent, int childIndex, String type, String translationKey,
ArrayList<String> paragraphs, List<SectionAppendix> appendixes,
ArrayList<String> tagList) {
ArrayList<String> tagList, ModBase<?> mod) {
if(type == null) type = "";
IInfoSectionFactory factory = SECTION_FACTORIES.get(type);
if(factory == null) {
throw new InfoBookException("No section of type '" + type + "' was found.");
}
return factory.create(infoBook, parent, childIndex, translationKey, paragraphs, appendixes, tagList);
return factory.create(infoBook, parent, childIndex, translationKey, paragraphs, appendixes, tagList, mod);
}

protected static SectionAppendix createAppendix(IInfoBook infoBook, String type, Element node) throws InvalidAppendixException {
Expand Down Expand Up @@ -713,10 +720,17 @@ protected static IReward createReward(IInfoBook infoBook, String type, Element n

public static interface IInfoSectionFactory {

@Deprecated // TODO: RM in next major MC version
public InfoSection create(IInfoBook infoBook, InfoSection parent, int childIndex, String translationKey,
ArrayList<String> paragraphs, List<SectionAppendix> appendixes,
ArrayList<String> tagList);

public default InfoSection create(IInfoBook infoBook, InfoSection parent, int childIndex, String translationKey,
ArrayList<String> paragraphs, List<SectionAppendix> appendixes,
ArrayList<String> tagList, ModBase<?> mod) {
return this.create(infoBook, parent, childIndex, translationKey, paragraphs, appendixes, tagList);
}

}

public static interface IAppendixFactory {
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/org/cyclops/cyclopscore/infobook/InfoSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import org.cyclops.cyclopscore.helper.Helpers;
import org.cyclops.cyclopscore.helper.L10NHelpers;
import org.cyclops.cyclopscore.infobook.pageelement.SectionAppendix;
import org.cyclops.cyclopscore.init.ModBase;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -40,6 +42,9 @@ public class InfoSection {
private static final int LINK_INDENT = 8;

@Getter private final IInfoBook infoBook;
@Getter
@Nullable
private final ModBase<?> mod;
private InfoSection parent;
private int childIndex;
@Getter private String translationKey;
Expand All @@ -53,8 +58,9 @@ public class InfoSection {
private Map<Integer, List<AdvancedButton>> advancedButtons = Maps.newHashMap();

public InfoSection(IInfoBook infoBook, InfoSection parent, int childIndex, String translationKey,
List<String> paragraphs, List<SectionAppendix> appendixes, ArrayList<String> tagList) {
List<String> paragraphs, List<SectionAppendix> appendixes, ArrayList<String> tagList, ModBase<?> mod) {
this.infoBook = infoBook;
this.mod = mod;
this.parent = parent;
this.childIndex = childIndex;
this.translationKey = translationKey;
Expand All @@ -63,12 +69,25 @@ public InfoSection(IInfoBook infoBook, InfoSection parent, int childIndex, Strin
this.tagList = tagList;
}

@Deprecated // TODO: RM in next major MC version
public InfoSection(IInfoBook infoBook, InfoSection parent, int childIndex, String translationKey,
List<String> paragraphs, List<SectionAppendix> appendixes, ArrayList<String> tagList) {
this(infoBook, parent, childIndex, translationKey, paragraphs, appendixes, tagList, null);
}

public String getRelativeWebPath() {
if (isRoot()) {
return "";
} else {
String suffix = getSubSections() > 0 ? "/" : ".html";
return getParent().getRelativeWebPath() + getTranslationKey().substring(getTranslationKey().lastIndexOf('.') + 1) + suffix;
StringBuilder sb = new StringBuilder();
sb = sb.append(getParent().getRelativeWebPath());
sb = sb.append(getTranslationKey().substring(getTranslationKey().lastIndexOf('.') + 1));
if (getMod() != null && getParent().getMod() != getMod()) {
// Go in a subfolder when we are handling a different mod
sb = sb.append("/" + getMod().getModId());
}
sb = sb.append(getSubSections() > 0 ? "/" : ".html");
return sb.toString();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
*/
public class InfoSectionTagIndex extends InfoSection {

public InfoSectionTagIndex(IInfoBook infoBook, InfoSection parent) {
public InfoSectionTagIndex(IInfoBook infoBook, InfoSection parent, ModBase<?> mod) {
super(infoBook, parent, parent.getSubSections(), "info_book." + infoBook.getMod().getModId() + ".tag_index", new ArrayList<String>(),
new ArrayList<SectionAppendix>(), new ArrayList<String>());
new ArrayList<SectionAppendix>(), new ArrayList<String>(), mod);

// treemap to ensure order by localized tag
infoBook.setConfigLinks(Maps.<String, String, Pair<InfoSection, Integer>>newTreeMap(new Comparator<String>() {
Expand Down

0 comments on commit 6b53115

Please sign in to comment.