diff --git a/AnvilMetalRecovery/AnvilMetalRecovery.csproj b/AnvilMetalRecovery/AnvilMetalRecovery.csproj index 06c8506..218d42f 100644 --- a/AnvilMetalRecovery/AnvilMetalRecovery.csproj +++ b/AnvilMetalRecovery/AnvilMetalRecovery.csproj @@ -7,7 +7,7 @@ Library AnvilMetalRecovery AnvilMetalRecovery - v4.5 + v4.5.2 true @@ -73,13 +73,13 @@ - + @@ -98,7 +98,6 @@ Always - Always Always @@ -113,6 +112,7 @@ Always + diff --git a/AnvilMetalRecovery/EntityBehaviors/HotbarObserverBehavior.cs b/AnvilMetalRecovery/EntityBehaviors/HotbarObserverBehavior.cs index 68f27b9..b3fdf06 100644 --- a/AnvilMetalRecovery/EntityBehaviors/HotbarObserverBehavior.cs +++ b/AnvilMetalRecovery/EntityBehaviors/HotbarObserverBehavior.cs @@ -13,12 +13,13 @@ using Vintagestory.Server; namespace AnvilMetalRecovery { + #region OBSOLETE /// /// Push events to Messagebus on certain INVENTORY hotbar actions /// public class HotbarObserverBehavior : EntityBehavior { - public const string HotbarChannelName = @"HotbarEvents"; + protected static List ItemFilterList; protected HotbarObserverData TrackedItemData; public bool Connected { get; private set;} @@ -160,7 +161,7 @@ namespace AnvilMetalRecovery } return false;//When should this be true? } - + #endregion } } diff --git a/AnvilMetalRecovery/EntityBehaviors/HotbarObserverData.cs b/AnvilMetalRecovery/EntityBehaviors/HotbarObserverData.cs index 781a2da..63b6160 100644 --- a/AnvilMetalRecovery/EntityBehaviors/HotbarObserverData.cs +++ b/AnvilMetalRecovery/EntityBehaviors/HotbarObserverData.cs @@ -9,13 +9,15 @@ namespace AnvilMetalRecovery public class HotbarObserverData : IAttribute { public AssetLocation ItemCode { get; private set; } - public int SlotID { get; private set; } + public string InventoryID { get; private set; } + public int Inventory_SlotID { get; private set; } public string PlayerUID { get; private set; } - public HotbarObserverData(int slotID, Item item, string playerUID) + public HotbarObserverData(string inventoryID, int slotID, AssetLocation itemCode, string playerUID) { - SlotID = slotID; - this.ItemCode = item.Code.Clone(); + InventoryID = inventoryID; + Inventory_SlotID = slotID; + this.ItemCode = itemCode.Clone(); PlayerUID = playerUID; } @@ -26,7 +28,8 @@ namespace AnvilMetalRecovery public void FromBytes(BinaryReader stream) { - SlotID = stream.ReadInt32( ); + InventoryID = stream.ReadString( ); + Inventory_SlotID = stream.ReadInt32( ); ItemCode = new AssetLocation( stream.ReadString( )); PlayerUID = stream.ReadString( ); } @@ -43,7 +46,8 @@ namespace AnvilMetalRecovery public void ToBytes(BinaryWriter stream) { - stream.Write(SlotID ); + stream.Write(InventoryID ); + stream.Write(Inventory_SlotID); stream.Write(ItemCode.ToString()); stream.Write(PlayerUID); } diff --git a/AnvilMetalRecovery/Harmony/GenericItemMortalityDetector.cs b/AnvilMetalRecovery/Harmony/GenericItemMortalityDetector.cs new file mode 100644 index 0000000..d97d582 --- /dev/null +++ b/AnvilMetalRecovery/Harmony/GenericItemMortalityDetector.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; + +using HarmonyLib; + +using Vintagestory.API.Common; +using Vintagestory.API.Common.Entities; +using Vintagestory.API.Config; +using Vintagestory.API.MathTools; +using Vintagestory.GameContent; + +namespace AnvilMetalRecovery.Patches +{ + + /// + /// Harmony patcher class to detect Item (CollectableObject) Hitpoint damage and generate Destruction events from 'Damage' method calls + /// + [HarmonyPatch(typeof(CollectibleObject))] + public class GenericItemMortalityDetector + { + + [HarmonyPrepare] + private static bool DeduplicatePatching(MethodBase original, Harmony harmony) + { + if (original != null) + { + foreach (var patched in harmony.GetPatchedMethods( )) + { + if (patched.Name == original.Name) return false; //SKIPS PATCHING, its already there + } + } + + return true;//patch all other methods + } + + + + [HarmonyPrefix] + [HarmonyPatch(nameof(CollectibleObject.DamageItem))] + private static void Prefix_DamageItem(IWorldAccessor world, Entity byEntity, ItemSlot itemslot, int amount, CollectibleObject __instance)//Object __state + { + if (world.Api.Side.IsClient( )) return; + #if DEBUG + world.Api.Logger.VerboseDebug("Prefix_DamageItem: {0} by {1}", __instance.Code, amount); + #endif + if (DamageFilterTool.Ignore(world, __instance)) return; + #if DEBUG + world.Api.Logger.VerboseDebug("InventoryID: {0}, Class: {1}", itemslot.Inventory.InventoryID, itemslot.Inventory.ClassName);//Class: hotbar + world.Api.Logger.VerboseDebug("Thing has HP: {0}", itemslot.Itemstack.Hitpoints( )); + #endif + if (itemslot.Itemstack.Hitpoints( ) <= amount) + { + #if DEBUG + world.Api.Logger.VerboseDebug("Sending Item Expiry Event"); + #endif + var playerEntity = byEntity as EntityPlayer; + var hotbarEvent = new HotbarObserverData(itemslot.Inventory.InventoryID, itemslot.Inventory.GetSlotId(itemslot), __instance.Code, (playerEntity == null ? String.Empty : playerEntity.PlayerUID)); + world.Api.Event.PushEvent(MetalRecoverySystem.HotbarChannelName, hotbarEvent); + } + } + + /// + /// Specialized Multitool for Setting / Getting, Checking Item-Filter list; and Ignore non-Items + /// + internal static class DamageFilterTool + { + + public static bool Ignore(IWorldAccessor world, CollectibleObject that) + { + if (that.ItemClass != EnumItemClass.Item || that.Durability <= 1) { + return true; + } + + Dictionary itemToVoxelLookup = ( Dictionary )world.Api.ObjectCache[MetalRecoverySystem.itemFilterListCacheKey]; + + if (itemToVoxelLookup.ContainsKey(that.Code)) return false; + + return true; + } + + } + } +} + diff --git a/AnvilMetalRecovery/MetalRecoverySystem.cs b/AnvilMetalRecovery/MetalRecoverySystem.cs index 7561f27..cdf2d31 100644 --- a/AnvilMetalRecovery/MetalRecoverySystem.cs +++ b/AnvilMetalRecovery/MetalRecoverySystem.cs @@ -16,7 +16,9 @@ namespace AnvilMetalRecovery internal const string anvilKey = @"Anvil"; internal const string metalFragmentsCode = @"fma:metal_fragments"; internal const string metalShavingsCode = @"metal_shaving"; + internal const string itemFilterListCacheKey = @"AMR_ItemFilters"; public const float IngotVoxelEquivalent = 2.38f; + public const string HotbarChannelName = @"HotbarEvents"; private Dictionary itemToVoxelLookup = new Dictionary();//Ammount & Material? @@ -132,9 +134,9 @@ namespace AnvilMetalRecovery private void SetupHotbarObserver( ){ - ServerCore.RegisterEntityBehaviorClass(@"HotbarObserver", typeof(HotbarObserverBehavior)); - ServerCore.Event.RegisterEventBusListener(HotbarEventReciever, 1.0f, HotbarObserverBehavior.HotbarChannelName); - ServerCore.Event.PlayerNowPlaying += HotbarObserverBehavior.DirectConnect; + //ServerCore.RegisterEntityBehaviorClass(@"HotbarObserver", typeof(HotbarObserverBehavior)); + ServerCore.Event.RegisterEventBusListener(HotbarEventReciever, 1.0f, HotbarChannelName); + //ServerCore.Event.PlayerNowPlaying += HotbarObserverBehavior.DirectConnect; } diff --git a/AnvilMetalRecovery/MetalRecoverySystem_Components.cs b/AnvilMetalRecovery/MetalRecoverySystem_Components.cs index 6b19b59..347658c 100644 --- a/AnvilMetalRecovery/MetalRecoverySystem_Components.cs +++ b/AnvilMetalRecovery/MetalRecoverySystem_Components.cs @@ -98,6 +98,8 @@ namespace AnvilMetalRecovery } } + //Cache list too + ServerAPI.ObjectCache.Add(itemFilterListCacheKey, itemToVoxelLookup); } private bool SmithingRecipieValidator(SmithingRecipe aRecipie ) @@ -119,7 +121,7 @@ namespace AnvilMetalRecovery HotbarObserverData hotbarData = data as HotbarObserverData; #if DEBUG - Mod.Logger.VerboseDebug("HotbarEvent Rx: Item:{0} Slot#{1} PlayerUID:{2}", hotbarData.ItemCode.ToString( ), hotbarData.SlotID, hotbarData.PlayerUID); + Mod.Logger.VerboseDebug("HotbarEvent Rx: Item:{0} InventoryID '{1}' Slot#{2} PlayerUID:{3}", hotbarData.ItemCode.ToString( ),hotbarData.InventoryID ,hotbarData.Inventory_SlotID, hotbarData.PlayerUID); #endif if (ItemFilterList.Contains(hotbarData.ItemCode)) { @@ -130,13 +132,13 @@ namespace AnvilMetalRecovery var playerTarget = ServerAPI.World.PlayerByUid(hotbarData.PlayerUID); var hotbarInv = playerTarget.InventoryManager.GetHotbarInventory( ); - var hotSlot = hotbarInv[hotbarData.SlotID]; + var hotSlot = hotbarInv[hotbarData.Inventory_SlotID]; var spim = playerTarget.InventoryManager as ServerPlayerInventoryManager; + bool probablyHotbar = hotbarData.InventoryID.StartsWith(@"hotbar", StringComparison.Ordinal); - - if (hotSlot.Empty) { + if (probablyHotbar && hotSlot.Empty) { #if DEBUG - Mod.Logger.VerboseDebug("Directly inserting fragments into hotbar slot# {0}", hotbarData.SlotID); + Mod.Logger.VerboseDebug("Directly inserting fragments into hotbar slot# {0}", hotbarData.Inventory_SlotID); #endif VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem; @@ -149,7 +151,7 @@ namespace AnvilMetalRecovery } else { #if DEBUG - Mod.Logger.VerboseDebug("Occupied Hotbar slot# {0}; shoving item in general direction of player...", hotbarData.SlotID); + Mod.Logger.VerboseDebug("Hotbar (or crafting?) slot#{0} occupied; shoving {1} in general direction of player...", hotbarData.Inventory_SlotID,hotbarData.ItemCode.ToShortString()); #endif VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem; diff --git a/AnvilMetalRecovery/Properties/AssemblyInfo.cs b/AnvilMetalRecovery/Properties/AssemblyInfo.cs index 9a50c58..374448e 100644 --- a/AnvilMetalRecovery/Properties/AssemblyInfo.cs +++ b/AnvilMetalRecovery/Properties/AssemblyInfo.cs @@ -5,11 +5,14 @@ using System.Runtime.CompilerServices; // Change them to the values specific to your project. [assembly: AssemblyTitle("AnvilMetalRecovery")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("librarian")] +[assembly: AssemblyDescription("Mod plugin for V.S.")] +#if DEBUG +[assembly: AssemblyConfiguration("DEBUG")] +#else +[assembly: AssemblyConfiguration("RELEASE")] +#endif +[assembly: AssemblyProduct("First_Machine_Age_component")] +[assembly: AssemblyCopyright("Melchior")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -17,7 +20,7 @@ using System.Runtime.CompilerServices; // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("0.1.9")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. diff --git a/AnvilMetalRecovery/modinfo.json b/AnvilMetalRecovery/modinfo.json index 9da6bbd..5ff850f 100644 --- a/AnvilMetalRecovery/modinfo.json +++ b/AnvilMetalRecovery/modinfo.json @@ -4,7 +4,7 @@ "description" : "Get back lost scrap and smithing discards. Plus more.", "authors": ["Melchior"], "ModID":"metalrecovery", - "version": "0.1.8", + "version": "0.1.9", "dependencies": { "game": "1.14.10", "survival": "" diff --git a/Machinations/BlockBehaviors/BEMultiphaseGearmesh.cs b/Machinations/BlockBehaviors/BEMultiphaseGearmesh.cs new file mode 100644 index 0000000..1f637d2 --- /dev/null +++ b/Machinations/BlockBehaviors/BEMultiphaseGearmesh.cs @@ -0,0 +1,11 @@ +using System; +namespace Machinations +{ + public class BEMultiphaseGearmesh + { + public BEMultiphaseGearmesh( ) + { + } + } +} + diff --git a/Machinations/Rendering/GearmeshBlockRenderer.cs b/Machinations/Rendering/GearmeshBlockRenderer.cs new file mode 100644 index 0000000..52b58bb --- /dev/null +++ b/Machinations/Rendering/GearmeshBlockRenderer.cs @@ -0,0 +1,11 @@ +using System; +namespace Machinations +{ + public class GearmeshBlockRenderer + { + public GearmeshBlockRenderer( ) + { + } + } +} +