Skip to content

Commit

Permalink
Clarify some stuff around spreads and pages:
Browse files Browse the repository at this point in the history
1. Pages arg to the API is zero-indexed
2. Rename bookmark data struct's "page" variable to "spread"

Related to VazkiiMods#374.
  • Loading branch information
williewillus committed Jun 19, 2022
1 parent 5e06a65 commit e3865d8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Xplat/src/main/java/vazkii/patchouli/api/PatchouliAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public interface IPatchouliAPI {
/**
* Sends a network message to the given player
* to open the book to the given entry
*
* @param page Zero-indexed page number
*/
void openBookEntry(ServerPlayer player, ResourceLocation book, ResourceLocation entry, int page);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package vazkii.patchouli.client.base;

import com.google.gson.annotations.SerializedName;

import net.minecraft.resources.ResourceLocation;

import vazkii.patchouli.client.book.BookEntry;
Expand Down Expand Up @@ -57,11 +59,12 @@ public static final class BookData {
public static final class Bookmark {

public String entry;
public int page;
// Serialized as page for legacy reasons
@SerializedName("page") public int spread;

public Bookmark(String entry, int page) {
public Bookmark(String entry, int spread) {
this.entry = entry;
this.page = page;
this.spread = spread;
}

public BookEntry getEntry(Book book) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void reloadLocks(boolean suppressToasts) {

/**
* @param entryId Entry to force to the top of the stack
* @param page Page in the entry to force. Ignored if {@code entryId} is null.
* @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) {
Minecraft mc = Minecraft.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public void handleButtonBookmark(Button button) {
PersistentData.save();
needsBookmarkUpdate = true;
} else {
displayLexiconGui(new GuiBookEntry(book, bookmark.getEntry(book), bookmark.page), true);
displayLexiconGui(new GuiBookEntry(book, bookmark.getEntry(book), bookmark.spread), true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ boolean isBookmarkedAlready() {
BookData data = PersistentData.data.getBookData(book);

for (Bookmark bookmark : data.bookmarks) {
if (bookmark.entry.equals(entryKey) && bookmark.page == spread) {
if (bookmark.entry.equals(entryKey) && bookmark.spread == spread) {
return true;
}
}
Expand All @@ -209,7 +209,7 @@ public static void displayOrBookmark(GuiBook currGui, BookEntry entry) {

if (gui.isBookmarkedAlready()) {
String key = entry.getId().toString();
data.bookmarks.removeIf((bm) -> bm.entry.equals(key) && bm.page == 0);
data.bookmarks.removeIf((bm) -> bm.entry.equals(key) && bm.spread == 0);
PersistentData.save();
currGui.needsBookmarkUpdate = true;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void renderButton(PoseStack ms, int mouseX, int mouseY, float partialTick
entry.getIcon().render(ms, px, py);

RenderSystem.disableDepthTest();
String s = Integer.toString(bookmark.page + 1);
String s = Integer.toString(bookmark.spread + 1);
if (multiblock) {
s = I18n.get("patchouli.gui.lexicon.visualize_letter");
}
Expand Down

0 comments on commit e3865d8

Please sign in to comment.