From 93ae102eacf812fdccabba79b7978f9965ddfaca Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Sat, 10 Aug 2024 01:37:58 +0900 Subject: [PATCH] Add RecursiveTileBreak --- Core/Config.cs | 6 ++++++ Core/Mitigations.cs | 13 +++++++++++++ Core/Plugin.cs | 2 ++ Core/WorldGen.cs | 11 +++++++++++ 4 files changed, 32 insertions(+) diff --git a/Core/Config.cs b/Core/Config.cs index 59298e1..ca9a050 100644 --- a/Core/Config.cs +++ b/Core/Config.cs @@ -772,6 +772,12 @@ public record class MitigationSettings /// public Optional ReloadILHook = Optional.Default(false); + /// + /// Break tile will be tracked and TileFrame-ed again after the KillTile. + /// This will trigger recursive tile break. + /// + public Optional RecursiveTileBreak = Optional.Default(false, true); + public enum DisabledDamageAction { AsIs, diff --git a/Core/Mitigations.cs b/Core/Mitigations.cs index 0100ffe..a8cef5d 100644 --- a/Core/Mitigations.cs +++ b/Core/Mitigations.cs @@ -324,6 +324,19 @@ private void TAHook_Mitigation_GameUpdate(EventArgs _) } } } + + if (mitigation.RecursiveTileBreak) + { + var kt = 0; + while (kt < this._pendingKilled.Count) + { + var item = this._pendingKilled[kt]; + var ti = (int) (item >> 32); + var tj = (int) item; + Terraria.WorldGen.TileFrame(ti, tj); + kt++; + } + } } private static readonly bool ShouldSuppressTitle = !System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows) diff --git a/Core/Plugin.cs b/Core/Plugin.cs index 9953241..2d9db2c 100644 --- a/Core/Plugin.cs +++ b/Core/Plugin.cs @@ -309,6 +309,7 @@ public override void Initialize() On.Terraria.WorldGen.KillTile_GetItemDrops += this.MMHook_Mitigation_TileDropItem; On.Terraria.Initializers.ChatInitializer.Load += this.MMHook_Mitigation_I18nCommand; On.Terraria.WorldGen.nextCount += this.MMHook_Mitigation_WorldGenNextCount; + On.Terraria.WorldGen.KillTile += this.MMHook_WorldGen_KillTile; OTAPI.Hooks.NetMessage.SendBytes += this.OTHook_Ghost_SendBytes; OTAPI.Hooks.NetMessage.SendBytes += this.OTHook_DebugPacket_SendBytes; OTAPI.Hooks.MessageBuffer.GetData += this.OTHook_Ping_GetData; @@ -352,6 +353,7 @@ protected override void Dispose(bool disposing) On.Terraria.WorldGen.KillTile_GetItemDrops -= this.MMHook_Mitigation_TileDropItem; On.Terraria.Initializers.ChatInitializer.Load -= this.MMHook_Mitigation_I18nCommand; On.Terraria.WorldGen.nextCount -= this.MMHook_Mitigation_WorldGenNextCount; + On.Terraria.WorldGen.KillTile -= this.MMHook_WorldGen_KillTile; OTAPI.Hooks.NetMessage.SendBytes -= this.OTHook_Ghost_SendBytes; OTAPI.Hooks.NetMessage.SendBytes -= this.OTHook_DebugPacket_SendBytes; OTAPI.Hooks.MessageBuffer.GetData -= this.OTHook_Mitigation_GetData; diff --git a/Core/WorldGen.cs b/Core/WorldGen.cs index 080c211..3d46d71 100644 --- a/Core/WorldGen.cs +++ b/Core/WorldGen.cs @@ -143,4 +143,15 @@ private void Detour_InspectTileFrame(Action orig, int i, i orig(i, j, resetFrame, noBreak); this._frameCount.Value -= 1; } + + private readonly List _pendingKilled = new List(); + private void MMHook_WorldGen_KillTile(On.Terraria.WorldGen.orig_KillTile orig, int i, int j, bool fail, bool effectOnly, bool noItem) + { + var pos = (((ulong) i) << 32) | ((uint) j); + if (this.config.Mitigation.Value.RecursiveTileBreak.Value && !this._pendingKilled.Contains(pos)) + { + this._pendingKilled.Add(pos); + } + orig(i, j, fail, effectOnly, noItem); + } } \ No newline at end of file