Skip to content

Commit

Permalink
Update ItemPickup to reflect 13.1 changes
Browse files Browse the repository at this point in the history
Increment version
  • Loading branch information
ced777ric committed Jun 24, 2023
1 parent 442a0ed commit 6e13cc6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
34 changes: 25 additions & 9 deletions NwPluginAPI/Core/Items/ItemPickup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace PluginAPI.Core.Items
public class ItemPickup
{
private static readonly Dictionary<ushort, ItemPickup> CachedItems = new Dictionary<ushort, ItemPickup>();
private PickupStandardPhysics _pickupStandardPhysics;

/// <summary>
/// The base-game object.
Expand All @@ -37,8 +38,8 @@ public class ItemPickup
/// </summary>
public float Weight
{
get => OriginalObject.Info.Weight;
set => OriginalObject.Info.Weight = value;
get => OriginalObject.Info.WeightKg;
set => OriginalObject.Info.WeightKg = value;
}

/// <summary>
Expand All @@ -50,10 +51,23 @@ public bool IsLocked
set => OriginalObject.Info.Locked = value;
}

/// <summary>
/// Gets the pickup's <see cref="PickupStandardPhysics"/>.
/// </summary>
public PickupStandardPhysics PickupStandardPhysics
{
get
{
if (_pickupStandardPhysics == null)
_pickupStandardPhysics = OriginalObject.PhysicsModule as PickupStandardPhysics;
return _pickupStandardPhysics;
}
}

/// <summary>
/// Gets the pickup's <see cref="UnityEngine.Rigidbody"/>.
/// </summary>
public Rigidbody Rigidbody => OriginalObject.RigidBody;
public Rigidbody Rigidbody => PickupStandardPhysics.Rb;

/// <summary>
/// Gets the pickup's <see cref="UnityEngine.Rigidbody"/>.
Expand Down Expand Up @@ -104,11 +118,14 @@ public static ItemPickup Create(ItemType item, Vector3 position, Quaternion rota
if (item == ItemType.None || !InventoryItemLoader.AvailableItems.TryGetValue(item, out ItemBase ib))
return null;

ItemPickupBase newPickup = Object.Instantiate(ib.PickupDropModel, position, rotation);
newPickup.Info.ItemId = item;
newPickup.Info.ServerSetPositionAndRotation(position, rotation);
newPickup.Info.Serial = ItemSerialGenerator.GenerateNext();
newPickup.Info.Weight = ib.Weight;
PickupSyncInfo syncInfo = new PickupSyncInfo()
{
ItemId = item,
Serial = ItemSerialGenerator.GenerateNext(),
WeightKg = ib.Weight
};

ItemPickupBase newPickup = InventoryExtensions.ServerCreatePickup(ib, syncInfo, position, rotation, false);

return GetOrAdd(newPickup);
}
Expand All @@ -118,7 +135,6 @@ public static ItemPickup Create(ItemType item, Vector3 position, Quaternion rota
/// </summary>
public void Spawn()
{
OriginalObject.InfoReceived(default, OriginalObject.Info);
NetworkServer.Spawn(GameObject);
}

Expand Down
4 changes: 2 additions & 2 deletions NwPluginAPI/PluginApiVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
public static class PluginApiVersion
{
public const string Version = "12.0.0"; //major.minor.patch ONLY
public const string VersionString = "12.0.0";
public const string Version = "13.1.0"; //major.minor.patch ONLY
public const string VersionString = "13.1.0";

//PackageVersion needs to be set to the same value as VersionString MANUALLY IN .csproj

Expand Down

0 comments on commit 6e13cc6

Please sign in to comment.