From c8e90aefd7c154770ca31e2260e0581aedff1056 Mon Sep 17 00:00:00 2001 From: Mrbysco Date: Wed, 20 Nov 2024 15:17:34 +0100 Subject: [PATCH] Remove old book related data from PlayerData --- .../mod/data/PlayerData.java | 109 +++++++++--------- .../mod/network/PacketHelperClient.java | 38 +++--- .../network/handler/ServerPayloadHandler.java | 24 ++-- 3 files changed, 82 insertions(+), 89 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/data/PlayerData.java b/src/main/java/de/ellpeck/actuallyadditions/mod/data/PlayerData.java index d8dcd5b30..d2bac2d4d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/data/PlayerData.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/data/PlayerData.java @@ -10,15 +10,10 @@ package de.ellpeck.actuallyadditions.mod.data; -import de.ellpeck.actuallyadditions.api.booklet.IBookletPage; import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.StringTag; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.player.Player; -import java.util.ArrayList; -import java.util.List; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -54,13 +49,13 @@ public final class PlayerData { public UUID id; public boolean bookGottenAlready; - public boolean didBookTutorial; +// public boolean didBookTutorial; public boolean hasBatWings; public boolean shouldDisableBatWings; public int batWingsFlyTime; - public IBookletPage[] bookmarks = new IBookletPage[12]; - public List completedTrials = new ArrayList<>(); +// public IBookletPage[] bookmarks = new IBookletPage[12]; +// public List completedTrials = new ArrayList<>(); // // public GuiBooklet lastOpenBooklet; @@ -71,16 +66,16 @@ public final class PlayerData { public void readFromNBT(CompoundTag compound, boolean savingToFile) { this.bookGottenAlready = compound.getBoolean("BookGotten"); - this.didBookTutorial = compound.getBoolean("DidTutorial"); +// this.didBookTutorial = compound.getBoolean("DidTutorial"); this.hasBatWings = compound.getBoolean("HasBatWings"); this.batWingsFlyTime = compound.getInt("BatWingsFlyTime"); - ListTag bookmarks = compound.getList("Bookmarks", 8); - this.loadBookmarks(bookmarks); - - ListTag trials = compound.getList("Trials", 8); - this.loadTrials(trials); +// ListTag bookmarks = compound.getList("Bookmarks", 8); +// this.loadBookmarks(bookmarks); +// +// ListTag trials = compound.getList("Trials", 8); +// this.loadTrials(trials); if (!savingToFile) { this.shouldDisableBatWings = compound.getBoolean("ShouldDisableWings"); @@ -89,59 +84,59 @@ public final class PlayerData { public void writeToNBT(CompoundTag compound, boolean savingToFile) { compound.putBoolean("BookGotten", this.bookGottenAlready); - compound.putBoolean("DidTutorial", this.didBookTutorial); +// compound.putBoolean("DidTutorial", this.didBookTutorial); compound.putBoolean("HasBatWings", this.hasBatWings); compound.putInt("BatWingsFlyTime", this.batWingsFlyTime); - compound.put("Bookmarks", this.saveBookmarks()); - compound.put("Trials", this.saveTrials()); +// compound.put("Bookmarks", this.saveBookmarks()); +// compound.put("Trials", this.saveTrials()); if (!savingToFile) { compound.putBoolean("ShouldDisableWings", this.shouldDisableBatWings); } } - public ListTag saveBookmarks() { - ListTag bookmarks = new ListTag(); - for (IBookletPage bookmark : this.bookmarks) { - bookmarks.add(StringTag.valueOf(bookmark == null - ? "" - : bookmark.getIdentifier())); - } - return bookmarks; - } - - public void loadBookmarks(ListTag bookmarks) { - for (int i = 0; i < bookmarks.size(); i++) { - String strg = bookmarks.getString(i); - if (!strg.isEmpty()) { -// IBookletPage page = BookletUtils.getBookletPageById(strg); - this.bookmarks[i] = null; // page; - } else { - this.bookmarks[i] = null; - } - } - } - - public ListTag saveTrials() { - ListTag trials = new ListTag(); - for (String trial : this.completedTrials) { - trials.add(StringTag.valueOf(trial)); - } - return trials; - } - - public void loadTrials(ListTag trials) { - this.completedTrials.clear(); - - for (int i = 0; i < trials.size(); i++) { - String strg = trials.getString(i); - if (!strg.isEmpty()) { - this.completedTrials.add(strg); - } - } - } +// public ListTag saveBookmarks() { +// ListTag bookmarks = new ListTag(); +// for (IBookletPage bookmark : this.bookmarks) { +// bookmarks.add(StringTag.valueOf(bookmark == null +// ? "" +// : bookmark.getIdentifier())); +// } +// return bookmarks; +// } +// +// public void loadBookmarks(ListTag bookmarks) { +// for (int i = 0; i < bookmarks.size(); i++) { +// String strg = bookmarks.getString(i); +// if (!strg.isEmpty()) { +//// IBookletPage page = BookletUtils.getBookletPageById(strg); +// this.bookmarks[i] = null; // page; +// } else { +// this.bookmarks[i] = null; +// } +// } +// } +// +// public ListTag saveTrials() { +// ListTag trials = new ListTag(); +// for (String trial : this.completedTrials) { +// trials.add(StringTag.valueOf(trial)); +// } +// return trials; +// } +// +// public void loadTrials(ListTag trials) { +// this.completedTrials.clear(); +// +// for (int i = 0; i < trials.size(); i++) { +// String strg = trials.getString(i); +// if (!strg.isEmpty()) { +// this.completedTrials.add(strg); +// } +// } +// } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHelperClient.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHelperClient.java index b6a64f2ca..8e86882c9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHelperClient.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHelperClient.java @@ -10,8 +10,6 @@ package de.ellpeck.actuallyadditions.mod.network; -import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; -import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter; import de.ellpeck.actuallyadditions.mod.data.PlayerData; import de.ellpeck.actuallyadditions.mod.data.PlayerData.PlayerSave; import de.ellpeck.actuallyadditions.mod.network.packet.ButtonToTilePacket; @@ -44,24 +42,24 @@ public final class PacketHelperClient { PlayerSave data = PlayerData.getDataFromPlayer(player); - if (type == 0) { - compound.put("Bookmarks", data.saveBookmarks()); - } else if (type == 1) { - compound.putBoolean("DidBookTutorial", data.didBookTutorial); - } else if (type == 2) { - compound.put("Trials", data.saveTrials()); - - int total = 0; - for (IBookletChapter chapter : ActuallyAdditionsAPI.entryTrials.getAllChapters()) { - //if (chapter instanceof BookletChapterTrials) { - // total++; - //} - } - - if (data.completedTrials.size() >= total) { - compound.putBoolean("Achievement", true); - } - } +// if (type == 0) { +// compound.put("Bookmarks", data.saveBookmarks()); +// } else if (type == 1) { +// compound.putBoolean("DidBookTutorial", data.didBookTutorial); +// } else if (type == 2) { +// compound.put("Trials", data.saveTrials()); +// +// int total = 0; +// for (IBookletChapter chapter : ActuallyAdditionsAPI.entryTrials.getAllChapters()) { +// //if (chapter instanceof BookletChapterTrials) { +// // total++; +// //} +// } +// +// if (data.completedTrials.size() >= total) { +// compound.putBoolean("Achievement", true); +// } +// } PacketDistributor.sendToServer(new SyncPlayerPacket(compound)); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/handler/ServerPayloadHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/handler/ServerPayloadHandler.java index 6670efcfc..7b8ad7fa4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/handler/ServerPayloadHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/handler/ServerPayloadHandler.java @@ -121,18 +121,18 @@ public class ServerPayloadHandler { if (player != null) { PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player); - int type = tag.getInt("Type"); - if (type == 0) { - data.loadBookmarks(tag.getList("Bookmarks", 8)); - } else if (type == 1) { - data.didBookTutorial = tag.getBoolean("DidBookTutorial"); - } else if (type == 2) { - data.loadTrials(tag.getList("Trials", 8)); - - if (tag.getBoolean("Achievement")) { - //TheAchievements.COMPLETE_TRIALS.get(player); - } - } +// int type = tag.getInt("Type"); +// if (type == 0) { +// data.loadBookmarks(tag.getList("Bookmarks", 8)); +// } else if (type == 1) { +// data.didBookTutorial = tag.getBoolean("DidBookTutorial"); +// } else if (type == 2) { +// data.loadTrials(tag.getList("Trials", 8)); +// +// if (tag.getBoolean("Achievement")) { +// //TheAchievements.COMPLETE_TRIALS.get(player); +// } +// } WorldData.get(level).setDirty(); if (tag.getBoolean("Log")) {