diff --git a/src/main/java/forestry/book/gui/GuiForesterBook.java b/src/main/java/forestry/book/gui/GuiForesterBook.java index 846dcc312..6292985aa 100644 --- a/src/main/java/forestry/book/gui/GuiForesterBook.java +++ b/src/main/java/forestry/book/gui/GuiForesterBook.java @@ -39,7 +39,7 @@ public abstract class GuiForesterBook extends GuiScreen implements IGuiSizable { private static final int X_SIZE = 256; private static final int Y_SIZE = 181; @Nullable - public static GuiForesterBook guiScreen; + private static GuiForesterBook guiScreen; protected final IForesterBook book; final ElementManager elementManager; @@ -52,6 +52,10 @@ public abstract class GuiForesterBook extends GuiScreen implements IGuiSizable { this.elementManager = new ElementManager<>(this); } + public IForesterBook getBook() { + return book; + } + @Override public void initGui() { super.initGui(); @@ -171,6 +175,11 @@ public abstract class GuiForesterBook extends GuiScreen implements IGuiSizable { return mc; } + @Nullable + public static GuiForesterBook getGuiScreen() { + return guiScreen; + } + public static void setGuiScreen(@Nullable GuiForesterBook guiScreen) { GuiForesterBook.guiScreen = guiScreen; } diff --git a/src/main/java/forestry/book/items/ItemForesterBook.java b/src/main/java/forestry/book/items/ItemForesterBook.java index 93795209b..567dbf299 100644 --- a/src/main/java/forestry/book/items/ItemForesterBook.java +++ b/src/main/java/forestry/book/items/ItemForesterBook.java @@ -37,7 +37,12 @@ public class ItemForesterBook extends ItemWithGui { @Override public GuiScreen getGui(EntityPlayer player, ItemStack heldItem, int data) { IForesterBook book = BookLoader.INSTANCE.loadBook(); - return GuiForesterBook.guiScreen != null ? GuiForesterBook.guiScreen : new GuiForestryBookCategories(book); + GuiForesterBook guiScreen = GuiForesterBook.getGuiScreen(); + if(guiScreen != null && guiScreen.getBook() != book){ + GuiForesterBook.setGuiScreen(null); + guiScreen = null; + } + return guiScreen != null ? guiScreen : new GuiForestryBookCategories(book); } @Nullable