mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-25 22:44:51 +00:00
Stamp transformed data with the current versions before it replaces the original
This commit is contained in:
2 files changed
+39
-3
No files matched your search
@@ -24,8 +24,8 @@ public final class VersionedPass {
|
||||
}
|
||||
|
||||
/// Runs `step` for every transformer whose stamp on `root` differs from its current version. The steps work on a
|
||||
/// copy of `root`, which replaces the contents of `root` once every step has succeeded. A failing step throws the
|
||||
/// [#failure] for `subjectName` and `subject`, and leaves `root` as read.
|
||||
/// copy of `root`, which is stamped with the current versions and replaces the contents of `root` once every step
|
||||
/// has succeeded. A failing step throws the [#failure] for `subjectName` and `subject`, and leaves `root` as read.
|
||||
///
|
||||
/// @return a copy of the stamps `root` was read with, or null if unstamped
|
||||
public static NBTTagCompound runAtomically(NBTTagCompound root, Iterable<IVersionedTransformer> transformers,
|
||||
@@ -47,7 +47,10 @@ public final class VersionedPass {
|
||||
throw failure(t, transformer, stored, current, subjectName, subject);
|
||||
}
|
||||
}
|
||||
if (working != null) replaceContents(root, working);
|
||||
if (working != null) {
|
||||
VersionStamps.write(working, carried, transformers);
|
||||
replaceContents(root, working);
|
||||
}
|
||||
return carried;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.gtnewhorizons.postea.utility.VersionStamps;
|
||||
import com.gtnewhorizons.postea.utility.VersionedPass;
|
||||
|
||||
class VersionedPassTest {
|
||||
|
||||
/// Data saved while a later step of the same load fails must not be transformed a second time on the next load.
|
||||
@Test
|
||||
void aTransformedRootCarriesTheCurrentStamps() {
|
||||
StubTransformer transformer = new StubTransformer("mod:t", 2);
|
||||
NBTTagCompound root = new NBTTagCompound();
|
||||
root.setString("data", "old");
|
||||
|
||||
VersionedPass.runAtomically(
|
||||
root,
|
||||
Collections.singletonList(transformer),
|
||||
"Player",
|
||||
"someone",
|
||||
(t, data, stored) -> data.setString("data", "new"));
|
||||
|
||||
assertEquals("new", root.getString("data"));
|
||||
assertEquals(2, VersionStamps.stored(VersionStamps.read(root), "mod:t"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user