changed EntrySet NBT methods

This commit is contained in:
Ellpeck 2016-09-09 17:58:34 +02:00
parent 9f314cf51d
commit 2fea0d3c6d
6 changed files with 27 additions and 19 deletions

View file

@ -21,7 +21,9 @@ public interface IEntrySet{
void removeEntry(); void removeEntry();
NBTTagCompound writeToNBT(); void writeToNBT(NBTTagCompound compound);
void readFromNBT(NBTTagCompound compound);
BookletPage getCurrentPage(); BookletPage getCurrentPage();

View file

@ -14,7 +14,6 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.booklet.BookletPage; import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter; import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry; import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
import de.ellpeck.actuallyadditions.mod.achievement.InitAchievements;
import de.ellpeck.actuallyadditions.mod.achievement.TheAchievements; import de.ellpeck.actuallyadditions.mod.achievement.TheAchievements;
import de.ellpeck.actuallyadditions.mod.booklet.button.BookmarkButton; import de.ellpeck.actuallyadditions.mod.booklet.button.BookmarkButton;
import de.ellpeck.actuallyadditions.mod.booklet.button.IndexButton; import de.ellpeck.actuallyadditions.mod.booklet.button.IndexButton;
@ -32,7 +31,6 @@ import net.minecraft.client.gui.GuiScreen;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
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.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
@ -504,7 +502,9 @@ public final class BookletUtils{
@SideOnly(Side.CLIENT) @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()); NBTTagCompound tag = new NBTTagCompound();
gui.currentEntrySet.writeToNBT(tag);
compound.setTag("SavedEntry", tag);
compound.setString("SearchWord", gui.searchField.getText()); compound.setString("SearchWord", gui.searchField.getText());
//Save Bookmarks //Save Bookmarks
@ -512,7 +512,9 @@ public final class BookletUtils{
for(int i = 0; i < gui.bookmarkButtons.length; i++){ for(int i = 0; i < gui.bookmarkButtons.length; i++){
BookmarkButton button = (BookmarkButton)gui.bookmarkButtons[i]; BookmarkButton button = (BookmarkButton)gui.bookmarkButtons[i];
list.appendTag(button.assignedEntry.writeToNBT()); NBTTagCompound buttonTag = new NBTTagCompound();
button.assignedEntry.writeToNBT(buttonTag);
list.appendTag(buttonTag);
} }
compound.setTag("Bookmarks", list); compound.setTag("Bookmarks", list);
} }
@ -520,7 +522,8 @@ public final class BookletUtils{
@SideOnly(Side.CLIENT) @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 = new EntrySet(null);
set.readFromNBT(compound.getCompoundTag("SavedEntry"));
if(set != null){ if(set != null){
BookletUtils.openIndexEntry(gui, set.getCurrentEntry(), set.getPageInIndex(), true); BookletUtils.openIndexEntry(gui, set.getCurrentEntry(), set.getPageInIndex(), true);
@ -544,7 +547,7 @@ public final class BookletUtils{
if(list != null){ if(list != null){
for(int i = 0; i < list.tagCount(); i++){ for(int i = 0; i < list.tagCount(); i++){
BookmarkButton button = (BookmarkButton)gui.bookmarkButtons[i]; BookmarkButton button = (BookmarkButton)gui.bookmarkButtons[i];
button.assignedEntry = EntrySet.readFromNBT(list.getCompoundTagAt(i)); button.assignedEntry.readFromNBT(list.getCompoundTagAt(i));
} }
} }
} }

View file

@ -41,7 +41,9 @@ public class GuiBookletStand extends GuiBooklet{
compound.setInteger("Z", this.theStand.getPos().getZ()); compound.setInteger("Z", this.theStand.getPos().getZ());
compound.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId()); compound.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId());
compound.setInteger("WorldID", this.theStand.getWorld().provider.getDimension()); compound.setInteger("WorldID", this.theStand.getWorld().provider.getDimension());
compound.setTag("EntrySet", this.currentEntrySet.writeToNBT()); NBTTagCompound tag = new NBTTagCompound();
this.currentEntrySet.writeToNBT(tag);
compound.setTag("EntrySet", tag);
PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.BOOKLET_STAND_BUTTON_HANDLER)); PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.BOOKLET_STAND_BUTTON_HANDLER));
} }
super.actionPerformed(button); super.actionPerformed(button);

