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: 29 additions & 2 deletions TShockAPI/NetItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -155,13 +155,40 @@ 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 ToItem()
{
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 `ToItem` method to get a copy of `Terraria.Item`.
* 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