From 49edf370b2aac266c66605dc894870c712d127f9 Mon Sep 17 00:00:00 2001 From: Mqrius Date: Sat, 14 Mar 2026 21:49:39 +0100 Subject: [PATCH] Load books on first open --- .../patchouli/client/base/ClientAdvancements.java | 8 ++++---- .../patchouli/client/book/ClientBookRegistry.java | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Xplat/src/main/java/vazkii/patchouli/client/base/ClientAdvancements.java b/Xplat/src/main/java/vazkii/patchouli/client/base/ClientAdvancements.java index 8dd5971a..a9f59e80 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/base/ClientAdvancements.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/base/ClientAdvancements.java @@ -22,17 +22,17 @@ import java.util.Map; public class ClientAdvancements { - private static boolean gotFirstAdvPacket = false; /* Hooked at the end of ClientAdvancementManager.read, when the advancement packet arrives clientside The initial book load is done here when the first advancement packet arrives. Doing it anytime before that leads to excessive toast spam because the book believes everything to be locked, and then the first advancement packet unlocks everything. + Books may also be loaded lazily on first open via displayBookGui, for cases where + no advancement packet arrives before the book is opened. */ public static void onClientPacket() { - if (!gotFirstAdvPacket) { + if (!ClientBookRegistry.INSTANCE.hasReloadedContents()) { ClientBookRegistry.INSTANCE.reload(); - gotFirstAdvPacket = true; } else { ClientBookRegistry.INSTANCE.reloadLocks(false); } @@ -56,7 +56,7 @@ public static boolean hasDone(String advancement) { } public static void playerLogout() { - gotFirstAdvPacket = false; + ClientBookRegistry.INSTANCE.resetReloadedState(); } public static void sendBookToast(Book book) { diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/ClientBookRegistry.java b/Xplat/src/main/java/vazkii/patchouli/client/book/ClientBookRegistry.java index 155abb1f..95e2e787 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/ClientBookRegistry.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/ClientBookRegistry.java @@ -31,6 +31,7 @@ public class ClientBookRegistry { .registerTypeHierarchyAdapter(TemplateComponent.class, new TemplateComponentAdapter()) .create(); public String currentLang; + private boolean hasReloadedContents = false; public static final ClientBookRegistry INSTANCE = new ClientBookRegistry(); @@ -62,17 +63,30 @@ private void addPageTypes() { public void reload() { currentLang = Minecraft.getInstance().getLanguageManager().getSelected(); BookRegistry.INSTANCE.reloadContents(Minecraft.getInstance().level); + hasReloadedContents = true; } public void reloadLocks(boolean suppressToasts) { BookRegistry.INSTANCE.books.values().forEach(b -> b.reloadLocks(suppressToasts)); } + public boolean hasReloadedContents() { + return hasReloadedContents; + } + + public void resetReloadedState() { + hasReloadedContents = false; + } + /** * @param entryId Entry to force to the top of the stack * @param page Zero-indexed page in the entry to force. Ignored if {@code entryId} is null. */ public void displayBookGui(ResourceLocation bookStr, @Nullable ResourceLocation entryId, int page) { + if (!hasReloadedContents) { + reload(); + } + Minecraft mc = Minecraft.getInstance(); currentLang = mc.getLanguageManager().getSelected();