View file

@ -32,7 +32,8 @@ public class EntrySet implements IEntrySet{
this.setEntry(page, chapter, entry, pageInIndex); this.setEntry(page, chapter, entry, pageInIndex);
} }
public static EntrySet readFromNBT(NBTTagCompound compound){ @Override
public void readFromNBT(NBTTagCompound compound){
if(compound != null){ if(compound != null){
String entryName = compound.getString("Entry"); String entryName = compound.getString("Entry");
if(!entryName.isEmpty()){ if(!entryName.isEmpty()){
@ -46,18 +47,19 @@ public class EntrySet implements IEntrySet{
if(chapterName.equals(chapter.getIdentifier())){ if(chapterName.equals(chapter.getIdentifier())){
int page = compound.getInteger("Page"); int page = compound.getInteger("Page");
if(page != -1){ if(page != -1){
return new EntrySet(chapter.getPageById(page), chapter, entry, indexPage); this.page = chapter.getPageById(page);
this.chapter = chapter;
} }
break; break;
} }
} }
} }
return new EntrySet(null, null, entry, indexPage); this.entry = entry;
this.pageInIndex = indexPage;
} }
} }
} }
} }
return new EntrySet(null);
} }
@Override @Override
@ -74,14 +76,11 @@ public class EntrySet implements IEntrySet{
} }
@Override @Override
public NBTTagCompound writeToNBT(){ public void writeToNBT(NBTTagCompound compound){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("PageInIndex", this.pageInIndex); compound.setInteger("PageInIndex", this.pageInIndex);
compound.setString("Entry", this.entry != null ? this.entry.getIdentifier() : ""); compound.setString("Entry", this.entry != null ? this.entry.getIdentifier() : "");
compound.setString("Chapter", this.chapter != null ? this.chapter.getIdentifier() : ""); compound.setString("Chapter", this.chapter != null ? this.chapter.getIdentifier() : "");
compound.setInteger("Page", this.page != null ? this.page.getChapter().getPageId(this.page) : -1); compound.setInteger("Page", this.page != null ? this.page.getChapter().getPageId(this.page) : -1);
return compound;
} }
@Override @Override

View file

@ -138,7 +138,7 @@ public final class PacketHandler{
if(player != null && tile instanceof TileEntityBookletStand){ if(player != null && tile instanceof TileEntityBookletStand){
TileEntityBookletStand stand = (TileEntityBookletStand)tile; TileEntityBookletStand stand = (TileEntityBookletStand)tile;
if(player.getName() != null && player.getName().equalsIgnoreCase(stand.assignedPlayer)){ if(player.getName() != null && player.getName().equalsIgnoreCase(stand.assignedPlayer)){
stand.assignedEntry = EntrySet.readFromNBT(compound.getCompoundTag("EntrySet")); stand.assignedEntry.readFromNBT(compound.getCompoundTag("EntrySet"));
stand.markDirty(); stand.markDirty();
stand.sendUpdate(); stand.sendUpdate();
} }

View file

@ -26,7 +26,9 @@ public class TileEntityBookletStand extends TileEntityBase{
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){ public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type); super.writeSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){ if(type != NBTType.SAVE_BLOCK){
compound.setTag("SavedEntry", this.assignedEntry.writeToNBT()); NBTTagCompound tag = new NBTTagCompound();
this.assignedEntry.writeToNBT(tag);
compound.setTag("SavedEntry", tag);
if(this.assignedPlayer != null){ if(this.assignedPlayer != null){
compound.setString("Player", this.assignedPlayer); compound.setString("Player", this.assignedPlayer);
@ -38,7 +40,7 @@ public class TileEntityBookletStand extends TileEntityBase{
public void readSyncableNBT(NBTTagCompound compound, NBTType type){ public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type); super.readSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){ if(type != NBTType.SAVE_BLOCK){
this.assignedEntry = EntrySet.readFromNBT(compound.getCompoundTag("SavedEntry")); this.assignedEntry.readFromNBT(compound.getCompoundTag("SavedEntry"));
this.assignedPlayer = compound.getString("Player"); this.assignedPlayer = compound.getString("Player");
} }
} }