mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-25 22:44:51 +00:00
Keep version stamps of absent transformers on rebuilt custom data roots
This commit is contained in:
4 files changed
+95
-45
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.gtnewhorizons.postea.utility.VersionStamps;
|
||||
|
||||
class CustomDataReplacementManagerTest {
|
||||
|
||||
@Test
|
||||
void aRebuiltRootKeepsTheStampOfATransformerThatIsNotRegistered() {
|
||||
StubTransformer present = new StubTransformer("mod:present", 2);
|
||||
StubTransformer absent = new StubTransformer("mod:absent", 5);
|
||||
NBTTagCompound original = new NBTTagCompound();
|
||||
CustomDataReplacementManager.transform("mod:storage", original, Arrays.asList(present, absent));
|
||||
NBTTagCompound saved = CustomDataReplacementManager.savedStamps(original);
|
||||
|
||||
present.version = 3;
|
||||
NBTTagCompound rebuilt = new NBTTagCompound();
|
||||
CustomDataReplacementManager.stamp(rebuilt, saved, Collections.singletonList(present));
|
||||
|
||||
NBTTagCompound stamps = VersionStamps.read(rebuilt);
|
||||
assertEquals(3, VersionStamps.stored(stamps, "mod:present"));
|
||||
assertEquals(5, VersionStamps.stored(stamps, "mod:absent"));
|
||||
assertEquals(2, VersionStamps.stored(saved, "mod:present"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
/// An [IVersionedTransformer] that changes nothing, at a version the test sets.
|
||||
public final class StubTransformer implements IVersionedTransformer {
|
||||
|
||||
private final String key;
|
||||
public int version;
|
||||
|
||||
public StubTransformer(String key, int version) {
|
||||
this.key = key;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int currentVersion() {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
@@ -9,25 +9,10 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.gtnewhorizons.postea.api.IVersionedTransformer;
|
||||
import com.gtnewhorizons.postea.api.StubTransformer;
|
||||
|
||||
class VersionStampsTest {
|
||||
|
||||
private static IVersionedTransformer transformer(String key, int version) {
|
||||
return new IVersionedTransformer() {
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int currentVersion() {
|
||||
return version;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnstampedContainerReadsAsUnstamped() {
|
||||
NBTTagCompound container = new NBTTagCompound();
|
||||
@@ -36,26 +21,11 @@ class VersionStampsTest {
|
||||
assertEquals(VersionStamps.UNSTAMPED, VersionStamps.stored(null, "mod:key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void writeStampsRegisteredKeysAtTheirCurrentVersionAndCarriesUnknownKeys() {
|
||||
NBTTagCompound carried = new NBTTagCompound();
|
||||
carried.setInteger("absentmod:key", 7);
|
||||
carried.setInteger("mod:key", 2);
|
||||
NBTTagCompound container = new NBTTagCompound();
|
||||
|
||||
VersionStamps.write(container, carried, Collections.singletonList(transformer("mod:key", 3)));
|
||||
|
||||
NBTTagCompound stamps = VersionStamps.read(container);
|
||||
assertEquals(3, VersionStamps.stored(stamps, "mod:key"));
|
||||
assertEquals(7, VersionStamps.stored(stamps, "absentmod:key"));
|
||||
assertEquals(2, carried.getInteger("mod:key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void writeWithoutCarriedStampsWritesOnlyRegisteredKeys() {
|
||||
NBTTagCompound container = new NBTTagCompound();
|
||||
|
||||
VersionStamps.write(container, null, Collections.singletonList(transformer("mod:key", 1)));
|
||||
VersionStamps.write(container, null, Collections.singletonList(new StubTransformer("mod:key", 1)));
|
||||
|
||||
assertEquals(1, VersionStamps.stored(VersionStamps.read(container), "mod:key"));
|
||||
assertEquals(VersionStamps.UNSTAMPED, VersionStamps.stored(VersionStamps.read(container), "other:key"));
|
||||
|
||||
Reference in new issue
Block a user