diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java index 69a147481..23dbc9381 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java @@ -31,7 +31,7 @@ public final class ActuallyAdditionsAPI{ public static final String MOD_ID = "actuallyadditions"; public static final String API_ID = MOD_ID+"api"; - public static final String API_VERSION = "20"; + public static final String API_VERSION = "21"; public static final List CRUSHER_RECIPES = new ArrayList(); public static final List BALL_OF_FUR_RETURN_ITEMS = new ArrayList(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletChapter.java b/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletChapter.java index 41179427b..e702f4ffb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletChapter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletChapter.java @@ -16,7 +16,9 @@ public interface IBookletChapter{ BookletPage[] getPages(); - String getUnlocalizedName(); + BookletPage getPageById(int id); + + int getPageId(BookletPage page); String getLocalizedName(); @@ -26,4 +28,6 @@ public interface IBookletChapter{ ItemStack getDisplayItemStack(); + String getIdentifier(); + } diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletEntry.java b/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletEntry.java index a46b9dc44..c8695e18b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletEntry.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletEntry.java @@ -18,7 +18,7 @@ public interface IBookletEntry{ void setChapters(List chapters); - String getUnlocalizedName(); + String getIdentifier(); String getLocalizedName(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/internal/IMethodHandler.java b/src/main/java/de/ellpeck/actuallyadditions/api/internal/IMethodHandler.java index 7ffb3bdb7..ab9133984 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/internal/IMethodHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/internal/IMethodHandler.java @@ -48,5 +48,5 @@ public interface IMethodHandler{ BookletPage generateFurnacePage(int id, ItemStack input, ItemStack result); - IBookletChapter generateBookletChapter(String unlocalizedName, IBookletEntry entry, ItemStack displayStack, BookletPage... pages); + IBookletChapter generateBookletChapter(String identifier, IBookletEntry entry, ItemStack displayStack, BookletPage... pages); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockBookletStand.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockBookletStand.java index 2a709a86c..58529a829 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockBookletStand.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockBookletStand.java @@ -140,19 +140,19 @@ public class BlockBookletStand extends BlockContainerBase implements IHudDisplay String strg1; String strg2; - if(set.entry == null){ + if(set.getCurrentEntry() == null){ strg1 = "No entry saved! Save one if"; strg2 = "you are the player who placed it!"; } - else if(set.chapter == null){ - strg1 = set.entry.getLocalizedName(); - strg2 = "Page "+set.pageInIndex; + else if(set.getCurrentChapter() == null){ + strg1 = set.getCurrentEntry().getLocalizedName(); + strg2 = "Page "+set.getPageInIndex(); } else{ - strg1 = set.chapter.getLocalizedName(); - strg2 = "Page "+set.page.getID(); + strg1 = set.getCurrentChapter().getLocalizedName(); + strg2 = "Page "+set.getCurrentPage().getID(); - AssetUtil.renderStackToGui(set.chapter.getDisplayItemStack() != null ? set.chapter.getDisplayItemStack() : new ItemStack(InitItems.itemBooklet), resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2+10, 1F); + AssetUtil.renderStackToGui(set.getCurrentChapter().getDisplayItemStack() != null ? set.getCurrentChapter().getDisplayItemStack() : new ItemStack(InitItems.itemBooklet), resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2+10, 1F); } minecraft.fontRendererObj.drawStringWithShadow(TextFormatting.YELLOW+""+TextFormatting.ITALIC+strg1, resolution.getScaledWidth()/2+25, resolution.getScaledHeight()/2+8, StringUtil.DECIMAL_COLOR_WHITE); minecraft.fontRendererObj.drawStringWithShadow(TextFormatting.YELLOW+""+TextFormatting.ITALIC+strg2, resolution.getScaledWidth()/2+25, resolution.getScaledHeight()/2+18, StringUtil.DECIMAL_COLOR_WHITE); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/BookletUtils.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/BookletUtils.java index 2a97e9b6f..0354356af 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/BookletUtils.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/BookletUtils.java @@ -490,9 +490,9 @@ public final class BookletUtils{ EntrySet set = EntrySet.readFromNBT(compound.getCompoundTag("SavedEntry")); if(set != null){ - BookletUtils.openIndexEntry(gui, set.entry, set.pageInIndex, true); - if(set.chapter != null){ - BookletUtils.openChapter(gui, set.chapter, set.page); + BookletUtils.openIndexEntry(gui, set.getCurrentEntry(), set.getPageInIndex(), true); + if(set.getCurrentChapter() != null){ + BookletUtils.openChapter(gui, set.getCurrentChapter(), set.getCurrentPage()); } String searchText = compound.getString("SearchWord"); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java index be951da0a..dd81aec72 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java @@ -252,7 +252,7 @@ public class GuiBooklet extends GuiScreen implements IBookletGui{ else if(button == this.buttonViewOnline){ IBookletChapter chapter = this.currentEntrySet.getCurrentChapter(); if(chapter != null){ - BookletUtils.openBrowser("http://ellpeck.de/actaddmanual/#"+chapter.getUnlocalizedName()); + BookletUtils.openBrowser("http://ellpeck.de/actaddmanual/#"+chapter.getIdentifier()); } } //Handles Website @@ -409,8 +409,8 @@ public class GuiBooklet extends GuiScreen implements IBookletGui{ } else{ //Open forced entry - BookletUtils.openIndexEntry(this, ItemBooklet.forcedEntry.entry, ItemBooklet.forcedEntry.pageInIndex, true); - BookletUtils.openChapter(this, ItemBooklet.forcedEntry.chapter, ItemBooklet.forcedEntry.page); + BookletUtils.openIndexEntry(this, ItemBooklet.forcedEntry.getCurrentEntry(), ItemBooklet.forcedEntry.getPageInIndex(), true); + BookletUtils.openChapter(this, ItemBooklet.forcedEntry.getCurrentChapter(), ItemBooklet.forcedEntry.getCurrentPage()); ItemBooklet.forcedEntry = null; this.shouldSaveDataNextClose = true; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBookletStand.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBookletStand.java index 4750162a9..b9d335427 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBookletStand.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBookletStand.java @@ -73,7 +73,7 @@ public class GuiBookletStand extends GuiBooklet{ } //Open the pages the book was assigned - BookletUtils.openIndexEntry(this, this.theStand.assignedEntry.entry, this.theStand.assignedEntry.pageInIndex, true); - BookletUtils.openChapter(this, this.theStand.assignedEntry.chapter, this.theStand.assignedEntry.page); + BookletUtils.openIndexEntry(this, this.theStand.assignedEntry.getCurrentEntry(), this.theStand.assignedEntry.getPageInIndex(), true); + BookletUtils.openChapter(this, this.theStand.assignedEntry.getCurrentChapter(), this.theStand.assignedEntry.getCurrentPage()); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/button/BookmarkButton.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/button/BookmarkButton.java index 9bee05685..4d7bf7aef 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/button/BookmarkButton.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/button/BookmarkButton.java @@ -38,14 +38,14 @@ public class BookmarkButton extends GuiButton{ } public void onPressed(){ - if(this.assignedEntry.entry != null){ + if(this.assignedEntry.getCurrentEntry() != null){ if(GuiScreen.isShiftKeyDown()){ this.assignedEntry.removeEntry(); this.booklet.shouldSaveDataNextClose = true; } else{ - BookletUtils.openIndexEntry(this.booklet, this.assignedEntry.entry, this.assignedEntry.pageInIndex, true); - BookletUtils.openChapter(this.booklet, this.assignedEntry.chapter, this.assignedEntry.page); + BookletUtils.openIndexEntry(this.booklet, this.assignedEntry.getCurrentEntry(), this.assignedEntry.getPageInIndex(), true); + BookletUtils.openChapter(this.booklet, this.assignedEntry.getCurrentChapter(), this.assignedEntry.getCurrentPage()); } } else{ @@ -71,12 +71,12 @@ public class BookmarkButton extends GuiButton{ GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); GlStateManager.blendFunc(770, 771); int renderHeight = 25; - this.drawTexturedModalRect(this.xPosition, this.yPosition, 146+(this.assignedEntry.entry == null ? 0 : 16), 194-renderHeight+k*renderHeight, this.width, renderHeight); + this.drawTexturedModalRect(this.xPosition, this.yPosition, 146+(this.assignedEntry.getCurrentEntry() == null ? 0 : 16), 194-renderHeight+k*renderHeight, this.width, renderHeight); this.mouseDragged(minecraft, x, y); - if(this.assignedEntry.entry != null){ + if(this.assignedEntry.getCurrentEntry() != null){ GlStateManager.pushMatrix(); - AssetUtil.renderStackToGui(this.assignedEntry.chapter != null && this.assignedEntry.chapter.getDisplayItemStack() != null ? this.assignedEntry.chapter.getDisplayItemStack() : new ItemStack(InitItems.itemBooklet), this.xPosition+2, this.yPosition+1, 0.725F); + AssetUtil.renderStackToGui(this.assignedEntry.getCurrentChapter() != null && this.assignedEntry.getCurrentChapter().getDisplayItemStack() != null ? this.assignedEntry.getCurrentChapter().getDisplayItemStack() : new ItemStack(InitItems.itemBooklet), this.xPosition+2, this.yPosition+1, 0.725F); GlStateManager.popMatrix(); } } @@ -84,12 +84,12 @@ public class BookmarkButton extends GuiButton{ public void drawHover(int mouseX, int mouseY){ ArrayList list = new ArrayList(); - if(this.assignedEntry.entry != null){ - if(this.assignedEntry.chapter != null){ - list.add(TextFormatting.GOLD+this.assignedEntry.chapter.getLocalizedName()+", Page "+this.assignedEntry.page.getID()); + if(this.assignedEntry.getCurrentEntry() != null){ + if(this.assignedEntry.getCurrentChapter() != null){ + list.add(TextFormatting.GOLD+this.assignedEntry.getCurrentChapter().getLocalizedName()+", Page "+this.assignedEntry.getCurrentPage().getID()); } else{ - list.add(TextFormatting.GOLD+this.assignedEntry.entry.getLocalizedName()+", Page "+this.assignedEntry.pageInIndex); + list.add(TextFormatting.GOLD+this.assignedEntry.getCurrentEntry().getLocalizedName()+", Page "+this.assignedEntry.getPageInIndex()); } list.add("Click to open"); list.add(TextFormatting.ITALIC+"Shift-Click to remove"); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/chapter/BookletChapter.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/chapter/BookletChapter.java index 306b8d6ab..eece589a6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/chapter/BookletChapter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/chapter/BookletChapter.java @@ -18,19 +18,20 @@ import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil; import net.minecraft.item.ItemStack; import net.minecraft.util.text.TextFormatting; +import org.apache.commons.lang3.ArrayUtils; public class BookletChapter implements IBookletChapter{ public final BookletPage[] pages; public final IBookletEntry entry; public final ItemStack displayStack; - private final String unlocalizedName; + private final String identifier; public TextFormatting color; - public BookletChapter(String unlocalizedName, IBookletEntry entry, ItemStack displayStack, BookletPage... pages){ + public BookletChapter(String identifier, IBookletEntry entry, ItemStack displayStack, BookletPage... pages){ this.pages = pages.clone(); - this.unlocalizedName = unlocalizedName; + this.identifier = identifier; entry.addChapter(this); ActuallyAdditionsAPI.allAndSearch.addChapter(this); this.entry = entry; @@ -49,13 +50,18 @@ public class BookletChapter implements IBookletChapter{ } @Override - public String getUnlocalizedName(){ - return this.unlocalizedName; + public BookletPage getPageById(int id){ + return this.getPages()[id-1]; + } + + @Override + public int getPageId(BookletPage page){ + return ArrayUtils.indexOf(this.getPages(), page)+1; } @Override public String getLocalizedName(){ - return StringUtil.localize("booklet."+ModUtil.MOD_ID+".chapter."+this.unlocalizedName+".name"); + return StringUtil.localize("booklet."+ModUtil.MOD_ID+".chapter."+this.getIdentifier()+".name"); } @Override @@ -73,6 +79,11 @@ public class BookletChapter implements IBookletChapter{ return this.displayStack; } + @Override + public String getIdentifier(){ + return this.identifier; + } + public void setImportant(){ this.color = TextFormatting.DARK_GREEN; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/BookletEntry.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/BookletEntry.java index a1d7902bd..5760af45b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/BookletEntry.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/BookletEntry.java @@ -22,12 +22,12 @@ import java.util.List; public class BookletEntry implements IBookletEntry{ - private final String unlocalizedName; + private final String identifier; public List chapters = new ArrayList(); private TextFormatting color; - public BookletEntry(String unlocalizedName){ - this.unlocalizedName = unlocalizedName; + public BookletEntry(String identifier){ + this.identifier = identifier; ActuallyAdditionsAPI.addBookletEntry(this); this.color = TextFormatting.RESET; @@ -44,13 +44,13 @@ public class BookletEntry implements IBookletEntry{ } @Override - public String getUnlocalizedName(){ - return this.unlocalizedName; + public String getIdentifier(){ + return this.identifier; } @Override public String getLocalizedName(){ - return StringUtil.localize("booklet."+ModUtil.MOD_ID+".indexEntry."+this.unlocalizedName+".name"); + return StringUtil.localize("booklet."+ModUtil.MOD_ID+".indexEntry."+this.getIdentifier()+".name"); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/EntrySet.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/EntrySet.java index 1c47892fa..68930377b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/EntrySet.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/EntrySet.java @@ -19,10 +19,10 @@ import net.minecraft.nbt.NBTTagCompound; public class EntrySet implements IEntrySet{ - public BookletPage page; - public IBookletChapter chapter; - public IBookletEntry entry; - public int pageInIndex; + private BookletPage page; + private IBookletChapter chapter; + private IBookletEntry entry; + private int pageInIndex; public EntrySet(IBookletEntry entry){ this(null, null, entry, 1); @@ -34,17 +34,27 @@ public class EntrySet implements IEntrySet{ public static EntrySet readFromNBT(NBTTagCompound compound){ if(compound != null){ - if(compound.hasKey("Entry")){ - int entry = compound.getInteger("Entry"); - int chapter = compound.getInteger("Chapter"); - int page = compound.getInteger("Page"); + String entryName = compound.getString("Entry"); + if(!entryName.isEmpty()){ + for(IBookletEntry entry : ActuallyAdditionsAPI.BOOKLET_ENTRIES){ + if(entryName.equals(entry.getIdentifier())){ + int indexPage = compound.getInteger("PageInIndex"); - IBookletEntry currentEntry = entry == -1 ? null : ActuallyAdditionsAPI.BOOKLET_ENTRIES.get(entry); - IBookletChapter currentChapter = chapter == -1 || entry == -1 || currentEntry.getChapters().size() <= chapter ? null : currentEntry.getChapters().get(chapter); - BookletPage currentPage = chapter == -1 || currentChapter == null || currentChapter.getPages().length <= page-1 ? null : currentChapter.getPages()[page-1]; - int pageInIndex = compound.getInteger("PageInIndex"); - - return new EntrySet(currentPage, currentChapter, currentEntry, pageInIndex); + String chapterName = compound.getString("Chapter"); + if(!chapterName.isEmpty()){ + for(IBookletChapter chapter : entry.getChapters()){ + if(chapterName.equals(chapter.getIdentifier())){ + int page = compound.getInteger("Page"); + if(page != -1){ + return new EntrySet(chapter.getPageById(page), chapter, entry, indexPage); + } + break; + } + } + } + return new EntrySet(null, null, entry, indexPage); + } + } } } return new EntrySet(null); @@ -66,10 +76,11 @@ public class EntrySet implements IEntrySet{ @Override public NBTTagCompound writeToNBT(){ NBTTagCompound compound = new NBTTagCompound(); - compound.setInteger("Entry", this.entry == null ? -1 : ActuallyAdditionsAPI.BOOKLET_ENTRIES.indexOf(this.entry)); - compound.setInteger("Chapter", this.entry == null || this.chapter == null ? -1 : this.entry.getChapters().indexOf(this.chapter)); - compound.setInteger("Page", this.page == null ? -1 : this.page.getID()); compound.setInteger("PageInIndex", this.pageInIndex); + compound.setString("Entry", this.entry != null ? this.entry.getIdentifier() : ""); + compound.setString("Chapter", this.chapter != null ? this.chapter.getIdentifier() : ""); + compound.setInteger("Page", this.page != null ? this.page.getChapter().getPageId(this.page) : -1); + return compound; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/BookletPageAA.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/BookletPageAA.java index ef2022ff8..04d0ba850 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/BookletPageAA.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/BookletPageAA.java @@ -35,7 +35,7 @@ public class BookletPageAA extends BookletPage{ @Override public int getID(){ - return ArrayUtils.indexOf(this.chapter.getPages(), this)+1; + return this.chapter.getPageId(this); } @Override @@ -44,7 +44,7 @@ public class BookletPageAA extends BookletPage{ return null; } - String base = StringUtil.localize("booklet."+ModUtil.MOD_ID+".chapter."+this.chapter.getUnlocalizedName()+".text."+this.localizationKey); + String base = StringUtil.localize("booklet."+ModUtil.MOD_ID+".chapter."+this.chapter.getIdentifier()+".text."+this.localizationKey); base = base.replaceAll("", TextFormatting.DARK_GREEN+""); base = base.replaceAll("", TextFormatting.BLUE+""); base = base.replaceAll("", TextFormatting.BLACK+""); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageButton.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageButton.java index a30b06d7f..b54693f5e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageButton.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageButton.java @@ -26,7 +26,7 @@ public abstract class PageButton extends PageTextOnly{ @Override public void onOpened(IBookletGui gui){ - String text = StringUtil.localize("booklet."+ModUtil.MOD_ID+".chapter."+this.chapter.getUnlocalizedName()+".page."+this.localizationKey+".button"); + String text = StringUtil.localize("booklet."+ModUtil.MOD_ID+".chapter."+this.chapter.getIdentifier()+".page."+this.localizationKey+".button"); int width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(text); this.button = new GuiButton(-1239, gui.getGuiLeft()+gui.getXSize()/2-width/2-8, gui.getGuiTop()+gui.getYSize()-40, width+15, 20, text); gui.getButtonList().add(this.button); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/MethodHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/MethodHandler.java index 32a64c712..8ec7f781b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/MethodHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/MethodHandler.java @@ -214,7 +214,7 @@ public class MethodHandler implements IMethodHandler{ } @Override - public IBookletChapter generateBookletChapter(String unlocalizedName, IBookletEntry entry, ItemStack displayStack, BookletPage... pages){ - return new BookletChapter(unlocalizedName, entry, displayStack, pages); + public IBookletChapter generateBookletChapter(String identifier, IBookletEntry entry, ItemStack displayStack, BookletPage... pages){ + return new BookletChapter(identifier, entry, displayStack, pages); } }