First Machine Age's Mods (Combined repo.)
Révision | 3ce516f1d434f89407a13fd3af8f22a584364cf8 (tree) |
---|---|
l'heure | 2022-08-30 07:17:17 |
Auteur | melchior <melchior@user...> |
Commiter | melchior |
Compat changes for 1.17
@@ -56,6 +56,13 @@ namespace AnvilMetalRecovery | ||
56 | 56 | { |
57 | 57 | throw new NotImplementedException( ); |
58 | 58 | } |
59 | + | |
60 | + public IAttribute Clone( ) | |
61 | + { | |
62 | + var newbie = new HotbarObserverData(this.InventoryID, this.Inventory_SlotID, this.ItemCode.Clone( ), this.PlayerUID); | |
63 | + | |
64 | + return newbie; | |
65 | + } | |
59 | 66 | } |
60 | 67 | } |
61 | 68 |
@@ -39,7 +39,7 @@ namespace AnvilMetalRecovery | ||
39 | 39 | private RecoveryEntryTable itemToVoxelLookup = new RecoveryEntryTable();//Item Asset Code to: Ammount & Material |
40 | 40 | |
41 | 41 | private ICoreAPI CoreAPI; |
42 | - private ICoreServerAPI ServerAPI; | |
42 | + | |
43 | 43 | private ServerCoreAPI ServerCore { get; set; } |
44 | 44 | private ClientCoreAPI ClientCore { get; set; } |
45 | 45 |
@@ -110,7 +110,18 @@ namespace AnvilMetalRecovery | ||
110 | 110 | |
111 | 111 | RegisterItemMappings( ); |
112 | 112 | RegisterBlockBehaviors( ); |
113 | - | |
113 | + if (api.Side.IsServer()) | |
114 | + { | |
115 | + if (api is ServerCoreAPI) { | |
116 | + ServerCore = api as ServerCoreAPI; | |
117 | + } | |
118 | + ServerCore.Event.AssetsFinalizers += AttachExtraBlockBehaviors; | |
119 | + } | |
120 | + else | |
121 | + { | |
122 | + ClientCore = api as ClientCoreAPI; | |
123 | + ClientCore.Event.LevelFinalize += PerformBlockClassSwaps; | |
124 | + } | |
114 | 125 | |
115 | 126 | #if DEBUG |
116 | 127 | //Harmony.DEBUG = true; |
@@ -123,54 +134,38 @@ namespace AnvilMetalRecovery | ||
123 | 134 | |
124 | 135 | public override void StartServerSide(ICoreServerAPI api) |
125 | 136 | { |
126 | - this.ServerAPI = api; | |
127 | 137 | |
128 | - | |
129 | - if (api is ServerCoreAPI) { | |
130 | - ServerCore = api as ServerCoreAPI; | |
131 | - } | |
132 | - else { | |
133 | - Mod.Logger.Error("Cannot access 'ServerCoreAPI' class: API (implimentation) has changed, Contact Developer!"); | |
134 | - return; | |
135 | - } | |
136 | 138 | PrepareServersideConfig( ); |
137 | 139 | PrepareDownlinkChannel( ); |
138 | - ServerAPI.Event.PlayerJoin += SendClientConfigMessage; | |
139 | - ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, PersistServersideConfig); | |
140 | - ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.GameReady, MaterialDataGathering); | |
141 | - PerformBlockClassSwaps(); | |
142 | - ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.RunGame, CacheRecoveryDataTable); | |
143 | - ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.GameReady, AttachExtraBlockBehaviors); | |
140 | + ServerCore.Event.PlayerJoin += SendClientConfigMessage; | |
141 | + ServerCore.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, PersistServersideConfig); | |
142 | + ServerCore.Event.ServerRunPhase(EnumServerRunPhase.GameReady, MaterialDataGathering); | |
143 | + ServerCore.Event.ServerRunPhase(EnumServerRunPhase.RunGame, CacheRecoveryDataTable); | |
144 | 144 | |
145 | 145 | SetupGeneralObservers( ); |
146 | 146 | |
147 | 147 | Mod.Logger.VerboseDebug("Anvil Metal Recovery - should be installed..."); |
148 | 148 | |
149 | 149 | #if DEBUG |
150 | - ServerAPI.RegisterCommand("durability", "edit durability of item", " (Held tool) and #", EditDurability, Privilege.give); | |
150 | + ServerCore.RegisterCommand("durability", "edit durability of item", " (Held tool) and #", EditDurability, Privilege.give); | |
151 | 151 | #endif |
152 | 152 | |
153 | 153 | } |
154 | 154 | |
155 | 155 | public override void StartClientSide(ICoreClientAPI api) |
156 | 156 | { |
157 | - base.StartClientSide(api); | |
158 | - | |
159 | - if (api is ClientCoreAPI) { | |
160 | - ClientCore = api as ClientCoreAPI; | |
161 | - } | |
162 | - else { | |
163 | - Mod.Logger.Error("Cannot access 'ClientCoreAPI' class: API (implimentation) has changed, Contact Developer!"); | |
164 | - return; | |
165 | - } | |
157 | + base.StartClientSide(api); | |
166 | 158 | |
167 | - ListenForServerConfigMessage( ); | |
168 | - //ClientCore.Event.RegisterCallback(PerformBlockClassSwaps, 0); | |
169 | - PerformBlockClassSwaps(); | |
159 | + ListenForServerConfigMessage( ); | |
170 | 160 | |
171 | 161 | Mod.Logger.VerboseDebug("Anvil Metal Recovery - should be installed..."); |
172 | 162 | } |
173 | 163 | |
164 | + public override void AssetsLoaded(ICoreAPI api) | |
165 | + { | |
166 | + if (api.Side.IsServer( )) { PerformBlockClassSwaps( );} | |
167 | + } | |
168 | + | |
174 | 169 | |
175 | 170 | private void RegisterItemMappings( ) |
176 | 171 | { |
@@ -189,6 +184,9 @@ namespace AnvilMetalRecovery | ||
189 | 184 | |
190 | 185 | private void PerformBlockClassSwaps() |
191 | 186 | { |
187 | + #if DEBUG | |
188 | + Mod.Logger.Debug("PerformBlockClassSwaps"); | |
189 | + #endif | |
192 | 190 | if (CoreAPI.Side == EnumAppSide.Server) |
193 | 191 | this.ServerCore.ClassRegistryNative.ReplaceBlockClassType(BlockWateringCanPlus.BlockClassName, typeof(BlockWateringCanPlus)); |
194 | 192 | else |
@@ -202,7 +200,7 @@ namespace AnvilMetalRecovery | ||
202 | 200 | new AssetLocation(@"game",@"toolmold-burned-*"), |
203 | 201 | }; |
204 | 202 | |
205 | - var moldRecoverBehaviorType = ServerAPI.ClassRegistry.GetBlockBehaviorClass(MoldDestructionRecovererBehavior.BehaviorClassName); | |
203 | + var moldRecoverBehaviorType = ServerCore.ClassRegistry.GetBlockBehaviorClass(MoldDestructionRecovererBehavior.BehaviorClassName); | |
206 | 204 | foreach (var assetName in mold_behaviorsAppendList) { |
207 | 205 | if (!assetName.IsWildCard) |
208 | 206 | { |
@@ -212,7 +210,7 @@ namespace AnvilMetalRecovery | ||
212 | 210 | #endif |
213 | 211 | } |
214 | 212 | else { |
215 | - var searchResults = ServerAPI.World.SearchBlocks(assetName); | |
213 | + var searchResults = ServerCore.World.SearchBlocks(assetName); | |
216 | 214 | if (searchResults != null && searchResults.Length > 0) { |
217 | 215 | #if DEBUG |
218 | 216 | Mod.Logger.VerboseDebug("Attaching Block-Behaviors, wildcard matches from '{0}'", assetName); |
@@ -237,14 +235,14 @@ namespace AnvilMetalRecovery | ||
237 | 235 | |
238 | 236 | private void PrepareServersideConfig( ) |
239 | 237 | { |
240 | - AMRConfig config = ServerAPI.LoadModConfig<AMRConfig>(_configFilename); | |
238 | + AMRConfig config = ServerCore.LoadModConfig<AMRConfig>(_configFilename); | |
241 | 239 | |
242 | 240 | if (config == null) |
243 | 241 | { |
244 | 242 | //Regen default |
245 | 243 | Mod.Logger.Warning("Regenerating default config as it was missing / unparsable..."); |
246 | - ServerAPI.StoreModConfig<AMRConfig>(new AMRConfig(true), _configFilename); | |
247 | - config = ServerAPI.LoadModConfig<AMRConfig>(_configFilename); | |
244 | + ServerCore.StoreModConfig<AMRConfig>(new AMRConfig(true), _configFilename); | |
245 | + config = ServerCore.LoadModConfig<AMRConfig>(_configFilename); | |
248 | 246 | } |
249 | 247 | else if( config.BlackList == null || config.BlackList.Count == 0) |
250 | 248 | { |
@@ -259,13 +257,13 @@ namespace AnvilMetalRecovery | ||
259 | 257 | { |
260 | 258 | if (this.CachedConfiguration != null) { |
261 | 259 | Mod.Logger.Notification("Persisting configuration."); |
262 | - ServerAPI.StoreModConfig<AMRConfig>(this.CachedConfiguration, _configFilename); | |
260 | + ServerCore.StoreModConfig<AMRConfig>(this.CachedConfiguration, _configFilename); | |
263 | 261 | } |
264 | 262 | } |
265 | 263 | |
266 | 264 | private void PrepareDownlinkChannel( ) |
267 | 265 | { |
268 | - _ConfigDownlink = ServerAPI.Network.RegisterChannel(_configFilename); | |
266 | + _ConfigDownlink = ServerCore.Network.RegisterChannel(_configFilename); | |
269 | 267 | _ConfigDownlink.RegisterMessageType<AMRConfig>( ); |
270 | 268 | } |
271 | 269 |
@@ -309,7 +307,7 @@ namespace AnvilMetalRecovery | ||
309 | 307 | #if DEBUG |
310 | 308 | Mod.Logger.VerboseDebug("Adding Recovery entries table to Cache..."); |
311 | 309 | #endif |
312 | - ServerAPI.ObjectCache.Add(itemFilterListCacheKey, itemToVoxelLookup); | |
310 | + ServerCore.ObjectCache.Add(itemFilterListCacheKey, itemToVoxelLookup); | |
313 | 311 | } |
314 | 312 | } |
315 | 313 |
@@ -30,8 +30,8 @@ namespace AnvilMetalRecovery | ||
30 | 30 | continue; |
31 | 31 | } |
32 | 32 | |
33 | - CollectibleObject metalObject = recipie.Ingredient.Type == EnumItemClass.Item ? ServerAPI.World.GetItem(recipie.Ingredient.Code) : ServerAPI.World.GetBlock(recipie.Ingredient.Code) as CollectibleObject; | |
34 | - Item outputItem = ServerAPI.World.GetItem(recipie?.Output?.Code); | |
33 | + CollectibleObject metalObject = recipie.Ingredient.Type == EnumItemClass.Item ? ServerCore.World.GetItem(recipie.Ingredient.Code) : ServerCore.World.GetBlock(recipie.Ingredient.Code) as CollectibleObject; | |
34 | + Item outputItem = ServerCore.World.GetItem(recipie?.Output?.Code); | |
35 | 35 | |
36 | 36 | if (outputItem == null) { |
37 | 37 | #if DEBUG |
@@ -69,9 +69,9 @@ namespace AnvilMetalRecovery | ||
69 | 69 | } |
70 | 70 | else { |
71 | 71 | //Tool-head map to Tool item; decode |
72 | - var itemToolCode = ServerAPI.World.GridRecipes.FirstOrDefault(gr => gr.Ingredients.Any(crg => crg.Value.Code.Equals(outputItem.Code)) && gr.Enabled && gr.Output.Type == EnumItemClass.Item)?.Output.Code; | |
72 | + var itemToolCode = ServerCore.World.GridRecipes.FirstOrDefault(gr => gr.Ingredients.Any(crg => crg.Value.Code.Equals(outputItem.Code)) && gr.Enabled && gr.Output.Type == EnumItemClass.Item)?.Output.Code; | |
73 | 73 | if (itemToolCode != null) { |
74 | - var itemTool = ServerAPI.World.GetItem(itemToolCode); | |
74 | + var itemTool = ServerCore.World.GetItem(itemToolCode); | |
75 | 75 | if (itemTool == null) { |
76 | 76 | #if DEBUG |
77 | 77 | Mod.Logger.Debug($"Missing Output Tool item, from: {recipie.Name.ToString( )}, skipping."); |
@@ -133,7 +133,7 @@ namespace AnvilMetalRecovery | ||
133 | 133 | if (String.IsNullOrEmpty(hotbarData.PlayerUID) || String.IsNullOrEmpty(hotbarData.InventoryID)) return; |
134 | 134 | |
135 | 135 | bool probablyHotbar = hotbarData.InventoryID.StartsWith(GlobalConstants.hotBarInvClassName, StringComparison.Ordinal); |
136 | - var playerTarget = ServerAPI.World.PlayerByUid(hotbarData.PlayerUID); | |
136 | + var playerTarget = ServerCore.World.PlayerByUid(hotbarData.PlayerUID); | |
137 | 137 | var spim = playerTarget.InventoryManager as ServerPlayerInventoryManager; |
138 | 138 | var hotbarInv = playerTarget.InventoryManager.GetHotbarInventory( ); |
139 | 139 | var hotSlot = hotbarInv[hotbarData.Inventory_SlotID]; |
@@ -144,11 +144,11 @@ namespace AnvilMetalRecovery | ||
144 | 144 | Mod.Logger.VerboseDebug("Directly inserting fragments into hotbar slot# {0}", hotbarData.Inventory_SlotID); |
145 | 145 | #endif |
146 | 146 | |
147 | - VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem; | |
147 | + VariableMetalItem variableMetal = ServerCore.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem; | |
148 | 148 | ItemStack metalFragmentsStack = new ItemStack(variableMetal, 1); |
149 | 149 | variableMetal.ApplyMetalProperties(rec, ref metalFragmentsStack, CachedConfiguration.ToolRecoveryRate); |
150 | 150 | hotSlot.Itemstack = metalFragmentsStack; |
151 | - hotSlot.Itemstack.ResolveBlockOrItem(ServerAPI.World); | |
151 | + hotSlot.Itemstack.ResolveBlockOrItem(ServerCore.World); | |
152 | 152 | hotSlot.MarkDirty( ); |
153 | 153 | spim.NotifySlot(playerTarget, hotSlot); |
154 | 154 | } |
@@ -158,13 +158,13 @@ namespace AnvilMetalRecovery | ||
158 | 158 | Mod.Logger.VerboseDebug("Hotbar-occupied (or crafting) slot#{0} so; shoving {1} in general direction of player...", hotbarData.Inventory_SlotID, hotbarData.ItemCode.ToShortString( )); |
159 | 159 | #endif |
160 | 160 | |
161 | - VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem; | |
161 | + VariableMetalItem variableMetal = ServerCore.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem; | |
162 | 162 | ItemStack metalFragmentsStack = new ItemStack(variableMetal, 1); |
163 | 163 | variableMetal.ApplyMetalProperties(rec, ref metalFragmentsStack, CachedConfiguration.ToolRecoveryRate); |
164 | 164 | if (spim.TryGiveItemstack(metalFragmentsStack, true) == false) |
165 | 165 | { |
166 | 166 | //Player with full Inv. |
167 | - ServerAPI.World.SpawnItemEntity(metalFragmentsStack, playerTarget.Entity.Pos.XYZ); | |
167 | + ServerCore.World.SpawnItemEntity(metalFragmentsStack, playerTarget.Entity.Pos.XYZ); | |
168 | 168 | } |
169 | 169 | } |
170 | 170 | } |
@@ -192,7 +192,7 @@ namespace AnvilMetalRecovery | ||
192 | 192 | private void ApplySmeltingPropertiesByCodeVariant(AssetLocation updatingCode, int ratioOverride = 1) |
193 | 193 | { |
194 | 194 | //ALL ????:'ingot-*' type items... |
195 | - var ingotItems = ServerAPI.World.Items.Where(itm => itm.ItemId > 0 && itm.Code != null && itm.Code.BeginingOnly(@"ingot")); | |
195 | + var ingotItems = ServerCore.World.Items.Where(itm => itm.ItemId > 0 && itm.Code != null && itm.Code.BeginingOnly(@"ingot")); | |
196 | 196 | |
197 | 197 | #if DEBUG |
198 | 198 | this.Mod.Logger.VerboseDebug("found {0} Ingot type items", ingotItems.Count( )); |
@@ -208,16 +208,16 @@ namespace AnvilMetalRecovery | ||
208 | 208 | |
209 | 209 | metalSmeltProps.SmeltedRatio = ratioOverride; |
210 | 210 | AssetLocation shavingCode = updatingCode.AppendPathVariant(metalName); |
211 | - var shavingEquivalentItem = ServerAPI.World.GetItem(shavingCode); | |
211 | + var shavingEquivalentItem = ServerCore.World.GetItem(shavingCode); | |
212 | 212 | if (shavingEquivalentItem != null) { |
213 | 213 | shavingEquivalentItem.CombustibleProps = metalSmeltProps; |
214 | 214 | #if DEBUG |
215 | - ServerAPI.Logger.VerboseDebug("Updated SmeltProps, for: {0}", shavingCode.ToString( )); | |
215 | + ServerCore.Logger.VerboseDebug("Updated SmeltProps, for: {0}", shavingCode.ToString( )); | |
216 | 216 | #endif |
217 | 217 | } |
218 | 218 | else { |
219 | 219 | #if DEBUG |
220 | - ServerAPI.Logger.VerboseDebug("Non-existant item: {0}", shavingCode.ToString( )); | |
220 | + ServerCore.Logger.VerboseDebug("Non-existant item: {0}", shavingCode.ToString( )); | |
221 | 221 | #endif |
222 | 222 | } |
223 | 223 | } |
@@ -4,9 +4,9 @@ | ||
4 | 4 | "description" : "Get back smithing discards, broken tool scrap, failed molds; and MORE!", |
5 | 5 | "authors": ["Melchior"], |
6 | 6 | "ModID":"metalrecovery", |
7 | - "version": "0.1.18-rc.1", | |
7 | + "version": "0.1.18-rc.2", | |
8 | 8 | "dependencies": { |
9 | - "game": "1.16.5", | |
9 | + "game": "1.17.0-rc.0", | |
10 | 10 | "survival": "" |
11 | 11 | }, |
12 | 12 | "website": "http://nowebsite.nope" |