Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetItem changes #2945

Open
wants to merge 10 commits into
base: general-devel
Choose a base branch
from
31 changes: 30 additions & 1 deletion TShockAPI/NetItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,42 @@ public int Stack
/// <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)
public NetItem(int netId, int stack = 1, byte prefixId = 0)
{
_netId = netId;
_stack = stack;
_prefixId = prefixId;
}

/// <summary>
/// Creates a new <see cref="NetItem"/>.
/// </summary>
/// <param name="item">Item in the game.</param>
public NetItem(Item item)
{
_netId = item.netID;
_stack = item.stack;
_prefixId = item.prefix;
}

/// <summary>
/// Creates <see cref="Terraria.Item"/> based on data from this structure.
/// </summary>
/// <returns>A copy of the item.</returns>
/// <exception cref="Exception">If the item ID is 0.</exception>
Arthri marked this conversation as resolved.
Show resolved Hide resolved
public Item Build()
Arthri marked this conversation as resolved.
Show resolved Hide resolved
{
if (_netId == 0)
throw new Exception("It is impossible to create an item whose ID is 0.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not true, and this method should allow creating an empty item in my opinion, in case that is useful to some plugins.

Item item = new Item();

item.netDefaults(_netId);
item.stack = _stack;
item.prefix = _prefixId;

return item;
}

/// <summary>
/// Converts the <see cref="NetItem"/> to a string.
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ Use past tense when adding new entries; sign your name off when you add or chang
* If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. -->

## Upcoming changes
Your changes could be here!
* Updated `TShockAPI.NetItem` (@AgaSpace):
* Added constructor overload with parameter `Terraria.Item`.
* Added the `Build` method to get a copy of `Terraria.Item`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be updated to ToItem

* In the constructor I added optional parameters `stack` and `prefix`.
Arthri marked this conversation as resolved.
Show resolved Hide resolved

## TShock 5.2
* An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK)
Expand Down