diff --git a/DeluxeGrabber/DeluxeGrabber.csproj b/DeluxeGrabber/DeluxeGrabber.csproj
index 5ef83e9..150ac65 100644
--- a/DeluxeGrabber/DeluxeGrabber.csproj
+++ b/DeluxeGrabber/DeluxeGrabber.csproj
@@ -64,6 +64,7 @@
+
diff --git a/DeluxeGrabber/ModEntry.cs b/DeluxeGrabber/ModEntry.cs
index 83d9134..0f2908c 100644
--- a/DeluxeGrabber/ModEntry.cs
+++ b/DeluxeGrabber/ModEntry.cs
@@ -82,7 +82,7 @@ private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e) {
continue;
}
- if ((grabber.heldObject.Value as Chest).items.Count >= 36) {
+ if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36) {
return;
}
@@ -118,7 +118,7 @@ private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e) {
}
}
- if ((grabber.heldObject.Value as Chest).items.Count > 0) {
+ if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() > 0) {
grabber.showNextIndex.Value = true;
}
}
@@ -173,7 +173,7 @@ private void AutograbBuildings() {
bool full = false;
foreach (Vector2 tile in grabbables) {
- if ((grabber.heldObject.Value as Chest).items.Count >= 36) {
+ if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36) {
Monitor.Log($" Grabber is full", LogLevel.Trace);
full = true;
break;
@@ -217,7 +217,7 @@ private void AutograbBuildings() {
}
// update sprite if grabber has items in it
- if (grabber != null && (grabber.heldObject.Value as Chest).items.Count > 0) {
+ if (grabber != null && (grabber.heldObject.Value as Chest).items.CountIgnoreNull() > 0) {
grabber.showNextIndex.Value = true;
}
}
@@ -234,10 +234,10 @@ private void AutograbCrops() {
foreach (KeyValuePair pair in location.Objects.Pairs) {
if (pair.Value.Name.Contains("Grabber")) {
Object grabber = pair.Value;
- if ((grabber.heldObject.Value == null) || (grabber.heldObject.Value as Chest).items.Count >= 36) {
+ if ((grabber.heldObject.Value == null) || (grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36) {
continue;
}
- bool full = (grabber.heldObject.Value as Chest).items.Count >= 36;
+ bool full = (grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36;
for (int x = (int)pair.Key.X - range; x < pair.Key.X + range + 1; x ++) {
for (int y = (int)pair.Key.Y - range; y < pair.Key.Y + range + 1 && !full; y++) {
Vector2 tile = new Vector2(x, y);
@@ -277,10 +277,10 @@ private void AutograbCrops() {
}
}
}
- full = (grabber.heldObject.Value as Chest).items.Count >= 36;
+ full = (grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36;
}
}
- if (grabber != null && (grabber.heldObject.Value as Chest).items.Count > 0) {
+ if (grabber != null && (grabber.heldObject.Value as Chest).items.CountIgnoreNull() > 0) {
grabber.showNextIndex.Value = true;
}
}
@@ -439,7 +439,7 @@ private void AutograbWorld() {
if (location.Name.Equals("Forest")) {
foreach (TerrainFeature feature in location.terrainFeatures.Values) {
- if ((grabber.heldObject.Value as Chest).items.Count >= 36) {
+ if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36) {
Monitor.Log("Global grabber full", LogLevel.Info);
return;
}
@@ -497,7 +497,7 @@ private void AutograbWorld() {
break;
}
- if ((grabber.heldObject.Value as Chest).items.Count >= 36) {
+ if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36) {
Monitor.Log("Global grabber full", LogLevel.Info);
return;
}
@@ -527,7 +527,7 @@ private void AutograbWorld() {
// add items to grabber and remove from floor
foreach (Vector2 tile in grabbables) {
- if ((grabber.heldObject.Value as Chest).items.Count >= 36) {
+ if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36) {
Monitor.Log("Global grabber full", LogLevel.Info);
return;
}
@@ -570,7 +570,7 @@ private void AutograbWorld() {
foreach (Object obj in location.Objects.Values)
{
- if ((grabber.heldObject.Value as Chest).items.Count >= 36)
+ if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36)
{
Monitor.Log("Global grabber full", LogLevel.Info);
return;
@@ -603,7 +603,7 @@ private void AutograbWorld() {
Monitor.Log($" {location} - found {pair.Value} {pair.Key}{plural}", LogLevel.Trace);
}
- if ((grabber.heldObject.Value as Chest).items.Count > 0) {
+ if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() > 0) {
grabber.showNextIndex.Value = true;
}
}
diff --git a/DeluxeGrabber/NetListExtend.cs b/DeluxeGrabber/NetListExtend.cs
new file mode 100644
index 0000000..0bbe710
--- /dev/null
+++ b/DeluxeGrabber/NetListExtend.cs
@@ -0,0 +1,13 @@
+using Netcode;
+using System.Linq;
+
+namespace DeluxeGrabber
+{
+ public static class NetListExtend
+ {
+ public static int CountIgnoreNull(this NetObjectList list) where T : class, INetObject
+ {
+ return list.Count(item => item != null);
+ }
+ }
+}