Fix NetItem serialization/deserialization
This commit is contained in:
parent
d5fb8726cc
commit
ad5ec1c252
2 changed files with 10 additions and 5 deletions
|
|
@ -77,7 +77,7 @@ namespace TShockAPI.DB
|
|||
playerData.maxHealth = reader.Get<int>("MaxHealth");
|
||||
playerData.mana = reader.Get<int>("Mana");
|
||||
playerData.maxMana = reader.Get<int>("MaxMana");
|
||||
playerData.inventory = reader.Get<string>("Inventory").Split('~').Select(NetItem.Parse).ToArray();
|
||||
playerData.inventory = reader.Get<string>("Inventory").Split('~').Select(NetItem.Parse).ToArray();
|
||||
playerData.spawnX = reader.Get<int>("spawnX");
|
||||
playerData.spawnY = reader.Get<int>("spawnY");
|
||||
playerData.hair = reader.Get<int?>("hair");
|
||||
|
|
@ -107,7 +107,7 @@ namespace TShockAPI.DB
|
|||
{
|
||||
var inventory = new StringBuilder();
|
||||
|
||||
var items = TShock.ServerSideCharacterConfig.StartingInventory;
|
||||
var items = new List<NetItem>(TShock.ServerSideCharacterConfig.StartingInventory);
|
||||
if (items.Count < NetItem.MaxInventory)
|
||||
items.AddRange(new NetItem[NetItem.MaxInventory - items.Count]);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Terraria;
|
||||
|
||||
namespace TShockAPI
|
||||
|
|
@ -9,6 +10,7 @@ namespace TShockAPI
|
|||
/// <summary>
|
||||
/// Represents an item.
|
||||
/// </summary>
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public struct NetItem
|
||||
{
|
||||
/// <summary>
|
||||
|
|
@ -26,9 +28,12 @@ namespace TShockAPI
|
|||
/// </summary>
|
||||
public static readonly int MaxInventory = 83;
|
||||
|
||||
private readonly int _netId;
|
||||
private readonly byte _prefixId;
|
||||
private readonly int _stack;
|
||||
[JsonProperty("netID")]
|
||||
private int _netId;
|
||||
[JsonProperty("prefix")]
|
||||
private byte _prefixId;
|
||||
[JsonProperty("stack")]
|
||||
private int _stack;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the net ID.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue