mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-25 22:34:33 +00:00
Transform mail boxes through Postea's custom data API
This commit is contained in:
3 files changed
+40
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user