From 2fea0d3c6d9b894af390cd93d7406f5d28703a52 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 9 Sep 2016 17:58:34 +0200 Subject: [PATCH] changed EntrySet NBT methods --- .../actuallyadditions/api/internal/IEntrySet.java | 4 +++- .../mod/booklet/BookletUtils.java | 15 +++++++++------ .../mod/booklet/GuiBookletStand.java | 4 +++- .../mod/booklet/entry/EntrySet.java | 15 +++++++-------- .../mod/network/PacketHandler.java | 2 +- .../mod/tile/TileEntityBookletStand.java | 6 ++++-- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/internal/IEntrySet.java b/src/main/java/de/ellpeck/actuallyadditions/api/internal/IEntrySet.java index 7340e315b..7509001b2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/internal/IEntrySet.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/internal/IEntrySet.java @@ -21,7 +21,9 @@ public interface IEntrySet{ void removeEntry(); - NBTTagCompound writeToNBT(); + void writeToNBT(NBTTagCompound compound); + + void readFromNBT(NBTTagCompound compound); BookletPage getCurrentPage(); 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 26d55cdd0..0b1f0451e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/BookletUtils.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/BookletUtils.java @@ -14,7 +14,6 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.booklet.BookletPage; import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter; 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.booklet.button.BookmarkButton; 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.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.stats.Achievement; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -504,7 +502,9 @@ public final class BookletUtils{ @SideOnly(Side.CLIENT) public static void saveBookPage(GuiBooklet gui, NBTTagCompound compound){ //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()); //Save Bookmarks @@ -512,7 +512,9 @@ public final class BookletUtils{ for(int i = 0; i < gui.bookmarkButtons.length; 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); } @@ -520,7 +522,8 @@ public final class BookletUtils{ @SideOnly(Side.CLIENT) public static void openLastBookPage(GuiBooklet gui, NBTTagCompound compound){ //Open Entry etc. - EntrySet set = EntrySet.readFromNBT(compound.getCompoundTag("SavedEntry")); + EntrySet set = new EntrySet(null); + set.readFromNBT(compound.getCompoundTag("SavedEntry")); if(set != null){ BookletUtils.openIndexEntry(gui, set.getCurrentEntry(), set.getPageInIndex(), true); @@ -544,7 +547,7 @@ public final class BookletUtils{ if(list != null){ for(int i = 0; i < list.tagCount(); i++){ BookmarkButton button = (BookmarkButton)gui.bookmarkButtons[i]; - button.assignedEntry = EntrySet.readFromNBT(list.getCompoundTagAt(i)); + button.assignedEntry.readFromNBT(list.getCompoundTagAt(i)); } } } 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 b9d335427..1b7f7fd9d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBookletStand.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBookletStand.java @@ -41,7 +41,9 @@ public class GuiBookletStand extends GuiBooklet{ compound.setInteger("Z", this.theStand.getPos().getZ()); compound.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId()); 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)); } super.actionPerformed(button); 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 68930377b..cb7655f55 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 @@ -32,7 +32,8 @@ public class EntrySet implements IEntrySet{ this.setEntry(page, chapter, entry, pageInIndex); } - public static EntrySet readFromNBT(NBTTagCompound compound){ + @Override + public void readFromNBT(NBTTagCompound compound){ if(compound != null){ String entryName = compound.getString("Entry"); if(!entryName.isEmpty()){ @@ -46,18 +47,19 @@ public class EntrySet implements IEntrySet{ if(chapterName.equals(chapter.getIdentifier())){ int page = compound.getInteger("Page"); if(page != -1){ - return new EntrySet(chapter.getPageById(page), chapter, entry, indexPage); + this.page = chapter.getPageById(page); + this.chapter = chapter; } break; } } } - return new EntrySet(null, null, entry, indexPage); + this.entry = entry; + this.pageInIndex = indexPage; } } } } - return new EntrySet(null); } @Override @@ -74,14 +76,11 @@ public class EntrySet implements IEntrySet{ } @Override - public NBTTagCompound writeToNBT(){ - NBTTagCompound compound = new NBTTagCompound(); + public void writeToNBT(NBTTagCompound compound){ 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; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java index 9a67f61d5..780e61be0 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java @@ -138,7 +138,7 @@ public final class PacketHandler{ if(player != null && tile instanceof TileEntityBookletStand){ TileEntityBookletStand stand = (TileEntityBookletStand)tile; 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.sendUpdate(); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBookletStand.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBookletStand.java index 390edccbe..6f80137e9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBookletStand.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBookletStand.java @@ -26,7 +26,9 @@ public class TileEntityBookletStand extends TileEntityBase{ public void writeSyncableNBT(NBTTagCompound compound, NBTType type){ super.writeSyncableNBT(compound, type); 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){ compound.setString("Player", this.assignedPlayer); @@ -38,7 +40,7 @@ public class TileEntityBookletStand extends TileEntityBase{ public void readSyncableNBT(NBTTagCompound compound, NBTType type){ super.readSyncableNBT(compound, type); if(type != NBTType.SAVE_BLOCK){ - this.assignedEntry = EntrySet.readFromNBT(compound.getCompoundTag("SavedEntry")); + this.assignedEntry.readFromNBT(compound.getCompoundTag("SavedEntry")); this.assignedPlayer = compound.getString("Player"); } }