From b70b4f1813e90ce47ecd4f97114dcb8e181effd5 Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Fri, 23 Aug 2019 14:46:07 -0700 Subject: [PATCH] More netcode updates. --- .../Framework/Objects/CustomObject.cs | 10 +++++++++ .../Framework/Objects/MultiTiledObject.cs | 1 + .../Utilities/Serialization/Serialization.cs | 21 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs index 040a31e2..ce2dcbf4 100644 --- a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs @@ -8,6 +8,8 @@ using PyTK.CustomElementHandler; using StardustCore.Animations; using StardewValley; using StardewValley.Objects; +using Netcode; +using StardewModdingAPI; namespace Revitalize.Framework.Objects { @@ -523,5 +525,13 @@ namespace Revitalize.Framework.Objects //Load in a file that has all object names referenced here or something. return this.info.name; } + + + public virtual void setNetFieldParent(INetSerializable Parent) + { + this.NetFields.Parent = Parent; + IReflectedProperty p=ModCore.ModHelper.Reflection.GetProperty(this.NetFields, "Root", true); + p.SetValue(Parent.Root); + } } } diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs index da94978d..d221ec11 100644 --- a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs @@ -4,6 +4,7 @@ using System.IO; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Netcode; using Newtonsoft.Json; using PyTK.CustomElementHandler; using StardewValley; diff --git a/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs b/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs index a44d12f0..f59af916 100644 --- a/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs +++ b/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Netcode; using Newtonsoft.Json; using Revitalize.Framework.Objects; using Revitalize.Framework.Objects.Furniture; @@ -165,6 +166,10 @@ namespace Revitalize.Framework.Utilities if (o is Chest && o.Name != "Chest") { Item I = this.GetItemFromChestName(o.Name); + if (I.NetFields != null) + { + (I as CustomObject).setNetFieldParent(o.NetFields); + } ModCore.log("Found a custom item in a chest!"); toAdd.Add(I); toRemove.Add(o); @@ -190,6 +195,10 @@ namespace Revitalize.Framework.Utilities if (o is Chest && o.Name != "Chest") { Item I = this.GetItemFromChestName(o.Name); + if (I.NetFields != null) + { + (I as CustomObject).setNetFieldParent(o.NetFields); + } toAdd.Add(I); toRemove.Add(o); } @@ -208,6 +217,10 @@ namespace Revitalize.Framework.Utilities { ModCore.log("Found a custom object as a held object!"); Item I = this.GetItemFromChestName(c.heldObject.Value.Name); + if (I.NetFields != null) + { + (I as CustomObject).setNetFieldParent(c.NetFields); + } c.heldObject.Value = (StardewValley.Object)I; } } @@ -220,6 +233,10 @@ namespace Revitalize.Framework.Utilities { ModCore.log("Found a custom object as a held object!"); Item I = this.GetItemFromChestName(c.heldObject.Value.Name); + if (I.NetFields != null) + { + (I as CustomObject).setNetFieldParent(c.NetFields); + } c.heldObject.Value = (StardewValley.Object)I; } } @@ -236,6 +253,10 @@ namespace Revitalize.Framework.Utilities if (I is Chest && I.Name != "Chest") { Item ret = this.GetItemFromChestName(I.Name); + if (I.NetFields != null) + { + (ret as CustomObject).setNetFieldParent(I.NetFields); + } toAdd2.Add(ret); toRemove2.Add(I); }