Skip to content

Commit

Permalink
Exclude unused fields, allow tileMoss, SandSpray and SnowSpray
Browse files Browse the repository at this point in the history
  • Loading branch information
sgkoishi committed Dec 10, 2022
1 parent d2037a6 commit 656a6a4
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions TShockAPI/Handlers/SendTileRectHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,18 @@ internal void ProcessFlowerBoots(int realX, int realY, NetTile newTile)
}
}

private static List<bool[]> _convertibleTiles = typeof(TileID.Sets.Conversion).GetFields().Select(f => (bool[])f.GetValue(null)).ToList();
private static List<bool[]> _convertibleWalls = typeof(WallID.Sets.Conversion).GetFields().Select(f => (bool[])f.GetValue(null)).ToList();
// Moss and MossBrick are not used in conversion
private static List<bool[]> _convertibleTiles = typeof(TileID.Sets.Conversion)
.GetFields()
.ExceptBy(new[] { nameof(TileID.Sets.Conversion.Moss), nameof(TileID.Sets.Conversion.MossBrick) }, f => f.Name)
.Select(f => (bool[])f.GetValue(null))
.ToList();
// PureSand is only used in WorldGen.SpreadDesertWalls, which is server side
private static List<bool[]> _convertibleWalls = typeof(WallID.Sets.Conversion)
.GetFields()
.ExceptBy(new[] { nameof(WallID.Sets.Conversion.PureSand) }, f => f.Name)
.Select(f => (bool[])f.GetValue(null))
.ToList();

/// <summary>
/// Updates a single tile on the server if it is a valid conversion from one tile or wall type to another (eg stone -> corrupt stone)
Expand All @@ -400,22 +410,42 @@ internal void ProcessFlowerBoots(int realX, int realY, NetTile newTile)
/// <param name="newTile">The NetTile containing new tile properties</param>
internal void ProcessConversionSpreads(ITile tile, NetTile newTile)
{
// Update if the existing tile or wall is convertible and the new tile or wall is a valid conversion
foreach (var tileType in _convertibleTiles)
var allowTile = false;
if (Main.tileMoss[tile.type] && TileID.Sets.Conversion.Stone[newTile.Type])
{
if (tileType[tile.type] && tileType[newTile.Type])
allowTile = true;
}
else if ((Main.tileMoss[tile.type] || TileID.Sets.Conversion.Stone[tile.type] || TileID.Sets.Conversion.Ice[tile.type] || TileID.Sets.Conversion.Sandstone[tile.type]) &&
(newTile.Type == TileID.Sandstone || newTile.Type == TileID.IceBlock))
{
// ProjectileID.SandSpray and ProjectileID.SnowSpray
allowTile = true;
}
else
{
foreach (var tileType in _convertibleTiles)
{
TShock.Log.ConsoleDebug(GetString($"Bouncer / SendTileRect processing a tile conversion update - [{tile.type}] -> [{newTile.Type}]"));
UpdateServerTileState(tile, newTile, TileDataType.Tile);
if (tileType[tile.type] && tileType[newTile.Type])
{
allowTile = true;
break;
}
}
}

if (allowTile)
{
TShock.Log.ConsoleDebug(GetString($"Bouncer / SendTileRect processing a tile conversion update - [{tile.type}] -> [{newTile.Type}]"));
UpdateServerTileState(tile, newTile, TileDataType.Tile);
}

foreach (var wallType in _convertibleWalls)
{
if (wallType[tile.wall] && wallType[newTile.Wall])
{
TShock.Log.ConsoleDebug(GetString($"Bouncer / SendTileRect processing a wall conversion update - [{tile.wall}] -> [{newTile.Wall}]"));
UpdateServerTileState(tile, newTile, TileDataType.Wall);
break;
}
}
}
Expand Down

0 comments on commit 656a6a4

Please sign in to comment.