Extend NetItem
This commit is contained in:
parent
0535f6b7c6
commit
d5fb8726cc
7 changed files with 170 additions and 194 deletions
114
TShockAPI/NetItem.cs
Normal file
114
TShockAPI/NetItem.cs
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Terraria;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an item.
|
||||
/// </summary>
|
||||
public struct NetItem
|
||||
{
|
||||
/// <summary>
|
||||
/// The number of armor slots.
|
||||
/// </summary>
|
||||
public static readonly int ArmorSlots = 16;
|
||||
|
||||
/// <summary>
|
||||
/// The number of dye slots.
|
||||
/// </summary>
|
||||
public static readonly int DyeSlots = 8;
|
||||
|
||||
/// <summary>
|
||||
/// The inventory size.
|
||||
/// </summary>
|
||||
public static readonly int MaxInventory = 83;
|
||||
|
||||
private readonly int _netId;
|
||||
private readonly byte _prefixId;
|
||||
private readonly int _stack;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the net ID.
|
||||
/// </summary>
|
||||
public int NetId
|
||||
{
|
||||
get { return _netId; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the prefix.
|
||||
/// </summary>
|
||||
public byte PrefixId
|
||||
{
|
||||
get { return _prefixId; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the stack.
|
||||
/// </summary>
|
||||
public int Stack
|
||||
{
|
||||
get { return _stack; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="NetItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="netId">The net ID.</param>
|
||||
/// <param name="stack">The stack.</param>
|
||||
/// <param name="prefixId">The prefix ID.</param>
|
||||
public NetItem(int netId, int stack, byte prefixId)
|
||||
{
|
||||
_netId = netId;
|
||||
_stack = stack;
|
||||
_prefixId = prefixId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the <see cref="NetItem"/> to a string.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0},{1},{2}", _netId, _stack, _prefixId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a string into a <see cref="NetItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="str">The string.</param>
|
||||
/// <exception cref="ArgumentNullException"/>
|
||||
/// <exception cref="FormatException"/>
|
||||
/// <returns></returns>
|
||||
public static NetItem Parse(string str)
|
||||
{
|
||||
if (str == null)
|
||||
throw new ArgumentNullException("str");
|
||||
|
||||
string[] comp = str.Split(',');
|
||||
if (comp.Length != 3)
|
||||
throw new FormatException("String does not contain three sections.");
|
||||
|
||||
int netId = Int32.Parse(comp[0]);
|
||||
int stack = Int32.Parse(comp[1]);
|
||||
byte prefixId = Byte.Parse(comp[2]);
|
||||
|
||||
return new NetItem(netId, stack, prefixId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an <see cref="Item"/> into a <see cref="NetItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="item">The <see cref="Item"/>.</param>
|
||||
/// <returns></returns>
|
||||
public static explicit operator NetItem(Item item)
|
||||
{
|
||||
return item == null
|
||||
? new NetItem()
|
||||
: new NetItem(item.netID, item.stack, item.prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue