Refuse post boxes whose Postea migration failed

This commit is contained in:
Ruling-0 committed 2026-11-24 15:36:49 -06:00
1 parent 01d40092f3
commit 414d7da5c0
3 files changed
+55 -7

No files matched your search

@@ -0,0 +1,51 @@
package forestry.mail;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.WorldSavedData;
import forestry.core.utils.PosteaCompat;
/// A mail storage in the world's `MapStorage`, with saved item stacks migrated through Postea under the storage id
/// `forestry:<mapName>`.
///
/// `MapStorage` swallows load exceptions and keeps the half-read storage, so a storage whose migration failed is never
/// saved and [PostRegistry] rethrows the failure instead of serving it.
public abstract class MailSavedData extends WorldSavedData {
private RuntimeException loadFailure;
protected MailSavedData(String mapName) {
super(mapName);
}
@Override
public final void readFromNBT(NBTTagCompound root) {
try {
PosteaCompat.transform("forestry:" + mapName, root);
} catch (RuntimeException e) {
loadFailure = e;
throw e;
}
readData(root);
}
@Override
public final void writeToNBT(NBTTagCompound root) {
writeData(root);
PosteaCompat.stamp(root);
}
@Override
public boolean isDirty() {
return loadFailure == null && super.isDirty();
}
/// Throws the exception that failed this storage's migration, if one did.
void throwIfLoadFailed() {
if (loadFailure != null) throw loadFailure;
}
protected abstract void readData(NBTTagCompound root);
protected abstract void writeData(NBTTagCompound root);
}