using Terraria.ModLoader;
using Terraria.ModLoader.IO;
namespace SoulHarvest.Common;
/// <summary>
/// Keeps altar progression independent from the vanilla prefix reset performed while reforging.
/// Reforging is local and synchronous, so one pending snapshot is sufficient.
/// </summary>
internal static class DeathAltarReforgePreservation
{
private static TagCompound? pendingData;
private static int pendingItemType;
internal static void Capture(ModItem modItem)
{
TagCompound snapshot = [];
modItem.SaveData(snapshot);
pendingData = snapshot;
pendingItemType = modItem.Item.type;
}
internal static void Restore(ModItem modItem)
{
if (pendingData is null || pendingItemType != modItem.Item.type)
return;
TagCompound snapshot = pendingData;
pendingData = null;
pendingItemType = 0;
modItem.LoadData(snapshot);
}
}
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
namespace SoulHarvest.Common;
/// <summary>
/// Keeps altar progression independent from the vanilla prefix reset performed while reforging.
/// Reforging is local and synchronous, so one pending snapshot is sufficient.
/// </summary>
internal static class DeathAltarReforgePreservation
{
private static TagCompound? pendingData;
private static int pendingItemType;
internal static void Capture(ModItem modItem)
{
TagCompound snapshot = [];
modItem.SaveData(snapshot);
pendingData = snapshot;
pendingItemType = modItem.Item.type;
}
internal static void Restore(ModItem modItem)
{
if (pendingData is null || pendingItemType != modItem.Item.type)
return;
TagCompound snapshot = pendingData;
pendingData = null;
pendingItemType = 0;
modItem.LoadData(snapshot);
}
}