From 5064f607b5b103a550a1948d3867edde05df024e Mon Sep 17 00:00:00 2001 From: Dencher12 Date: Sun, 29 Jun 2025 02:00:22 +0300 Subject: [PATCH] Catch gear break event --- .gitignore | 2 -- .idea/.idea.GearToLife/.idea/workspace.xml | 29 ++++++++------------ GearToLife.sln.DotSettings.user | 9 ++++++ GearToLife/GearToLife/GearToLifeModSystem.cs | 25 ++++++++--------- GearToLife/GearToLife/Patches/KnifePatch.cs | 21 ++++++++++++++ 5 files changed, 52 insertions(+), 34 deletions(-) delete mode 100644 .gitignore create mode 100644 GearToLife.sln.DotSettings.user create mode 100644 GearToLife/GearToLife/Patches/KnifePatch.cs diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 2836780..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -bin/ -obj/ \ No newline at end of file diff --git a/.idea/.idea.GearToLife/.idea/workspace.xml b/.idea/.idea.GearToLife/.idea/workspace.xml index b4173a5..abdc99a 100644 --- a/.idea/.idea.GearToLife/.idea/workspace.xml +++ b/.idea/.idea.GearToLife/.idea/workspace.xml @@ -10,23 +10,10 @@ - - - - - - - - - - - - - - - - - + + + + diff --git a/GearToLife.sln.DotSettings.user b/GearToLife.sln.DotSettings.user new file mode 100644 index 0000000..f9c6d3f --- /dev/null +++ b/GearToLife.sln.DotSettings.user @@ -0,0 +1,9 @@ + + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + <AssemblyExplorer> + <Assembly Path="D:\VintageStory\Lib\0Harmony.dll" /> + <Assembly Path="C:\Users\Den\RiderProjects\GearToLife\TemporalLife.dll" /> +</AssemblyExplorer> \ No newline at end of file diff --git a/GearToLife/GearToLife/GearToLifeModSystem.cs b/GearToLife/GearToLife/GearToLifeModSystem.cs index 90fda9b..f7f4550 100644 --- a/GearToLife/GearToLife/GearToLifeModSystem.cs +++ b/GearToLife/GearToLife/GearToLifeModSystem.cs @@ -1,26 +1,23 @@ -using Vintagestory.API.Client; -using Vintagestory.API.Server; -using Vintagestory.API.Config; +using HarmonyLib; using Vintagestory.API.Common; namespace GearToLife; public class GearToLifeModSystem : ModSystem { - // Called on server and client - // Useful for registering block/entity classes on both sides + private Harmony patcher; + public override void Start(ICoreAPI api) { - Mod.Logger.Notification("Hello from template mod: " + api.Side); + if (!Harmony.HasAnyPatches(Mod.Info.ModID)) + { + patcher = new Harmony(Mod.Info.ModID); + patcher.PatchCategory(Mod.Info.ModID); + } } - - public override void StartServerSide(ICoreServerAPI api) + + public override void Dispose() { - Mod.Logger.Notification("Hello from template mod server side: " + Lang.Get("geartolife:hello")); - } - - public override void StartClientSide(ICoreClientAPI api) - { - Mod.Logger.Notification("Hello from template mod client side: " + Lang.Get("geartolife:hello")); + patcher?.UnpatchAll(Mod.Info.ModID); } } \ No newline at end of file diff --git a/GearToLife/GearToLife/Patches/KnifePatch.cs b/GearToLife/GearToLife/Patches/KnifePatch.cs new file mode 100644 index 0000000..207b82f --- /dev/null +++ b/GearToLife/GearToLife/Patches/KnifePatch.cs @@ -0,0 +1,21 @@ +using HarmonyLib; +using Vintagestory.API.Common; +using Vintagestory.API.Common.Entities; +using Vintagestory.GameContent; + +namespace GearToLife.Patches; + +[HarmonyPatchCategory("geartolife")] +internal static class KnifePatch +{ + [HarmonyPostfix()] + [HarmonyPatch(typeof(ItemKnife), "OnHeldInteractStop")] + public static void AfterBreakingGear(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) + { + if (byEntity.Attributes.GetBool("isInsertGear") && secondsUsed >= 1.95f) + { + // Пример события + byEntity.Ignite(); + } + } +} \ No newline at end of file