mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 23:28:35 +01:00
Fixed one random exception and one bug with the booklet.
Great. Could've done that an hour ago.
This commit is contained in:
parent
f330657cf7
commit
5c8fba3d64
2 changed files with 33 additions and 9 deletions
|
@ -33,6 +33,8 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.stats.Achievement;
|
import net.minecraft.stats.Achievement;
|
||||||
import net.minecraft.util.text.TextFormatting;
|
import net.minecraft.util.text.TextFormatting;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
@ -46,6 +48,7 @@ public final class BookletUtils{
|
||||||
/**
|
/**
|
||||||
* Tries to open a URL in the Browser
|
* Tries to open a URL in the Browser
|
||||||
*/
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public static void openBrowser(String url){
|
public static void openBrowser(String url){
|
||||||
openBrowser(url, url);
|
openBrowser(url, url);
|
||||||
}
|
}
|
||||||
|
@ -56,6 +59,7 @@ public final class BookletUtils{
|
||||||
* @param url The URL
|
* @param url The URL
|
||||||
* @param shiftUrl The URL to open when Shift is held
|
* @param shiftUrl The URL to open when Shift is held
|
||||||
*/
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public static void openBrowser(String url, String shiftUrl){
|
public static void openBrowser(String url, String shiftUrl){
|
||||||
try{
|
try{
|
||||||
if(Desktop.isDesktopSupported()){
|
if(Desktop.isDesktopSupported()){
|
||||||
|
@ -75,6 +79,7 @@ public final class BookletUtils{
|
||||||
/**
|
/**
|
||||||
* Draws the Title of the current chapter, current index entry or just "Actually Additions" if neither is present
|
* Draws the Title of the current chapter, current index entry or just "Actually Additions" if neither is present
|
||||||
*/
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public static void drawTitle(GuiBooklet booklet){
|
public static void drawTitle(GuiBooklet booklet){
|
||||||
booklet.mc.getTextureManager().bindTexture(GuiBooklet.RES_LOC);
|
booklet.mc.getTextureManager().bindTexture(GuiBooklet.RES_LOC);
|
||||||
//Upper title
|
//Upper title
|
||||||
|
@ -122,6 +127,7 @@ public final class BookletUtils{
|
||||||
*
|
*
|
||||||
* @param pre If the hover info texts or the icon should be drawn
|
* @param pre If the hover info texts or the icon should be drawn
|
||||||
*/
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public static void drawAchievementInfo(GuiBooklet booklet, boolean pre, int mouseX, int mouseY){
|
public static void drawAchievementInfo(GuiBooklet booklet, boolean pre, int mouseX, int mouseY){
|
||||||
if(booklet.currentEntrySet.getCurrentChapter() == null){
|
if(booklet.currentEntrySet.getCurrentChapter() == null){
|
||||||
return;
|
return;
|
||||||
|
@ -167,6 +173,7 @@ public final class BookletUtils{
|
||||||
* -the number of a page in a chapter
|
* -the number of a page in a chapter
|
||||||
* -the amount of words and chars in the index (Just for teh lulz)
|
* -the amount of words and chars in the index (Just for teh lulz)
|
||||||
*/
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public static void renderPre(GuiBooklet booklet, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
|
public static void renderPre(GuiBooklet booklet, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
|
||||||
if(booklet.currentEntrySet.getCurrentEntry() != null){
|
if(booklet.currentEntrySet.getCurrentEntry() != null){
|
||||||
//Renders Booklet Page Number and Content
|
//Renders Booklet Page Number and Content
|
||||||
|
@ -192,6 +199,7 @@ public final class BookletUtils{
|
||||||
/**
|
/**
|
||||||
* Draws all of the hovering texts for the buttons that need explanation in the booklet
|
* Draws all of the hovering texts for the buttons that need explanation in the booklet
|
||||||
*/
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public static void doHoverTexts(GuiBooklet booklet, int mouseX, int mouseY){
|
public static void doHoverTexts(GuiBooklet booklet, int mouseX, int mouseY){
|
||||||
//Update all of the buttons' hovering texts
|
//Update all of the buttons' hovering texts
|
||||||
for(Object button : booklet.getButtonList()){
|
for(Object button : booklet.getButtonList()){
|
||||||
|
@ -209,6 +217,7 @@ public final class BookletUtils{
|
||||||
/**
|
/**
|
||||||
* Updates the search bar, should be called when it is getting typed into
|
* Updates the search bar, should be called when it is getting typed into
|
||||||
*/
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public static void updateSearchBar(GuiBooklet booklet){
|
public static void updateSearchBar(GuiBooklet booklet){
|
||||||
if(booklet.currentEntrySet.getCurrentEntry() instanceof BookletEntryAllSearch){
|
if(booklet.currentEntrySet.getCurrentEntry() instanceof BookletEntryAllSearch){
|
||||||
BookletEntryAllSearch currentEntry = (BookletEntryAllSearch)booklet.currentEntrySet.getCurrentEntry();
|
BookletEntryAllSearch currentEntry = (BookletEntryAllSearch)booklet.currentEntrySet.getCurrentEntry();
|
||||||
|
@ -229,6 +238,7 @@ public final class BookletUtils{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
private static boolean getChapterStacksContainString(String text, IBookletChapter chapter){
|
private static boolean getChapterStacksContainString(String text, IBookletChapter chapter){
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
for(BookletPage page : chapter.getPages()){
|
for(BookletPage page : chapter.getPages()){
|
||||||
|
@ -251,6 +261,7 @@ public final class BookletUtils{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public static void openIndexEntry(GuiBooklet booklet, IBookletEntry entry, int page, boolean resetTextField){
|
public static void openIndexEntry(GuiBooklet booklet, IBookletEntry entry, int page, boolean resetTextField){
|
||||||
booklet.searchField.setVisible(entry instanceof BookletEntryAllSearch);
|
booklet.searchField.setVisible(entry instanceof BookletEntryAllSearch);
|
||||||
booklet.searchField.setFocused(entry instanceof BookletEntryAllSearch);
|
booklet.searchField.setFocused(entry instanceof BookletEntryAllSearch);
|
||||||
|
@ -309,6 +320,7 @@ public final class BookletUtils{
|
||||||
/**
|
/**
|
||||||
* Called when one of the buttons to open an index or a chapter is pressed
|
* Called when one of the buttons to open an index or a chapter is pressed
|
||||||
*/
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public static void handleChapterButtonClick(GuiBooklet booklet, GuiButton button){
|
public static void handleChapterButtonClick(GuiBooklet booklet, GuiButton button){
|
||||||
int place = ArrayUtils.indexOf(booklet.chapterButtons, button);
|
int place = ArrayUtils.indexOf(booklet.chapterButtons, button);
|
||||||
if(place >= 0){
|
if(place >= 0){
|
||||||
|
@ -332,6 +344,7 @@ public final class BookletUtils{
|
||||||
* Opens a chapter in the booklet.
|
* Opens a chapter in the booklet.
|
||||||
* Can only be done when the chapter is not null and an index entry is opened in the booklet
|
* Can only be done when the chapter is not null and an index entry is opened in the booklet
|
||||||
*/
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public static void openChapter(GuiBooklet booklet, IBookletChapter chapter, BookletPage page){
|
public static void openChapter(GuiBooklet booklet, IBookletChapter chapter, BookletPage page){
|
||||||
if(chapter == null || booklet.currentEntrySet.getCurrentEntry() == null){
|
if(chapter == null || booklet.currentEntrySet.getCurrentEntry() == null){
|
||||||
return;
|
return;
|
||||||
|
@ -366,6 +379,7 @@ public final class BookletUtils{
|
||||||
/**
|
/**
|
||||||
* Checks if a chapter has a certain page
|
* Checks if a chapter has a certain page
|
||||||
*/
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
private static boolean doesChapterHavePage(IBookletChapter chapter, BookletPage page){
|
private static boolean doesChapterHavePage(IBookletChapter chapter, BookletPage page){
|
||||||
for(BookletPage aPage : chapter.getPages()){
|
for(BookletPage aPage : chapter.getPages()){
|
||||||
if(aPage == page){
|
if(aPage == page){
|
||||||
|
@ -378,6 +392,7 @@ public final class BookletUtils{
|
||||||
/**
|
/**
|
||||||
* Gets the next available page in the booklet (or null if there is none)
|
* Gets the next available page in the booklet (or null if there is none)
|
||||||
*/
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
private static BookletPage getNextPage(IBookletChapter chapter, BookletPage page){
|
private static BookletPage getNextPage(IBookletChapter chapter, BookletPage page){
|
||||||
for(int i = 0; i < chapter.getPages().length; i++){
|
for(int i = 0; i < chapter.getPages().length; i++){
|
||||||
if(chapter.getPages()[i] == page){
|
if(chapter.getPages()[i] == page){
|
||||||
|
@ -392,6 +407,7 @@ public final class BookletUtils{
|
||||||
/**
|
/**
|
||||||
* Gets the previous available page in the booklet (or null if there is none)
|
* Gets the previous available page in the booklet (or null if there is none)
|
||||||
*/
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
private static BookletPage getPrevPage(IBookletChapter chapter, BookletPage page){
|
private static BookletPage getPrevPage(IBookletChapter chapter, BookletPage page){
|
||||||
for(int i = 0; i < chapter.getPages().length; i++){
|
for(int i = 0; i < chapter.getPages().length; i++){
|
||||||
if(chapter.getPages()[i] == page){
|
if(chapter.getPages()[i] == page){
|
||||||
|
@ -406,6 +422,7 @@ public final class BookletUtils{
|
||||||
/**
|
/**
|
||||||
* Called when the "next page"-button is pressed
|
* Called when the "next page"-button is pressed
|
||||||
*/
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public static void handleNextPage(GuiBooklet booklet){
|
public static void handleNextPage(GuiBooklet booklet){
|
||||||
if(booklet.currentEntrySet.getCurrentEntry() != null){
|
if(booklet.currentEntrySet.getCurrentEntry() != null){
|
||||||
if(booklet.currentEntrySet.getCurrentPage() != null){
|
if(booklet.currentEntrySet.getCurrentPage() != null){
|
||||||
|
@ -432,6 +449,7 @@ public final class BookletUtils{
|
||||||
/**
|
/**
|
||||||
* Called when the "previous page"-button is pressed
|
* Called when the "previous page"-button is pressed
|
||||||
*/
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public static void handlePreviousPage(GuiBooklet booklet){
|
public static void handlePreviousPage(GuiBooklet booklet){
|
||||||
if(booklet.currentEntrySet.getCurrentEntry() != null){
|
if(booklet.currentEntrySet.getCurrentEntry() != null){
|
||||||
if(booklet.currentEntrySet.getCurrentPage() != null){
|
if(booklet.currentEntrySet.getCurrentPage() != null){
|
||||||
|
@ -470,6 +488,7 @@ public final class BookletUtils{
|
||||||
return possiblePages;
|
return possiblePages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public static void saveBookPage(GuiBooklet gui, NBTTagCompound compound){
|
public static void saveBookPage(GuiBooklet gui, NBTTagCompound compound){
|
||||||
//Save Entry etc.
|
//Save Entry etc.
|
||||||
compound.setTag("SavedEntry", gui.currentEntrySet.writeToNBT());
|
compound.setTag("SavedEntry", gui.currentEntrySet.writeToNBT());
|
||||||
|
@ -485,6 +504,7 @@ public final class BookletUtils{
|
||||||
compound.setTag("Bookmarks", list);
|
compound.setTag("Bookmarks", list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public static void openLastBookPage(GuiBooklet gui, NBTTagCompound compound){
|
public static void openLastBookPage(GuiBooklet gui, NBTTagCompound compound){
|
||||||
//Open Entry etc.
|
//Open Entry etc.
|
||||||
EntrySet set = EntrySet.readFromNBT(compound.getCompoundTag("SavedEntry"));
|
EntrySet set = EntrySet.readFromNBT(compound.getCompoundTag("SavedEntry"));
|
||||||
|
|
|
@ -458,6 +458,9 @@ public class GuiBooklet extends GuiScreen implements IBookletGui{
|
||||||
@Override
|
@Override
|
||||||
public void onGuiClosed(){
|
public void onGuiClosed(){
|
||||||
if(this.saveOnClose && this.shouldSaveDataNextClose){
|
if(this.saveOnClose && this.shouldSaveDataNextClose){
|
||||||
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
//Happens when you get thrown out with the book open
|
||||||
|
if(mc.theWorld != null && mc.thePlayer != null){
|
||||||
NBTTagCompound bookletData = new NBTTagCompound();
|
NBTTagCompound bookletData = new NBTTagCompound();
|
||||||
BookletUtils.saveBookPage(this, bookletData);
|
BookletUtils.saveBookPage(this, bookletData);
|
||||||
|
|
||||||
|
@ -466,11 +469,12 @@ public class GuiBooklet extends GuiScreen implements IBookletGui{
|
||||||
|
|
||||||
NBTTagCompound dataToSend = new NBTTagCompound();
|
NBTTagCompound dataToSend = new NBTTagCompound();
|
||||||
dataToSend.setTag("Data", extraData);
|
dataToSend.setTag("Data", extraData);
|
||||||
dataToSend.setInteger("WorldID", Minecraft.getMinecraft().theWorld.provider.getDimension());
|
dataToSend.setInteger("WorldID", mc.theWorld.provider.getDimension());
|
||||||
dataToSend.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId());
|
dataToSend.setInteger("PlayerID", mc.thePlayer.getEntityId());
|
||||||
PacketHandler.theNetwork.sendToServer(new PacketClientToServer(dataToSend, PacketHandler.CHANGE_PLAYER_DATA_HANDLER));
|
PacketHandler.theNetwork.sendToServer(new PacketClientToServer(dataToSend, PacketHandler.CHANGE_PLAYER_DATA_HANDLER));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doesGuiPauseGame(){
|
public boolean doesGuiPauseGame(){
|
||||||
|
|
Loading…
Reference in a new issue