mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-25 16:38:33 +01:00
Made Booklet save its data via identifiers instead of number ids
This commit is contained in:
parent
388123741c
commit
a3c1d7e110
15 changed files with 89 additions and 63 deletions
|
@ -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<CrusherRecipe> CRUSHER_RECIPES = new ArrayList<CrusherRecipe>();
|
||||
public static final List<BallOfFurReturn> BALL_OF_FUR_RETURN_ITEMS = new ArrayList<BallOfFurReturn>();
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public interface IBookletEntry{
|
|||
|
||||
void setChapters(List<IBookletChapter> chapters);
|
||||
|
||||
String getUnlocalizedName();
|
||||
String getIdentifier();
|
||||
|
||||
String getLocalizedName();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -22,12 +22,12 @@ import java.util.List;
|
|||
|
||||
public class BookletEntry implements IBookletEntry{
|
||||
|
||||
private final String unlocalizedName;
|
||||
private final String identifier;
|
||||
public List<IBookletChapter> chapters = new ArrayList<IBookletChapter>();
|
||||
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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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("<imp>", TextFormatting.DARK_GREEN+"");
|
||||
base = base.replaceAll("<item>", TextFormatting.BLUE+"");
|
||||
base = base.replaceAll("<r>", TextFormatting.BLACK+"");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue