• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

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

Revisione08d051014ac9f4b5ce5edf1a4072b78d05aab3c (tree)
Time2021-07-07 10:09:49
Authormelchior <melchior@user...>
Commitermelchior

Log Message

Entirely NEW method of detecting item expiry,
HotbarObserve class - now obsolete

Change Summary

Incremental Difference

--- a/AnvilMetalRecovery/AnvilMetalRecovery.csproj
+++ b/AnvilMetalRecovery/AnvilMetalRecovery.csproj
@@ -7,7 +7,7 @@
77 <OutputType>Library</OutputType>
88 <RootNamespace>AnvilMetalRecovery</RootNamespace>
99 <AssemblyName>AnvilMetalRecovery</AssemblyName>
10- <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
10+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
1111 </PropertyGroup>
1212 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1313 <DebugSymbols>true</DebugSymbols>
@@ -73,13 +73,13 @@
7373 <Compile Include="MetalRecoverySystem.cs" />
7474 <Compile Include="Properties\AssemblyInfo.cs" />
7575 <Compile Include="Helpers.cs" />
76- <Compile Include="EntityBehaviors\HotbarObserverBehavior.cs" />
7776 <Compile Include="EntityBehaviors\HotbarObserverData.cs" />
7877 <Compile Include="Data\RecoveryEntry.cs" />
7978 <Compile Include="Items\VariableMetalItem.cs" />
8079 <Compile Include="Items\SmartSmeltableItem.cs" />
8180 <Compile Include="Harmony\AnvilDaptor.cs" />
8281 <Compile Include="MetalRecoverySystem_Components.cs" />
82+ <Compile Include="Harmony\GenericItemMortalityDetector.cs" />
8383 </ItemGroup>
8484 <ItemGroup>
8585 <None Include="modinfo.json">
@@ -98,7 +98,6 @@
9898 <CopyToOutputDirectory>Always</CopyToOutputDirectory>
9999 </None>
100100 <None Include="assets\fma\patches\hotbarobserver_for_playerentity.json">
101- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
102101 </None>
103102 <None Include="modicon.png">
104103 <CopyToOutputDirectory>Always</CopyToOutputDirectory>
@@ -113,6 +112,7 @@
113112 <None Include="assets\fma\lang\de.json">
114113 <CopyToOutputDirectory>Always</CopyToOutputDirectory>
115114 </None>
115+ <None Include="EntityBehaviors\HotbarObserverBehavior.cs" />
116116 </ItemGroup>
117117 <ItemGroup>
118118 <Folder Include="assets\" />
--- a/AnvilMetalRecovery/EntityBehaviors/HotbarObserverBehavior.cs
+++ b/AnvilMetalRecovery/EntityBehaviors/HotbarObserverBehavior.cs
@@ -13,12 +13,13 @@ using Vintagestory.Server;
1313
1414 namespace AnvilMetalRecovery
1515 {
16+ #region OBSOLETE
1617 /// <summary>
1718 /// Push events to Messagebus on certain INVENTORY hotbar actions
1819 /// </summary>
1920 public class HotbarObserverBehavior : EntityBehavior
2021 {
21- public const string HotbarChannelName = @"HotbarEvents";
22+
2223 protected static List<AssetLocation> ItemFilterList;
2324 protected HotbarObserverData TrackedItemData;
2425 public bool Connected { get; private set;}
@@ -160,7 +161,7 @@ namespace AnvilMetalRecovery
160161 }
161162 return false;//When should this be true?
162163 }
163-
164+ #endregion
164165 }
165166 }
166167
--- a/AnvilMetalRecovery/EntityBehaviors/HotbarObserverData.cs
+++ b/AnvilMetalRecovery/EntityBehaviors/HotbarObserverData.cs
@@ -9,13 +9,15 @@ namespace AnvilMetalRecovery
99 public class HotbarObserverData : IAttribute
1010 {
1111 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; }
1314 public string PlayerUID { get; private set; }
1415
15- public HotbarObserverData(int slotID, Item item, string playerUID)
16+ public HotbarObserverData(string inventoryID, int slotID, AssetLocation itemCode, string playerUID)
1617 {
17- SlotID = slotID;
18- this.ItemCode = item.Code.Clone();
18+ InventoryID = inventoryID;
19+ Inventory_SlotID = slotID;
20+ this.ItemCode = itemCode.Clone();
1921 PlayerUID = playerUID;
2022 }
2123
@@ -26,7 +28,8 @@ namespace AnvilMetalRecovery
2628
2729 public void FromBytes(BinaryReader stream)
2830 {
29- SlotID = stream.ReadInt32( );
31+ InventoryID = stream.ReadString( );
32+ Inventory_SlotID = stream.ReadInt32( );
3033 ItemCode = new AssetLocation( stream.ReadString( ));
3134 PlayerUID = stream.ReadString( );
3235 }
@@ -43,7 +46,8 @@ namespace AnvilMetalRecovery
4346
4447 public void ToBytes(BinaryWriter stream)
4548 {
46- stream.Write(SlotID );
49+ stream.Write(InventoryID );
50+ stream.Write(Inventory_SlotID);
4751 stream.Write(ItemCode.ToString());
4852 stream.Write(PlayerUID);
4953 }
--- /dev/null
+++ b/AnvilMetalRecovery/Harmony/GenericItemMortalityDetector.cs
@@ -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+
--- a/AnvilMetalRecovery/MetalRecoverySystem.cs
+++ b/AnvilMetalRecovery/MetalRecoverySystem.cs
@@ -16,7 +16,9 @@ namespace AnvilMetalRecovery
1616 internal const string anvilKey = @"Anvil";
1717 internal const string metalFragmentsCode = @"fma:metal_fragments";
1818 internal const string metalShavingsCode = @"metal_shaving";
19+ internal const string itemFilterListCacheKey = @"AMR_ItemFilters";
1920 public const float IngotVoxelEquivalent = 2.38f;
21+ public const string HotbarChannelName = @"HotbarEvents";
2022
2123 private Dictionary<AssetLocation, RecoveryEntry> itemToVoxelLookup = new Dictionary<AssetLocation, RecoveryEntry>();//Ammount & Material?
2224
@@ -132,9 +134,9 @@ namespace AnvilMetalRecovery
132134
133135
134136 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;
138140 }
139141
140142
--- a/AnvilMetalRecovery/MetalRecoverySystem_Components.cs
+++ b/AnvilMetalRecovery/MetalRecoverySystem_Components.cs
@@ -98,6 +98,8 @@ namespace AnvilMetalRecovery
9898 }
9999 }
100100
101+ //Cache list too
102+ ServerAPI.ObjectCache.Add(itemFilterListCacheKey, itemToVoxelLookup);
101103 }
102104
103105 private bool SmithingRecipieValidator(SmithingRecipe aRecipie )
@@ -119,7 +121,7 @@ namespace AnvilMetalRecovery
119121 HotbarObserverData hotbarData = data as HotbarObserverData;
120122
121123 #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);
123125 #endif
124126
125127 if (ItemFilterList.Contains(hotbarData.ItemCode)) {
@@ -130,13 +132,13 @@ namespace AnvilMetalRecovery
130132
131133 var playerTarget = ServerAPI.World.PlayerByUid(hotbarData.PlayerUID);
132134 var hotbarInv = playerTarget.InventoryManager.GetHotbarInventory( );
133- var hotSlot = hotbarInv[hotbarData.SlotID];
135+ var hotSlot = hotbarInv[hotbarData.Inventory_SlotID];
134136 var spim = playerTarget.InventoryManager as ServerPlayerInventoryManager;
137+ bool probablyHotbar = hotbarData.InventoryID.StartsWith(@"hotbar", StringComparison.Ordinal);
135138
136-
137- if (hotSlot.Empty) {
139+ if (probablyHotbar && hotSlot.Empty) {
138140 #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);
140142 #endif
141143
142144 VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem;
@@ -149,7 +151,7 @@ namespace AnvilMetalRecovery
149151 }
150152 else {
151153 #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());
153155 #endif
154156
155157 VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem;
--- a/AnvilMetalRecovery/Properties/AssemblyInfo.cs
+++ b/AnvilMetalRecovery/Properties/AssemblyInfo.cs
@@ -5,11 +5,14 @@ using System.Runtime.CompilerServices;
55 // Change them to the values specific to your project.
66
77 [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")]
1316 [assembly: AssemblyTrademark("")]
1417 [assembly: AssemblyCulture("")]
1518
@@ -17,7 +20,7 @@ using System.Runtime.CompilerServices;
1720 // The form "{Major}.{Minor}.*" will automatically update the build and revision,
1821 // and "{Major}.{Minor}.{Build}.*" will update just the revision.
1922
20-[assembly: AssemblyVersion("1.0.*")]
23+[assembly: AssemblyVersion("0.1.9")]
2124
2225 // The following attributes are used to specify the signing key for the assembly,
2326 // if desired. See the Mono documentation for more information about signing.
--- a/AnvilMetalRecovery/modinfo.json
+++ b/AnvilMetalRecovery/modinfo.json
@@ -4,7 +4,7 @@
44 "description" : "Get back lost scrap and smithing discards. Plus more.",
55 "authors": ["Melchior"],
66 "ModID":"metalrecovery",
7- "version": "0.1.8",
7+ "version": "0.1.9",
88 "dependencies": {
99 "game": "1.14.10",
1010 "survival": ""
--- /dev/null
+++ b/Machinations/BlockBehaviors/BEMultiphaseGearmesh.cs
@@ -0,0 +1,11 @@
1+using System;
2+namespace Machinations
3+{
4+ public class BEMultiphaseGearmesh
5+ {
6+ public BEMultiphaseGearmesh( )
7+ {
8+ }
9+ }
10+}
11+
--- /dev/null
+++ b/Machinations/Rendering/GearmeshBlockRenderer.cs
@@ -0,0 +1,11 @@
1+using System;
2+namespace Machinations
3+{
4+ public class GearmeshBlockRenderer
5+ {
6+ public GearmeshBlockRenderer( )
7+ {
8+ }
9+ }
10+}
11+