mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-18 11:19:20 +00:00
Merge remote-tracking branch 'origin/1.12' into 1.13
This commit is contained in:
commit
c14d405a75
5 files changed
+47
-2
No files matched your search
@@ -0,0 +1,6 @@
|
||||
package slimeknights.mantle.client.book.data;
|
||||
|
||||
public class PageDataModule extends PageData {
|
||||
/** Module required to load this section, see {@link slimeknights.mantle.pulsar.control.PulseManager#isPulseLoaded(String)} for more details */
|
||||
public String module = "";
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class SectionData implements IDataItem {
|
||||
String data = source.resourceToString(pagesInfo);
|
||||
if(!data.isEmpty()) {
|
||||
try {
|
||||
pages = new ArrayList<>(Arrays.asList(BookLoader.GSON.fromJson(data, PageData[].class)));
|
||||
pages = getPages(data);
|
||||
} catch(Exception e) {
|
||||
pages = new ArrayList<>();
|
||||
PageData pdError = new PageData(true);
|
||||
@@ -81,6 +81,15 @@ public class SectionData implements IDataItem {
|
||||
icon.location = source.getResourceLocation(icon.file, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of pages from the given data
|
||||
* @param data JSON data
|
||||
* @return ArrayList of pages for the book
|
||||
*/
|
||||
protected ArrayList<PageData> getPages(String data) {
|
||||
return new ArrayList<>(Arrays.asList(BookLoader.GSON.fromJson(data, PageData[].class)));
|
||||
}
|
||||
|
||||
public void update(@Nullable GuiBook.AdvancementCache advancementCache) {
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
package slimeknights.mantle.client.book.data;
|
||||
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.client.book.repository.ModuleFileRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SectionDataModule extends SectionData {
|
||||
/** Module required to load this section, see {@link slimeknights.mantle.pulsar.control.PulseManager#isPulseLoaded(String)} for more details */
|
||||
public String module = "";
|
||||
|
||||
@Override
|
||||
protected ArrayList<PageData> getPages(String data) {
|
||||
// this should always be the case, but just for safety
|
||||
if(source instanceof ModuleFileRepository) {
|
||||
// just filters out pages where the module is not loaded
|
||||
Predicate<String> manager = ((ModuleFileRepository)source).getManager();
|
||||
return new ArrayList<>(Arrays.stream(BookLoader.GSON.fromJson(data, PageDataModule[].class))
|
||||
.filter((page)->page.module.isEmpty() || manager.test(page.module))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
return super.getPages(data);
|
||||
}
|
||||
}
|
||||
@@ -31,4 +31,12 @@ public class ModuleFileRepository extends FileRepository {
|
||||
.filter((section)->section.module.isEmpty() || manager.test(section.module))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the manager used to determine if a module is available
|
||||
* @return Predicate to test a module availability
|
||||
*/
|
||||
public Predicate<String> getManager() {
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
@@ -274,7 +274,7 @@ public class PulseManager {
|
||||
*/
|
||||
private static boolean isPulseLoaded(Map<Object, PulseMeta> pulses, String pulseId) {
|
||||
for(Map.Entry<Object, PulseMeta> entry : pulses.entrySet()) {
|
||||
if (entry.getValue().getId().equals(pulseId)) {
|
||||
if (entry.getValue().getId().equalsIgnoreCase(pulseId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user