Fix book entry loading after reloading the resource manager

This commit is contained in:
Nedelosk committed 2018-04-20 17:35:01 +02:00
1 parent 47ff5d9ad1
commit d4dee797d7
2 files changed
+16 -2

No files matched your search

@@ -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<GuiForesterBook> 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;
}
@@ -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