From 3012c923706d271110fdf8787a522a80f526714f Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Thu, 18 Jun 2020 16:48:22 +0200 Subject: [PATCH] GetDataHandlers - Add RequestTileEntityInteraction hook. --- TShockAPI/GetDataHandlers.cs | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index d0024e51..3276d86d 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -152,6 +152,7 @@ namespace TShockAPI { PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 }, { PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 }, { PacketTypes.Emoji, HandleEmoji }, + { PacketTypes.RequestTileEntityInteraction, HandleRequestTileEntityInteraction }, { PacketTypes.SyncTilePicking, HandleSyncTilePicking }, { PacketTypes.SyncRevengeMarker, HandleSyncRevengeMarker }, { PacketTypes.LandGolfBallInCup, HandleLandGolfBallInCup }, @@ -1903,6 +1904,39 @@ namespace TShockAPI return args.Handled; } + /// For use in an OnRequestTileEntityInteraction event. + /// + public class RequestTileEntityInteractionEventArgs : GetDataHandledEventArgs + { + /// + /// The ID of the TileEntity that the player is requesting interaction with. + /// + public int TileEntityID { get; set; } + /// + /// The player index in the packet who requests interaction with the TileEntity. + /// + public byte PlayerIndex { get; set; } + } + /// + /// Called when a player requests interaction with a TileEntity. + /// + public static HandlerList RequestTileEntityInteraction = new HandlerList(); + private static bool OnRequestTileEntityInteraction(TSPlayer player, MemoryStream data, int tileEntityID, byte playerIndex) + { + if (RequestTileEntityInteraction == null) + return false; + + var args = new RequestTileEntityInteractionEventArgs + { + Player = player, + Data = data, + PlayerIndex = playerIndex, + TileEntityID = tileEntityID + }; + RequestTileEntityInteraction.Invoke(null, args); + return args.Handled; + } + /// /// For use in a SyncTilePicking event. /// @@ -3702,6 +3736,17 @@ namespace TShockAPI return false; } + private static bool HandleRequestTileEntityInteraction(GetDataHandlerArgs args) + { + int tileEntityID = args.Data.ReadInt32(); + byte playerIndex = args.Data.ReadInt8(); + + if (OnRequestTileEntityInteraction(args.Player, args.Data, tileEntityID, playerIndex)) + return true; + + return false; + } + private static bool HandleSyncTilePicking(GetDataHandlerArgs args) { byte playerIndex = args.Data.ReadInt8();