Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down