• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

First Machine Age's Mods (Combined repo.)


Commit MetaInfo

Révisionc93427d089215a1f6d3bf264aa9667edd2abd3a4 (tree)
l'heure2021-07-10 05:49:04
Auteurmelchior <melchior@user...>
Commitermelchior

Message de Log

AMR+ Reworked ItemDamage event handling a little,
(EntityItem / throwables) - not supported yet

Change Summary

Modification

--- a/AnvilMetalRecovery/Harmony/GenericItemMortalityDetector.cs
+++ b/AnvilMetalRecovery/Harmony/GenericItemMortalityDetector.cs
@@ -48,17 +48,17 @@ namespace AnvilMetalRecovery.Patches
4848 #endif
4949 if (DamageFilterTool.Ignore(world, __instance)) return;
5050 #if DEBUG
51- world.Api.Logger.VerboseDebug("InventoryID: {0}, Class: {1}", itemslot.Inventory.InventoryID, itemslot.Inventory.ClassName);//Class: hotbar
51+ world.Api.Logger.VerboseDebug("InventoryID: {0}, Class: {1}", itemslot?.Inventory?.InventoryID, itemslot?.Inventory?.ClassName);//Class: hotbar
5252 world.Api.Logger.VerboseDebug("Thing has HP: {0}", itemslot.Itemstack.Hitpoints( ));
5353 #endif
54- if (itemslot.Itemstack.Hitpoints( ) <= amount)
54+ if (itemslot.Itemstack.Hitpoints( ) <= amount && itemslot.Inventory != null)
5555 {
5656 #if DEBUG
5757 world.Api.Logger.VerboseDebug("Sending Item Expiry Event");
5858 #endif
5959 var playerEntity = byEntity as EntityPlayer;
6060 var hotbarEvent = new HotbarObserverData(itemslot.Inventory.InventoryID, itemslot.Inventory.GetSlotId(itemslot), __instance.Code, (playerEntity == null ? String.Empty : playerEntity.PlayerUID));
61- world.Api.Event.PushEvent(MetalRecoverySystem.HotbarChannelName, hotbarEvent);
61+ world.Api.Event.PushEvent(MetalRecoverySystem.ItemDamageChannelName, hotbarEvent);
6262 }
6363 }
6464
--- a/AnvilMetalRecovery/MetalRecoverySystem.cs
+++ b/AnvilMetalRecovery/MetalRecoverySystem.cs
@@ -18,7 +18,7 @@ namespace AnvilMetalRecovery
1818 internal const string metalShavingsCode = @"metal_shaving";
1919 internal const string itemFilterListCacheKey = @"AMR_ItemFilters";
2020 public const float IngotVoxelEquivalent = 2.38f;
21- public const string HotbarChannelName = @"HotbarEvents";
21+ public const string ItemDamageChannelName = @"ItemDamageEvents";
2222
2323 private Dictionary<AssetLocation, RecoveryEntry> itemToVoxelLookup = new Dictionary<AssetLocation, RecoveryEntry>();//Ammount & Material?
2424
@@ -41,7 +41,7 @@ namespace AnvilMetalRecovery
4141
4242 /// <summary>
4343 /// ALL Items that have were derivable from smithing recipies (and are tool / durable)
44- /// </summary>
44+ /// </summary>/
4545 /// <value>The item filter list.</value>
4646 public Dictionary<AssetLocation, RecoveryEntry> ItemRecoveryTable {
4747 get
@@ -90,13 +90,11 @@ namespace AnvilMetalRecovery
9090 else {
9191 Mod.Logger.Error("Cannot access 'ServerCoreAPI' class: API (implimentation) has changed, Contact Developer!");
9292 return;
93- }
94-
95- //ServerCore.ClassRegistryNative.ReplaceBlockEntityType(anvilKey, typeof(MetalRecovery_BlockEntityAnvil));
93+ }
9694
9795 ServerCore.Event.ServerRunPhase(EnumServerRunPhase.GameReady, MaterialDataGathering);
9896
99- SetupHotbarObserver( );
97+ SetupGeneralObservers( );
10098
10199 Mod.Logger.VerboseDebug("Anvil Metal Recovery - should be installed...");
102100
@@ -119,7 +117,7 @@ namespace AnvilMetalRecovery
119117 return;
120118 }
121119
122- //ClientCore.ClassRegistryNative.ReplaceBlockEntityType(anvilKey, typeof(MetalRecovery_BlockEntityAnvil));
120+
123121
124122 Mod.Logger.VerboseDebug("Anvil Metal Recovery - should be installed...");
125123 }
@@ -133,10 +131,8 @@ namespace AnvilMetalRecovery
133131
134132
135133
136- private void SetupHotbarObserver( ){
137- //ServerCore.RegisterEntityBehaviorClass(@"HotbarObserver", typeof(HotbarObserverBehavior));
138- ServerCore.Event.RegisterEventBusListener(HotbarEventReciever, 1.0f, HotbarChannelName);
139- //ServerCore.Event.PlayerNowPlaying += HotbarObserverBehavior.DirectConnect;
134+ private void SetupGeneralObservers( ){
135+ ServerCore.Event.RegisterEventBusListener(Item_DamageEventReciever, 1.0f, ItemDamageChannelName);
140136 }
141137
142138
--- a/AnvilMetalRecovery/MetalRecoverySystem_Components.cs
+++ b/AnvilMetalRecovery/MetalRecoverySystem_Components.cs
@@ -5,6 +5,7 @@ using System.Linq.Expressions;
55
66 using Vintagestory.API.Client;
77 using Vintagestory.API.Common;
8+using Vintagestory.API.Config;
89 using Vintagestory.API.Datastructures;
910 using Vintagestory.API.Server;
1011 using Vintagestory.Client.NoObf;
@@ -57,7 +58,7 @@ namespace AnvilMetalRecovery
5758 }
5859 else {
5960 itemToVoxelLookup.Add(outputItem.Code.Clone( ), new RecoveryEntry(metalObject.Code,
60- ( uint )(setVoxels / recipie.Output.Quantity),
61+ ( uint )(setVoxels / recipie.Output.Quantity),
6162 metalObject.CombustibleProps.MeltingDuration,
6263 metalObject.CombustibleProps.MeltingPoint)
6364 );
@@ -115,56 +116,60 @@ namespace AnvilMetalRecovery
115116 return false;
116117 }
117118
118- private void HotbarEventReciever(string eventName, ref EnumHandling handling, IAttribute data)
119+ private void Item_DamageEventReciever(string eventName, ref EnumHandling handling, IAttribute data)
119120 {
120121 handling = EnumHandling.PassThrough;
121122 HotbarObserverData hotbarData = data as HotbarObserverData;
122123
123124 #if DEBUG
124- Mod.Logger.VerboseDebug("HotbarEvent Rx: Item:{0} InventoryID '{1}' Slot#{2} PlayerUID:{3}", hotbarData.ItemCode.ToString( ),hotbarData.InventoryID ,hotbarData.Inventory_SlotID, hotbarData.PlayerUID);
125+ Mod.Logger.VerboseDebug("Item_Damage Rx: Item:{0} InventoryID '{1}' Slot#{2} PlayerUID:{3}", hotbarData.ItemCode.ToString( ), hotbarData.InventoryID, hotbarData.Inventory_SlotID, hotbarData.PlayerUID);
125126 #endif
126127
127- if (ItemFilterList.Contains(hotbarData.ItemCode)) {
128+ if (ItemFilterList.Contains(hotbarData.ItemCode)) {
129+
128130 RecoveryEntry rec = itemToVoxelLookup[hotbarData.ItemCode];
129131 #if DEBUG
130- Mod.Logger.VerboseDebug("broken-tool/weap. {0} WORTH: {1:F1}*{2} units", hotbarData.ItemCode.ToString( ), (rec.Quantity * IngotVoxelEquivalent), rec.IngotCode.ToShortString( ));
132+ Mod.Logger.VerboseDebug("broken-item {0} WORTH: {1:F1}*{2} units", hotbarData.ItemCode.ToString( ), (rec.Quantity * IngotVoxelEquivalent), rec.IngotCode.ToShortString( ));
131133 #endif
132134
135+ if (String.IsNullOrEmpty(hotbarData.PlayerUID) || String.IsNullOrEmpty(hotbarData.InventoryID)) return;
136+
137+ bool probablyHotbar = hotbarData.InventoryID.StartsWith(GlobalConstants.hotBarInvClassName, StringComparison.Ordinal);
133138 var playerTarget = ServerAPI.World.PlayerByUid(hotbarData.PlayerUID);
139+ var spim = playerTarget.InventoryManager as ServerPlayerInventoryManager;
134140 var hotbarInv = playerTarget.InventoryManager.GetHotbarInventory( );
135141 var hotSlot = hotbarInv[hotbarData.Inventory_SlotID];
136- var spim = playerTarget.InventoryManager as ServerPlayerInventoryManager;
137- bool probablyHotbar = hotbarData.InventoryID.StartsWith(@"hotbar", StringComparison.Ordinal);
138142
139- if (probablyHotbar && hotSlot.Empty) {
140- #if DEBUG
141- Mod.Logger.VerboseDebug("Directly inserting fragments into hotbar slot# {0}", hotbarData.Inventory_SlotID);
142- #endif
143+ if (probablyHotbar && hotSlot.Empty)
144+ {
145+ #if DEBUG
146+ Mod.Logger.VerboseDebug("Directly inserting fragments into hotbar slot# {0}", hotbarData.Inventory_SlotID);
147+ #endif
143148
144- VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem;
145- ItemStack metalFragmentsStack = new ItemStack(variableMetal, 1);
146- variableMetal.ApplyMetalProperties(rec, ref metalFragmentsStack);
147- hotSlot.Itemstack = metalFragmentsStack;
148- hotSlot.Itemstack.ResolveBlockOrItem(ServerAPI.World);
149- hotSlot.MarkDirty( );
150- spim.NotifySlot(playerTarget, hotSlot);
151- }
152- else {
153- #if DEBUG
154- Mod.Logger.VerboseDebug("Hotbar (or crafting?) slot#{0} occupied; shoving {1} in general direction of player...", hotbarData.Inventory_SlotID,hotbarData.ItemCode.ToShortString());
155- #endif
149+ VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem;
150+ ItemStack metalFragmentsStack = new ItemStack(variableMetal, 1);
151+ variableMetal.ApplyMetalProperties(rec, ref metalFragmentsStack);
152+ hotSlot.Itemstack = metalFragmentsStack;
153+ hotSlot.Itemstack.ResolveBlockOrItem(ServerAPI.World);
154+ hotSlot.MarkDirty( );
155+ spim.NotifySlot(playerTarget, hotSlot);
156+ }
157+ else
158+ {
159+ #if DEBUG
160+ Mod.Logger.VerboseDebug("Hotbar-occupied (or crafting) slot#{0} so; shoving {1} in general direction of player...", hotbarData.Inventory_SlotID, hotbarData.ItemCode.ToShortString( ));
161+ #endif
156162
157- VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem;
158- ItemStack metalFragmentsStack = new ItemStack(variableMetal, 1);
159- variableMetal.ApplyMetalProperties(rec, ref metalFragmentsStack);
160- spim.TryGiveItemstack(metalFragmentsStack, true);
161- }
163+ VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem;
164+ ItemStack metalFragmentsStack = new ItemStack(variableMetal, 1);
165+ variableMetal.ApplyMetalProperties(rec, ref metalFragmentsStack);
166+ spim.TryGiveItemstack(metalFragmentsStack, true);
167+ }
162168 }
163169
164170 }
165171
166172
167-
168173 private void EditDurability(IServerPlayer player, int groupId, CmdArgs args)
169174 {
170175 if (!player.Entity.RightHandItemSlot.Empty &&