Coding Help Help with getting NetCollection<T> working in a mod

TimidCashew

Newcomer
I am creating a mod that adds a bird critter (grouse) to trees that fly away when the user interacts with the tree. I have things working smoothly in single player but want to add multiplayer support.

Based off this guidance, it seems NetCollections are the way to go (I tried using the messaging and found myself with way too many synchronization issues).

I modeled the NetGrouse after the Projectile since they are pretty similar (idle until user triggers then some deterministic behavior until they are off-screen) by using the INetObject<NetFields>
interface and implementing the constructor with a similar initNetFields() which every Net type seems to have.

This part of my code compiles and works fine in singleplayer, but multiplayer seems to be much more difficult...

I then went to incorporate the Dictionary<string, NetCollection<NetGrouse>> (a NetCollection<NetGrouse> for each outdoor location) into GameLocation by adding the NetCollection<NetGrouse> here right after I spawn a location's grouse (this happens once per day). I am not sure if its as simple as calling loc.NetFields.AddField(localGrouse, "grouse"); to register my NetCollection<NetGrouse> with the larger net tree, but it seems to trigger something when I test in multiplayer.

What I can't figure out is that I seem to break the multiplayer experience completely with this error: https://smapi.io/log/b8b08d253dbe4a739b64a144562dfae4. The host always has the right number of grouse and they work, but all the farmhands show 0 grouse and it seems the host cannot even see the farmhands at all! (probably because I have broken the Netcode sync loop)

I then tried switching my code to have NetGrouse subclass Character in the same way that Farmer does, but I get the same error. I am really hoping someone with experience using NetCollection<T> can help me wire the NetCollection<NetGrouse> to the mod so I can get everything working!
 
Top