mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-25 22:34:33 +00:00
Carry Postea stamps of absent transformers across post box saves
This commit is contained in:
2 files changed
+20
-8
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user