From a2a1f8eca9d339e2fb59b7e659e811dd4463926d Mon Sep 17 00:00:00 2001 From: Ruling-0 <47913168+Ruling-0@users.noreply.github.com> Date: Mon, 14 Sep 2026 23:55:46 -0500 Subject: [PATCH] Transform mail boxes through Postea's custom data API --- dependencies.gradle | 1 + .../forestry/core/utils/PosteaCompat.java | 36 +++++++++++++++++++ src/main/java/forestry/mail/POBox.java | 3 ++ 3 files changed, 40 insertions(+) create mode 100644 src/main/java/forestry/core/utils/PosteaCompat.java diff --git a/dependencies.gradle b/dependencies.gradle index d3b02db93..3911a69a6 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -9,5 +9,6 @@ dependencies { compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.57:api') compileOnly('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev') compileOnly('curse.maven:craftguide-75557:2459320') + compileOnly('com.github.GTNewHorizons:Postea:1.4.0-mu:dev') devOnlyNonPublishable('net.xonich.mc:NoHotbarNeeded:0.0.3:dev') } diff --git a/src/main/java/forestry/core/utils/PosteaCompat.java b/src/main/java/forestry/core/utils/PosteaCompat.java new file mode 100644 index 000000000..2a2e495d4 --- /dev/null +++ b/src/main/java/forestry/core/utils/PosteaCompat.java @@ -0,0 +1,36 @@ +package forestry.core.utils; + +import net.minecraft.nbt.NBTTagCompound; + +import cpw.mods.fml.common.Loader; + +/// Offers Forestry's mail boxes to Postea's custom world data API, so versioned transformers rewrite +/// their stacks exactly once per content version change. Safe to call without Postea installed: the Postea types +/// live in the inner holder, which only loads when the mod is present. +public final class PosteaCompat { + + private static final boolean POSTEA = Loader.isModLoaded("postea"); + + private PosteaCompat() {} + + /// Transforms a root read from disk in place; call before consuming it. + public static void transform(String storageId, NBTTagCompound root) { + 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); + } + + private static final class Impl { + + static void transform(String storageId, NBTTagCompound root) { + com.gtnewhorizons.postea.api.CustomDataReplacementManager.transform(storageId, root); + } + + static void stamp(NBTTagCompound root) { + com.gtnewhorizons.postea.api.CustomDataReplacementManager.stamp(root); + } + } +} diff --git a/src/main/java/forestry/mail/POBox.java b/src/main/java/forestry/mail/POBox.java index 2277c5c3e..7b63e53cd 100755 --- a/src/main/java/forestry/mail/POBox.java +++ b/src/main/java/forestry/mail/POBox.java @@ -19,6 +19,7 @@ import forestry.api.mail.IMailAddress; import forestry.api.mail.PostManager; import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.InventoryUtil; +import forestry.core.utils.PosteaCompat; public class POBox extends WorldSavedData implements IInventory { @@ -42,6 +43,7 @@ public class POBox extends WorldSavedData implements IInventory { @Override public void readFromNBT(NBTTagCompound nbttagcompound) { + PosteaCompat.transform("forestry:" + mapName, nbttagcompound); if (nbttagcompound.hasKey("address")) { this.address = MailAddress.loadFromNBT(nbttagcompound.getCompoundTag("address")); } @@ -56,6 +58,7 @@ public class POBox extends WorldSavedData implements IInventory { nbttagcompound.setTag("address", nbt); } letters.writeToNBT(nbttagcompound); + PosteaCompat.stamp(nbttagcompound); } public boolean storeLetter(ItemStack letterstack) {