Skip to content

Commit

Permalink
RecursiveTileBreak should work now.
Browse files Browse the repository at this point in the history
Not fully synced to the client but should be fine
  • Loading branch information
sgkoishi committed Aug 10, 2024
1 parent 2118496 commit 121c505
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
6 changes: 0 additions & 6 deletions Core/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -778,12 +778,6 @@ public record class MitigationSettings
/// </summary>
public Optional<bool> RecursiveTileBreak = Optional.Default(false, true);

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

public enum DisabledDamageAction
{
AsIs,
Expand Down
9 changes: 4 additions & 5 deletions Core/Mitigations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,17 @@ private void TAHook_Mitigation_GameUpdate(EventArgs _)
if (mitigation.RecursiveTileBreak)
{
var kt = 0;
var count = this._pendingKilled.Count;
while (kt < this._pendingKilled.Count)
var count = this._pendingTileFrame.Count;
while (kt < this._pendingTileFrame.Count)
{
var item = this._pendingKilled[kt];
var item = this._pendingTileFrame[kt];
var ti = (int) (item >> 32);
var tj = (int) item;
Terraria.WorldGen.SquareTileFrame(ti, tj);
kt++;
}

this.Statistics.MitigationNewTileKillTriggered += this._pendingKilled.Count - count;
this._pendingKilled.Clear();
this.Statistics.MitigationNewTileKillTriggered += this._pendingTileFrame.Count - count;
this._pendingTileFrame.Clear();
}
}
Expand Down
19 changes: 7 additions & 12 deletions Core/WorldGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,30 +144,25 @@ private void Detour_InspectTileFrame(Action<int, int, bool, bool> orig, int i, i
this._frameCount.Value -= 1;
}

private readonly List<ulong> _pendingKilled = new List<ulong>();
private readonly List<ulong> _pendingTileFrame = 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))
if (this.config.Mitigation.Value.RecursiveTileBreak.Value && !this._pendingTileFrame.Contains(pos))
{
this._pendingKilled.Add(pos);
this. _pendingTileFrame.Add(pos);
}
orig(i, j, fail, effectOnly, noItem);
}

private readonly Dictionary<ulong, int> _pendingTileFrame = new Dictionary<ulong, int>();
private void MMHook_WorldGen_TileFrame(On.Terraria.WorldGen.orig_TileFrame orig, int i, int j, bool resetFrame, bool noBreak)
{
var pos = (((ulong) i) << 32) | ((uint) j);
if (this.config.Mitigation.Value.RecursiveTileFrame.Value)
var type = Terraria.Main.tile[i, j].type;
orig.Invoke(i, j, resetFrame, noBreak);
if (type != Terraria.Main.tile[i, j].type && this.config.Mitigation.Value.RecursiveTileBreak.Value && !this._pendingTileFrame.Contains(pos))
{
if (this._pendingTileFrame.TryGetValue(pos, out var frames) && frames > 2)
{
return;
}
this._pendingTileFrame[pos] = frames + 1;
Terraria.WorldGen.destroyObject = false;
orig(i, j, resetFrame, noBreak);
this._pendingTileFrame.Add(pos);
}
}
}

0 comments on commit 121c505

Please sign in to comment.