mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-25 22:44:51 +00:00
Make IVersionedTransformer.UNSTAMPED the only unstamped constant
This commit is contained in:
4 files changed
+7
-9
No files matched your search
@@ -1,7 +1,5 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
import com.gtnewhorizons.postea.utility.VersionStamps;
|
||||
|
||||
/// Upgrades saved chunks, players and custom world storage written under another version of a mod's content.
|
||||
///
|
||||
/// Postea stamps everything it saves with [#currentVersion()] under [#key()]. On read, the transformer runs for every
|
||||
@@ -19,7 +17,7 @@ import com.gtnewhorizons.postea.utility.VersionStamps;
|
||||
/// [#transformCustomData].
|
||||
public interface IVersionedTransformer {
|
||||
|
||||
int UNSTAMPED = VersionStamps.UNSTAMPED;
|
||||
int UNSTAMPED = -1;
|
||||
|
||||
/// The stamp key, unique across all registered transformers, e.g. `"examplemod:idList"`. Must return the same
|
||||
/// value for the transformer's lifetime.
|
||||
|
||||
@@ -14,7 +14,6 @@ import com.gtnewhorizons.postea.api.IVersionedTransformer;
|
||||
public final class VersionStamps {
|
||||
|
||||
public static final String KEY = "POSTEA_VERSIONS";
|
||||
public static final int UNSTAMPED = -1;
|
||||
|
||||
private VersionStamps() {}
|
||||
|
||||
@@ -23,9 +22,9 @@ public final class VersionStamps {
|
||||
return container.hasKey(KEY, TAG_COMPOUND) ? container.getCompoundTag(KEY) : null;
|
||||
}
|
||||
|
||||
/// The version stored for `key` in `stamps`, or [#UNSTAMPED]. `stamps` may be null.
|
||||
/// The version stored for `key` in `stamps`, or [IVersionedTransformer#UNSTAMPED]. `stamps` may be null.
|
||||
public static int stored(NBTTagCompound stamps, String key) {
|
||||
return stamps != null && stamps.hasKey(key, TAG_INT) ? stamps.getInteger(key) : UNSTAMPED;
|
||||
return stamps != null && stamps.hasKey(key, TAG_INT) ? stamps.getInteger(key) : IVersionedTransformer.UNSTAMPED;
|
||||
}
|
||||
|
||||
/// Writes the stamps onto `container`: `carried`, the stamps the data was read with or null, with every
|
||||
|
||||
@@ -18,7 +18,7 @@ public final class VersionedTransformerLog {
|
||||
Postea.LOG.info(
|
||||
"{} is bringing saved data from version {} to {}",
|
||||
transformer.key(),
|
||||
stored == VersionStamps.UNSTAMPED ? "unstamped" : String.valueOf(stored),
|
||||
stored == IVersionedTransformer.UNSTAMPED ? "unstamped" : String.valueOf(stored),
|
||||
current);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ 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 {
|
||||
@@ -18,7 +19,7 @@ class VersionStampsTest {
|
||||
NBTTagCompound container = new NBTTagCompound();
|
||||
|
||||
assertNull(VersionStamps.read(container));
|
||||
assertEquals(VersionStamps.UNSTAMPED, VersionStamps.stored(null, "mod:key"));
|
||||
assertEquals(IVersionedTransformer.UNSTAMPED, VersionStamps.stored(null, "mod:key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -28,6 +29,6 @@ class VersionStampsTest {
|
||||
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"));
|
||||
assertEquals(IVersionedTransformer.UNSTAMPED, VersionStamps.stored(VersionStamps.read(container), "other:key"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user