diff --git a/dependencies.gradle b/dependencies.gradle index ef4ce8e..50b5505 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,3 +1,4 @@ dependencies { devOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.8.93-GTNH:dev") + compileOnly("com.github.GTNewHorizons:Postea:1.4.0-mu:dev") } diff --git a/repositories.gradle b/repositories.gradle index c884390..033d07f 100644 --- a/repositories.gradle +++ b/repositories.gradle @@ -1,5 +1,5 @@ // Add any additional repositories for your dependencies here repositories { - + mavenLocal() } diff --git a/src/main/java/baubles/common/lib/PlayerHandler.java b/src/main/java/baubles/common/lib/PlayerHandler.java index bff378d..0cdefea 100644 --- a/src/main/java/baubles/common/lib/PlayerHandler.java +++ b/src/main/java/baubles/common/lib/PlayerHandler.java @@ -131,6 +131,7 @@ public class PlayerHandler { } if(data != null) { + PosteaCompat.transform("baubles:" + player.getCommandSenderName(), data); InventoryBaubles inventory = new InventoryBaubles(player); inventory.readNBT(data); playerBaublesServer.put(player.getCommandSenderName(), inventory); @@ -161,6 +162,7 @@ public class PlayerHandler { InventoryBaubles inventory = getPlayerBaubles(player); NBTTagCompound data = new NBTTagCompound(); inventory.saveNBT(data); + PosteaCompat.stamp(data); FileOutputStream fileoutputstream = new FileOutputStream(mainFile); CompressedStreamTools.writeCompressed(data, fileoutputstream); diff --git a/src/main/java/baubles/common/lib/PosteaCompat.java b/src/main/java/baubles/common/lib/PosteaCompat.java new file mode 100644 index 0000000..3696236 --- /dev/null +++ b/src/main/java/baubles/common/lib/PosteaCompat.java @@ -0,0 +1,36 @@ +package baubles.common.lib; + +import net.minecraft.nbt.NBTTagCompound; + +import cpw.mods.fml.common.Loader; + +/// Offers the per-player baubles files to Postea's custom world data API, so versioned transformers rewrite their +/// stacks exactly once per content version change. Safe to call without Postea installed: the Postea types live in +/// the inner holder, which only loads when the mod is present. +public final class PosteaCompat { + + private static final boolean POSTEA = Loader.isModLoaded("postea"); + + private PosteaCompat() {} + + /// Transforms a root read from disk in place; call before consuming it. + public static void transform(String storageId, NBTTagCompound root) { + if (POSTEA) Impl.transform(storageId, root); + } + + /// Stamps a freshly built root about to be written to disk. + public static void stamp(NBTTagCompound root) { + if (POSTEA) Impl.stamp(root); + } + + private static final class Impl { + + static void transform(String storageId, NBTTagCompound root) { + com.gtnewhorizons.postea.api.CustomDataReplacementManager.transform(storageId, root); + } + + static void stamp(NBTTagCompound root) { + com.gtnewhorizons.postea.api.CustomDataReplacementManager.stamp(root); + } + } +}