From ebfdf989cd0554f9ed004874dcd7fcf6b02dd96e Mon Sep 17 00:00:00 2001 From: Ruling-0 <47913168+Ruling-0@users.noreply.github.com> Date: Tue, 24 Nov 2026 15:37:36 -0600 Subject: [PATCH] Carry Postea stamps of absent transformers across post box saves --- .../forestry/core/utils/PosteaCompat.java | 24 +++++++++++++------ .../java/forestry/mail/MailSavedData.java | 4 +++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/forestry/core/utils/PosteaCompat.java b/src/main/java/forestry/core/utils/PosteaCompat.java index 0f74b4c09..1667ffdc2 100644 --- a/src/main/java/forestry/core/utils/PosteaCompat.java +++ b/src/main/java/forestry/core/utils/PosteaCompat.java @@ -1,13 +1,12 @@ package forestry.core.utils; -import com.gtnewhorizons.postea.api.IVersionedTransformer; import net.minecraft.nbt.NBTTagCompound; import com.gtnewhorizons.postea.api.CustomDataReplacementManager; import cpw.mods.fml.common.Loader; -/// Used to provide custom save data (like mail boxes) to Postea's [IVersionedTransformer]s. +/// Used to provide custom save data (like mail boxes) to Postea's versioned transformers. /// /// These transformers allow other mods to change saved data based on their own version stamps. This compat flags, /// to those transformers, the times they should fire. [#transform] is used before consuming data, so the transformer @@ -23,9 +22,16 @@ public final class PosteaCompat { if (POSTEA) Impl.transform(storageId, root); } - /// Stamps a freshly built root about to be written to disk. - public static void stamp(NBTTagCompound root) { - if (POSTEA) Impl.stamp(root); + /// A copy of the stamps on a root read from disk, or null when it carries none or Postea is absent. Call after + /// [#transform]. + public static NBTTagCompound savedStamps(NBTTagCompound root) { + return POSTEA ? Impl.savedStamps(root) : null; + } + + /// Stamps a freshly built root about to be written to disk, keeping the stamps in `carried` (from [#savedStamps]) + /// for transformers not registered now. `carried` may be null. + public static void stamp(NBTTagCompound root, NBTTagCompound carried) { + if (POSTEA) Impl.stamp(root, carried); } private static final class Impl { @@ -34,8 +40,12 @@ public final class PosteaCompat { CustomDataReplacementManager.transform(storageId, root); } - static void stamp(NBTTagCompound root) { - CustomDataReplacementManager.stamp(root); + static NBTTagCompound savedStamps(NBTTagCompound root) { + return CustomDataReplacementManager.savedStamps(root); + } + + static void stamp(NBTTagCompound root, NBTTagCompound carried) { + CustomDataReplacementManager.stamp(root, carried); } } } diff --git a/src/main/java/forestry/mail/MailSavedData.java b/src/main/java/forestry/mail/MailSavedData.java index f2a1b1288..a14845f2f 100644 --- a/src/main/java/forestry/mail/MailSavedData.java +++ b/src/main/java/forestry/mail/MailSavedData.java @@ -13,6 +13,7 @@ import forestry.core.utils.PosteaCompat; public abstract class MailSavedData extends WorldSavedData { private RuntimeException loadFailure; + private NBTTagCompound savedStamps; protected MailSavedData(String mapName) { super(mapName); @@ -26,13 +27,14 @@ public abstract class MailSavedData extends WorldSavedData { loadFailure = e; throw e; } + savedStamps = PosteaCompat.savedStamps(root); readData(root); } @Override public final void writeToNBT(NBTTagCompound root) { writeData(root); - PosteaCompat.stamp(root); + PosteaCompat.stamp(root, savedStamps); } @Override