VS plugin mod for Basic Armour
Revision | bdcc17d40c3cf30b7f6791d6b27c85ff3eac914f (tree) |
---|---|
Zeit | 2019-05-19 09:07:30 |
Autor | melchior <melchior@user...> |
Commiter | melchior |
Reworked workaround for out of order execution
Renderer will self-disable on exception
@@ -16,6 +16,7 @@ namespace ArmourMod | ||
16 | 16 | { |
17 | 17 | protected ICoreClientAPI ClientApi { get; set; } |
18 | 18 | private Dictionary<AssetLocation,ArmourModelData> Armoury; |
19 | + private bool enabled = true; | |
19 | 20 | |
20 | 21 | public double RenderOrder |
21 | 22 | { |
@@ -35,37 +36,43 @@ namespace ArmourMod | ||
35 | 36 | } |
36 | 37 | |
37 | 38 | public void OnRenderFrame(float deltaTime, EnumRenderStage stage) |
38 | - { | |
39 | - for (int i = 0; i < ClientApi.World.AllOnlinePlayers.Length; i++) | |
40 | - { | |
41 | - var aPlayer = ClientApi.World.AllOnlinePlayers[i]; | |
39 | + { | |
40 | + if (enabled) { | |
41 | + try { | |
42 | + for (int i = 0; i < ClientApi.World.AllOnlinePlayers.Length; i++) { | |
43 | + var aPlayer = ClientApi.World.AllOnlinePlayers[i]; | |
42 | 44 | |
43 | - if ( aPlayer != null ) { | |
44 | - | |
45 | - EntityShapeRenderer rend = aPlayer.Entity.Properties.Client.Renderer as EntityShapeRenderer; | |
46 | - | |
47 | - if ( rend == null ) | |
48 | - continue; | |
45 | + if (aPlayer != null) { | |
49 | 46 | |
50 | - if (aPlayer.Entity is EntityArmourPlayer) | |
51 | - { | |
52 | - EntityArmourPlayer armouredPlayer = aPlayer.Entity as EntityArmourPlayer; | |
47 | + EntityShapeRenderer rend = aPlayer.Entity.Properties.Client.Renderer as EntityShapeRenderer; | |
53 | 48 | |
54 | - if (armouredPlayer == null) { | |
55 | - ClientApi.Logger.Error("Could not cast EntityPlayer to EntityArmourPlayer"); | |
56 | - continue; | |
57 | - } | |
49 | + if (rend == null) | |
50 | + continue; | |
58 | 51 | |
59 | - if (armouredPlayer.RenderableWornArmours == null) { | |
60 | - ClientApi.Logger.Error("RenderableWornArmours was NULL!"); | |
61 | - continue; | |
62 | - } | |
52 | + if (aPlayer.Entity is EntityArmourPlayer) { | |
53 | + EntityArmourPlayer armouredPlayer = aPlayer.Entity as EntityArmourPlayer; | |
63 | 54 | |
64 | - if ( armouredPlayer.RenderableWornArmours.Count > 0 ) { | |
65 | - | |
66 | - RenderWornArmour( armouredPlayer, rend, stage != EnumRenderStage.Opaque ); | |
55 | + if (armouredPlayer == null) { | |
56 | + ClientApi.Logger.Error("Could not cast EntityPlayer to EntityArmourPlayer"); | |
57 | + return; | |
58 | + } | |
59 | + | |
60 | + if (armouredPlayer.RenderableWornArmours == null) { | |
61 | + ClientApi.Logger.Error("RenderableWornArmours was NULL!"); | |
62 | + return; | |
63 | + } | |
64 | + | |
65 | + if (armouredPlayer.RenderableWornArmours.Count > 0) { | |
66 | + | |
67 | + RenderWornArmour(armouredPlayer, rend, stage != EnumRenderStage.Opaque); | |
68 | + } | |
69 | + } | |
67 | 70 | } |
68 | 71 | } |
72 | + } catch (Exception problem) | |
73 | + { | |
74 | + ClientApi.Logger.Error("ArmourMeshRenderer FAULT: {0} Disabling.", problem.Message); | |
75 | + enabled = false; | |
69 | 76 | } |
70 | 77 | } |
71 | 78 | } |
@@ -23,6 +23,9 @@ namespace ArmourMod | ||
23 | 23 | //Pre-compute values; |
24 | 24 | private DamageFilter finalFilter; |
25 | 25 | |
26 | + private long recurringClientDelayHookId; | |
27 | + | |
28 | + | |
26 | 29 | internal ArmourModConfig CachedConfiguration |
27 | 30 | { |
28 | 31 | get |
@@ -252,20 +255,35 @@ namespace ArmourMod | ||
252 | 255 | |
253 | 256 | |
254 | 257 | protected void ClientDelayHook(IClientPlayer byPlayer) |
255 | - { | |
256 | - retry: | |
257 | - Thread.Sleep(100); | |
258 | + { | |
258 | 259 | if (base.GearInventory == null) { |
259 | 260 | Logger.Error("ClientDelayHook: base.GearInventory IS NULL! "); |
260 | - | |
261 | - goto retry; | |
261 | + recurringClientDelayHookId = ClientAPI.Event.RegisterCallback(RecurringClientDelayHook, 100); | |
262 | + return; | |
262 | 263 | } |
263 | 264 | |
264 | - //CoreAPI.Event.UnregisterCallback(client_callback); | |
265 | 265 | base.GearInventory.SlotModified += ClientWatchSlotModified; |
266 | 266 | PopulateWornArmourModels( ); |
267 | 267 | } |
268 | 268 | |
269 | + protected void RecurringClientDelayHook(float delayed) | |
270 | + { | |
271 | + if (base.GearInventory == null) { | |
272 | + Logger.Error("RecurringClientDelayHook: base.GearInventory IS NULL! "); | |
273 | + | |
274 | + return; | |
275 | + } else { | |
276 | + Logger.Notification("RecurringClientDelayHook: Finally the Gear data arrived - can proceed with event hooks"); | |
277 | + | |
278 | + ClientAPI.Event.UnregisterCallback(recurringClientDelayHookId); | |
279 | + | |
280 | + base.GearInventory.SlotModified += ClientWatchSlotModified; | |
281 | + PopulateWornArmourModels( ); | |
282 | + } | |
283 | + } | |
284 | + | |
285 | + | |
286 | + | |
269 | 287 | private void ServerWatchSlotModified (int slotId) |
270 | 288 | { |
271 | 289 | var watchedSlot = base.GearInventory[slotId]; |
@@ -3,7 +3,7 @@ | ||
3 | 3 | "name": "Basic Armour Mod", |
4 | 4 | "description" : "Leather, Plate, Scale & More", |
5 | 5 | "authors": ["Melchior", "Bunnyviking"], |
6 | - "version": "0.1.4", | |
6 | + "version": "0.1.5", | |
7 | 7 | "dependencies": { |
8 | 8 | "game": "1.9.3", |
9 | 9 | "survival": "" |