mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-25 22:34:33 +00:00
Refuse post boxes whose Postea migration failed
This commit is contained in:
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);
|
||||
}
|
||||
Reference in new issue
Block a user