Skip to content

Commit

Permalink
Add RecursiveTileBreak
Browse files Browse the repository at this point in the history
  • Loading branch information
sgkoishi committed Aug 9, 2024
1 parent 870cb67 commit 93ae102
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Core/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,12 @@ public record class MitigationSettings
/// </summary>
public Optional<bool> ReloadILHook = Optional.Default(false);

/// <summary>
/// Break tile will be tracked and TileFrame-ed again after the KillTile.
/// This will trigger recursive tile break.
/// </summary>
public Optional<bool> RecursiveTileBreak = Optional.Default(false, true);

public enum DisabledDamageAction
{
AsIs,
Expand Down
13 changes: 13 additions & 0 deletions Core/Mitigations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Core/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions Core/WorldGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,15 @@ private void Detour_InspectTileFrame(Action<int, int, bool, bool> orig, int i, i
orig(i, j, resetFrame, noBreak);
this._frameCount.Value -= 1;
}

private readonly List<ulong> _pendingKilled = new List<ulong>();
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);
}
}

0 comments on commit 93ae102

Please sign in to comment.