First Machine Age's Mods (Combined repo.)
Revision | e08d051014ac9f4b5ce5edf1a4072b78d05aab3c (tree) |
---|---|
Time | 2021-07-07 10:09:49 |
Author | melchior <melchior@user...> |
Commiter | melchior |
Entirely NEW method of detecting item expiry,
HotbarObserve class - now obsolete
@@ -7,7 +7,7 @@ | ||
7 | 7 | <OutputType>Library</OutputType> |
8 | 8 | <RootNamespace>AnvilMetalRecovery</RootNamespace> |
9 | 9 | <AssemblyName>AnvilMetalRecovery</AssemblyName> |
10 | - <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | |
10 | + <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | |
11 | 11 | </PropertyGroup> |
12 | 12 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
13 | 13 | <DebugSymbols>true</DebugSymbols> |
@@ -73,13 +73,13 @@ | ||
73 | 73 | <Compile Include="MetalRecoverySystem.cs" /> |
74 | 74 | <Compile Include="Properties\AssemblyInfo.cs" /> |
75 | 75 | <Compile Include="Helpers.cs" /> |
76 | - <Compile Include="EntityBehaviors\HotbarObserverBehavior.cs" /> | |
77 | 76 | <Compile Include="EntityBehaviors\HotbarObserverData.cs" /> |
78 | 77 | <Compile Include="Data\RecoveryEntry.cs" /> |
79 | 78 | <Compile Include="Items\VariableMetalItem.cs" /> |
80 | 79 | <Compile Include="Items\SmartSmeltableItem.cs" /> |
81 | 80 | <Compile Include="Harmony\AnvilDaptor.cs" /> |
82 | 81 | <Compile Include="MetalRecoverySystem_Components.cs" /> |
82 | + <Compile Include="Harmony\GenericItemMortalityDetector.cs" /> | |
83 | 83 | </ItemGroup> |
84 | 84 | <ItemGroup> |
85 | 85 | <None Include="modinfo.json"> |
@@ -98,7 +98,6 @@ | ||
98 | 98 | <CopyToOutputDirectory>Always</CopyToOutputDirectory> |
99 | 99 | </None> |
100 | 100 | <None Include="assets\fma\patches\hotbarobserver_for_playerentity.json"> |
101 | - <CopyToOutputDirectory>Always</CopyToOutputDirectory> | |
102 | 101 | </None> |
103 | 102 | <None Include="modicon.png"> |
104 | 103 | <CopyToOutputDirectory>Always</CopyToOutputDirectory> |
@@ -113,6 +112,7 @@ | ||
113 | 112 | <None Include="assets\fma\lang\de.json"> |
114 | 113 | <CopyToOutputDirectory>Always</CopyToOutputDirectory> |
115 | 114 | </None> |
115 | + <None Include="EntityBehaviors\HotbarObserverBehavior.cs" /> | |
116 | 116 | </ItemGroup> |
117 | 117 | <ItemGroup> |
118 | 118 | <Folder Include="assets\" /> |
@@ -13,12 +13,13 @@ using Vintagestory.Server; | ||
13 | 13 | |
14 | 14 | namespace AnvilMetalRecovery |
15 | 15 | { |
16 | + #region OBSOLETE | |
16 | 17 | /// <summary> |
17 | 18 | /// Push events to Messagebus on certain INVENTORY hotbar actions |
18 | 19 | /// </summary> |
19 | 20 | public class HotbarObserverBehavior : EntityBehavior |
20 | 21 | { |
21 | - public const string HotbarChannelName = @"HotbarEvents"; | |
22 | + | |
22 | 23 | protected static List<AssetLocation> ItemFilterList; |
23 | 24 | protected HotbarObserverData TrackedItemData; |
24 | 25 | public bool Connected { get; private set;} |
@@ -160,7 +161,7 @@ namespace AnvilMetalRecovery | ||
160 | 161 | } |
161 | 162 | return false;//When should this be true? |
162 | 163 | } |
163 | - | |
164 | + #endregion | |
164 | 165 | } |
165 | 166 | } |
166 | 167 |
@@ -9,13 +9,15 @@ namespace AnvilMetalRecovery | ||
9 | 9 | public class HotbarObserverData : IAttribute |
10 | 10 | { |
11 | 11 | public AssetLocation ItemCode { get; private set; } |
12 | - public int SlotID { get; private set; } | |
12 | + public string InventoryID { get; private set; } | |
13 | + public int Inventory_SlotID { get; private set; } | |
13 | 14 | public string PlayerUID { get; private set; } |
14 | 15 | |
15 | - public HotbarObserverData(int slotID, Item item, string playerUID) | |
16 | + public HotbarObserverData(string inventoryID, int slotID, AssetLocation itemCode, string playerUID) | |
16 | 17 | { |
17 | - SlotID = slotID; | |
18 | - this.ItemCode = item.Code.Clone(); | |
18 | + InventoryID = inventoryID; | |
19 | + Inventory_SlotID = slotID; | |
20 | + this.ItemCode = itemCode.Clone(); | |
19 | 21 | PlayerUID = playerUID; |
20 | 22 | } |
21 | 23 |
@@ -26,7 +28,8 @@ namespace AnvilMetalRecovery | ||
26 | 28 | |
27 | 29 | public void FromBytes(BinaryReader stream) |
28 | 30 | { |
29 | - SlotID = stream.ReadInt32( ); | |
31 | + InventoryID = stream.ReadString( ); | |
32 | + Inventory_SlotID = stream.ReadInt32( ); | |
30 | 33 | ItemCode = new AssetLocation( stream.ReadString( )); |
31 | 34 | PlayerUID = stream.ReadString( ); |
32 | 35 | } |
@@ -43,7 +46,8 @@ namespace AnvilMetalRecovery | ||
43 | 46 | |
44 | 47 | public void ToBytes(BinaryWriter stream) |
45 | 48 | { |
46 | - stream.Write(SlotID ); | |
49 | + stream.Write(InventoryID ); | |
50 | + stream.Write(Inventory_SlotID); | |
47 | 51 | stream.Write(ItemCode.ToString()); |
48 | 52 | stream.Write(PlayerUID); |
49 | 53 | } |
@@ -0,0 +1,87 @@ | ||
1 | +using System; | |
2 | +using System.Collections.Generic; | |
3 | +using System.Linq; | |
4 | +using System.Reflection; | |
5 | +using System.Text; | |
6 | + | |
7 | +using HarmonyLib; | |
8 | + | |
9 | +using Vintagestory.API.Common; | |
10 | +using Vintagestory.API.Common.Entities; | |
11 | +using Vintagestory.API.Config; | |
12 | +using Vintagestory.API.MathTools; | |
13 | +using Vintagestory.GameContent; | |
14 | + | |
15 | +namespace AnvilMetalRecovery.Patches | |
16 | +{ | |
17 | + | |
18 | + /// <summary> | |
19 | + /// Harmony patcher class to detect Item (CollectableObject) Hitpoint damage and generate Destruction events from 'Damage' method calls | |
20 | + /// </summary> | |
21 | + [HarmonyPatch(typeof(CollectibleObject))] | |
22 | + public class GenericItemMortalityDetector | |
23 | + { | |
24 | + | |
25 | + [HarmonyPrepare] | |
26 | + private static bool DeduplicatePatching(MethodBase original, Harmony harmony) | |
27 | + { | |
28 | + if (original != null) | |
29 | + { | |
30 | + foreach (var patched in harmony.GetPatchedMethods( )) | |
31 | + { | |
32 | + if (patched.Name == original.Name) return false; //SKIPS PATCHING, its already there | |
33 | + } | |
34 | + } | |
35 | + | |
36 | + return true;//patch all other methods | |
37 | + } | |
38 | + | |
39 | + | |
40 | + | |
41 | + [HarmonyPrefix] | |
42 | + [HarmonyPatch(nameof(CollectibleObject.DamageItem))] | |
43 | + private static void Prefix_DamageItem(IWorldAccessor world, Entity byEntity, ItemSlot itemslot, int amount, CollectibleObject __instance)//Object __state | |
44 | + { | |
45 | + if (world.Api.Side.IsClient( )) return; | |
46 | + #if DEBUG | |
47 | + world.Api.Logger.VerboseDebug("Prefix_DamageItem: {0} by {1}", __instance.Code, amount); | |
48 | + #endif | |
49 | + if (DamageFilterTool.Ignore(world, __instance)) return; | |
50 | + #if DEBUG | |
51 | + world.Api.Logger.VerboseDebug("InventoryID: {0}, Class: {1}", itemslot.Inventory.InventoryID, itemslot.Inventory.ClassName);//Class: hotbar | |
52 | + world.Api.Logger.VerboseDebug("Thing has HP: {0}", itemslot.Itemstack.Hitpoints( )); | |
53 | + #endif | |
54 | + if (itemslot.Itemstack.Hitpoints( ) <= amount) | |
55 | + { | |
56 | + #if DEBUG | |
57 | + world.Api.Logger.VerboseDebug("Sending Item Expiry Event"); | |
58 | + #endif | |
59 | + var playerEntity = byEntity as EntityPlayer; | |
60 | + 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); | |
62 | + } | |
63 | + } | |
64 | + | |
65 | + /// <summary> | |
66 | + /// Specialized Multitool for Setting / Getting, Checking Item-Filter list; and Ignore non-Items | |
67 | + /// </summary> | |
68 | + internal static class DamageFilterTool | |
69 | + { | |
70 | + | |
71 | + public static bool Ignore(IWorldAccessor world, CollectibleObject that) | |
72 | + { | |
73 | + if (that.ItemClass != EnumItemClass.Item || that.Durability <= 1) { | |
74 | + return true; | |
75 | + } | |
76 | + | |
77 | + Dictionary<AssetLocation, RecoveryEntry> itemToVoxelLookup = ( Dictionary<AssetLocation, RecoveryEntry> )world.Api.ObjectCache[MetalRecoverySystem.itemFilterListCacheKey]; | |
78 | + | |
79 | + if (itemToVoxelLookup.ContainsKey(that.Code)) return false; | |
80 | + | |
81 | + return true; | |
82 | + } | |
83 | + | |
84 | + } | |
85 | + } | |
86 | +} | |
87 | + |
@@ -16,7 +16,9 @@ namespace AnvilMetalRecovery | ||
16 | 16 | internal const string anvilKey = @"Anvil"; |
17 | 17 | internal const string metalFragmentsCode = @"fma:metal_fragments"; |
18 | 18 | internal const string metalShavingsCode = @"metal_shaving"; |
19 | + internal const string itemFilterListCacheKey = @"AMR_ItemFilters"; | |
19 | 20 | public const float IngotVoxelEquivalent = 2.38f; |
21 | + public const string HotbarChannelName = @"HotbarEvents"; | |
20 | 22 | |
21 | 23 | private Dictionary<AssetLocation, RecoveryEntry> itemToVoxelLookup = new Dictionary<AssetLocation, RecoveryEntry>();//Ammount & Material? |
22 | 24 |
@@ -132,9 +134,9 @@ namespace AnvilMetalRecovery | ||
132 | 134 | |
133 | 135 | |
134 | 136 | private void SetupHotbarObserver( ){ |
135 | - ServerCore.RegisterEntityBehaviorClass(@"HotbarObserver", typeof(HotbarObserverBehavior)); | |
136 | - ServerCore.Event.RegisterEventBusListener(HotbarEventReciever, 1.0f, HotbarObserverBehavior.HotbarChannelName); | |
137 | - ServerCore.Event.PlayerNowPlaying += HotbarObserverBehavior.DirectConnect; | |
137 | + //ServerCore.RegisterEntityBehaviorClass(@"HotbarObserver", typeof(HotbarObserverBehavior)); | |
138 | + ServerCore.Event.RegisterEventBusListener(HotbarEventReciever, 1.0f, HotbarChannelName); | |
139 | + //ServerCore.Event.PlayerNowPlaying += HotbarObserverBehavior.DirectConnect; | |
138 | 140 | } |
139 | 141 | |
140 | 142 |
@@ -98,6 +98,8 @@ namespace AnvilMetalRecovery | ||
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | + //Cache list too | |
102 | + ServerAPI.ObjectCache.Add(itemFilterListCacheKey, itemToVoxelLookup); | |
101 | 103 | } |
102 | 104 | |
103 | 105 | private bool SmithingRecipieValidator(SmithingRecipe aRecipie ) |
@@ -119,7 +121,7 @@ namespace AnvilMetalRecovery | ||
119 | 121 | HotbarObserverData hotbarData = data as HotbarObserverData; |
120 | 122 | |
121 | 123 | #if DEBUG |
122 | - Mod.Logger.VerboseDebug("HotbarEvent Rx: Item:{0} Slot#{1} PlayerUID:{2}", hotbarData.ItemCode.ToString( ), hotbarData.SlotID, hotbarData.PlayerUID); | |
124 | + Mod.Logger.VerboseDebug("HotbarEvent Rx: Item:{0} InventoryID '{1}' Slot#{2} PlayerUID:{3}", hotbarData.ItemCode.ToString( ),hotbarData.InventoryID ,hotbarData.Inventory_SlotID, hotbarData.PlayerUID); | |
123 | 125 | #endif |
124 | 126 | |
125 | 127 | if (ItemFilterList.Contains(hotbarData.ItemCode)) { |
@@ -130,13 +132,13 @@ namespace AnvilMetalRecovery | ||
130 | 132 | |
131 | 133 | var playerTarget = ServerAPI.World.PlayerByUid(hotbarData.PlayerUID); |
132 | 134 | var hotbarInv = playerTarget.InventoryManager.GetHotbarInventory( ); |
133 | - var hotSlot = hotbarInv[hotbarData.SlotID]; | |
135 | + var hotSlot = hotbarInv[hotbarData.Inventory_SlotID]; | |
134 | 136 | var spim = playerTarget.InventoryManager as ServerPlayerInventoryManager; |
137 | + bool probablyHotbar = hotbarData.InventoryID.StartsWith(@"hotbar", StringComparison.Ordinal); | |
135 | 138 | |
136 | - | |
137 | - if (hotSlot.Empty) { | |
139 | + if (probablyHotbar && hotSlot.Empty) { | |
138 | 140 | #if DEBUG |
139 | - Mod.Logger.VerboseDebug("Directly inserting fragments into hotbar slot# {0}", hotbarData.SlotID); | |
141 | + Mod.Logger.VerboseDebug("Directly inserting fragments into hotbar slot# {0}", hotbarData.Inventory_SlotID); | |
140 | 142 | #endif |
141 | 143 | |
142 | 144 | VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem; |
@@ -149,7 +151,7 @@ namespace AnvilMetalRecovery | ||
149 | 151 | } |
150 | 152 | else { |
151 | 153 | #if DEBUG |
152 | - Mod.Logger.VerboseDebug("Occupied Hotbar slot# {0}; shoving item in general direction of player...", hotbarData.SlotID); | |
154 | + Mod.Logger.VerboseDebug("Hotbar (or crafting?) slot#{0} occupied; shoving {1} in general direction of player...", hotbarData.Inventory_SlotID,hotbarData.ItemCode.ToShortString()); | |
153 | 155 | #endif |
154 | 156 | |
155 | 157 | VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem; |
@@ -5,11 +5,14 @@ using System.Runtime.CompilerServices; | ||
5 | 5 | // Change them to the values specific to your project. |
6 | 6 | |
7 | 7 | [assembly: AssemblyTitle("AnvilMetalRecovery")] |
8 | -[assembly: AssemblyDescription("")] | |
9 | -[assembly: AssemblyConfiguration("")] | |
10 | -[assembly: AssemblyCompany("")] | |
11 | -[assembly: AssemblyProduct("")] | |
12 | -[assembly: AssemblyCopyright("librarian")] | |
8 | +[assembly: AssemblyDescription("Mod plugin for V.S.")] | |
9 | +#if DEBUG | |
10 | +[assembly: AssemblyConfiguration("DEBUG")] | |
11 | +#else | |
12 | +[assembly: AssemblyConfiguration("RELEASE")] | |
13 | +#endif | |
14 | +[assembly: AssemblyProduct("First_Machine_Age_component")] | |
15 | +[assembly: AssemblyCopyright("Melchior")] | |
13 | 16 | [assembly: AssemblyTrademark("")] |
14 | 17 | [assembly: AssemblyCulture("")] |
15 | 18 |
@@ -17,7 +20,7 @@ using System.Runtime.CompilerServices; | ||
17 | 20 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, |
18 | 21 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. |
19 | 22 | |
20 | -[assembly: AssemblyVersion("1.0.*")] | |
23 | +[assembly: AssemblyVersion("0.1.9")] | |
21 | 24 | |
22 | 25 | // The following attributes are used to specify the signing key for the assembly, |
23 | 26 | // if desired. See the Mono documentation for more information about signing. |
@@ -4,7 +4,7 @@ | ||
4 | 4 | "description" : "Get back lost scrap and smithing discards. Plus more.", |
5 | 5 | "authors": ["Melchior"], |
6 | 6 | "ModID":"metalrecovery", |
7 | - "version": "0.1.8", | |
7 | + "version": "0.1.9", | |
8 | 8 | "dependencies": { |
9 | 9 | "game": "1.14.10", |
10 | 10 | "survival": "" |
@@ -0,0 +1,11 @@ | ||
1 | +using System; | |
2 | +namespace Machinations | |
3 | +{ | |
4 | + public class BEMultiphaseGearmesh | |
5 | + { | |
6 | + public BEMultiphaseGearmesh( ) | |
7 | + { | |
8 | + } | |
9 | + } | |
10 | +} | |
11 | + |
@@ -0,0 +1,11 @@ | ||
1 | +using System; | |
2 | +namespace Machinations | |
3 | +{ | |
4 | + public class GearmeshBlockRenderer | |
5 | + { | |
6 | + public GearmeshBlockRenderer( ) | |
7 | + { | |
8 | + } | |
9 | + } | |
10 | +} | |
11 | + |