Skip to content

Commit

Permalink
Improve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
punchready committed Aug 13, 2022
1 parent cf9240d commit 9358f11
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
4 changes: 2 additions & 2 deletions TShockAPI/Bouncer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ internal void OnTileEdit(object sender, GetDataHandlers.TileEditEventArgs args)
return;
}

// i do not understand the ice tile check enough to be able to modify it, however i do know that it can be used to completely bypass region protection
// this check ensures that build permission is always checked no matter what
// I do not understand the ice tile check enough to be able to modify it, however I do know that it can be used to completely bypass region protection
// This check ensures that build permission is always checked no matter what
if (!args.Player.HasBuildPermission(tileX, tileY))
{
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from build from {0} {1} {2}", args.Player.Name, action, editData);
Expand Down
45 changes: 33 additions & 12 deletions TShockAPI/Handlers/SendTileRectHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ namespace TShockAPI.Handlers
/// </summary>
public class SendTileRectHandler : IPacketHandler<GetDataHandlers.SendTileRectEventArgs>
{
private static readonly Dictionary<ushort, HashSet<ushort>> PlantToGrassMap = new Dictionary<ushort, HashSet<ushort>>
/// <summary>
/// Maps plant tile types to their valid grass ground tiles when using flower boots
/// </summary>
private static readonly Dictionary<ushort, HashSet<ushort>> FlowerBootPlantToGrassMap = new Dictionary<ushort, HashSet<ushort>>
{
{ TileID.Plants, new HashSet<ushort>()
{
Expand All @@ -39,19 +42,27 @@ public class SendTileRectHandler : IPacketHandler<GetDataHandlers.SendTileRectEv
} },
};

private static readonly Dictionary<ushort, HashSet<ushort>> PlantToStyleMap = new Dictionary<ushort, HashSet<ushort>>()
/// <summary>
/// Maps plant tile types to a list of valid styles, which are used to determine the FrameX value of the plant tile
/// See `Player.DoBootsEffect_PlaceFlowersOnTile`
/// </summary>
private static readonly Dictionary<ushort, HashSet<ushort>> FlowerBootPlantToStyleMap = new Dictionary<ushort, HashSet<ushort>>()
{
{ TileID.Plants, new HashSet<ushort>()
{
// The upper line is from a `NextFromList` call
// The lower line is from an additional switch which will add the listed options by adding a random value to a select set of styles
6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24, 27, 30, 33, 36, 39, 42,
22, 23, 25, 26, 28, 29, 31, 32, 34, 35, 37, 38, 40, 41, 43, 44,
} },
{ TileID.HallowedPlants, new HashSet<ushort>()
{
// 5 is intentionally missing here because it is being skipped by vanilla
4, 6,
} },
{ TileID.HallowedPlants2, new HashSet<ushort>()
{
// 5 is intentionally missing here because it is being skipped by vanilla
2, 3, 4, 6, 7,
} },
{ TileID.JunglePlants2, new HashSet<ushort>()
Expand Down Expand Up @@ -199,7 +210,7 @@ internal void IterateTileRect(NetTile[,] tiles, bool[,] processed, GetDataHandle
case TileID.MinecartTrack:
case TileID.ChristmasTree:
{
// allowed changes
// Allowed changes
}
break;
default:
Expand All @@ -222,7 +233,7 @@ internal void IterateTileRect(NetTile[,] tiles, bool[,] processed, GetDataHandle
case TileID.TeleportationPylon:
case TileID.TargetDummy:
{
// allowed placements
// Allowed placements
}
break;
default:
Expand Down Expand Up @@ -263,7 +274,7 @@ internal void IterateTileRect(NetTile[,] tiles, bool[,] processed, GetDataHandle
}
}
}

/// <summary>
/// Processes a tile object consisting of multiple tiles from the tile rect packet
/// </summary>
Expand Down Expand Up @@ -321,24 +332,30 @@ internal void ProcessSingleTile(int realX, int realY, NetTile newTile, byte rect

ITile tile = Main.tile[realX, realY];

// Triggering a single land mine tile
if (rectWidth == 1 && rectLength == 1 && tile.type == TileID.LandMine && !newTile.Active)
{
UpdateServerTileState(tile, newTile, TileDataType.Tile);
}

// Hammering a single junction box
if (rectWidth == 1 && rectLength == 1 && tile.type == TileID.WirePipe)
{
UpdateServerTileState(tile, newTile, TileDataType.Tile);
}

// Mowing a single grass tile: Grass -> GolfGrass OR HallowedGrass -> GolfGrassHallowed
if (rectWidth == 1 && rectLength == 1 &&
(tile.type == TileID.Grass && newTile.Type == TileID.GolfGrass ||
tile.type == TileID.HallowedGrass && newTile.Type == TileID.GolfGrassHallowed))
(
tile.type == TileID.Grass && newTile.Type == TileID.GolfGrass ||
tile.type == TileID.HallowedGrass && newTile.Type == TileID.GolfGrassHallowed
))
{
UpdateServerTileState(tile, newTile, TileDataType.Tile);
}

if (rectWidth == 1 && rectLength == 1) // Conversion only sends a 1x1 rect
// Conversion: only sends a 1x1 rect
if (rectWidth == 1 && rectLength == 1)
{
ProcessConversionSpreads(tile, newTile);
}
Expand All @@ -355,11 +372,15 @@ internal void ProcessSingleTile(int realX, int realY, NetTile newTile, byte rect
internal void ProcessFlowerBoots(int realX, int realY, NetTile newTile)
{
ITile tile = Main.tile[realX, realY];
// Ensure that the placed plant is valid for the grass below, that the target tile is empty, and that the placed plant has valid framing
// Ensure that:
// - the placed plant is valid for the grass below
// - the target tile is empty
// - and the placed plant has valid framing (style * 18 = FrameX)
if (
PlantToGrassMap.TryGetValue(newTile.Type, out HashSet<ushort> grassTiles) &&
!tile.active() && grassTiles.Contains(Main.tile[realX, realY + 1].type) &&
PlantToStyleMap[newTile.Type].Contains((ushort)(newTile.FrameX / 18))
FlowerBootPlantToGrassMap.TryGetValue(newTile.Type, out HashSet<ushort> grassTiles) &&
!tile.active() &&
grassTiles.Contains(Main.tile[realX, realY + 1].type) &&
FlowerBootPlantToStyleMap[newTile.Type].Contains((ushort)(newTile.FrameX / 18))
)
{
UpdateServerTileState(tile, newTile, TileDataType.Tile);
Expand Down

0 comments on commit 9358f11

Please sign in to comment.