Adding DisplayDollItemSync event.
An event that is called when a player modifies the slot of a DisplayDoll (Mannequin). I was trying to think from a developer friendly perspective here. Instead of passing seperate variables for type/stack/prefix, thought I pass an Item object. As well as, instead of having devs who work with this hook figure out and implement how to get the Item of the DisplayDoll, I just provide it in the hook. I can imagine this being used for creative purposes in plugins.
This commit is contained in:
parent
1807488f2f
commit
69f232b12a
2 changed files with 99 additions and 1 deletions
|
|
@ -152,6 +152,7 @@ namespace TShockAPI
|
|||
{ PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 },
|
||||
{ PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 },
|
||||
{ PacketTypes.Emoji, HandleEmoji },
|
||||
{ PacketTypes.TileEntityDisplayDollItemSync, HandleTileEntityDisplayDollItemSync },
|
||||
{ PacketTypes.SyncTilePicking, HandleSyncTilePicking },
|
||||
{ PacketTypes.SyncRevengeMarker, HandleSyncRevengeMarker },
|
||||
{ PacketTypes.LandGolfBallInCup, HandleLandGolfBallInCup },
|
||||
|
|
@ -1945,7 +1946,60 @@ namespace TShockAPI
|
|||
Emoji.Invoke(null, args);
|
||||
return args.Handled;
|
||||
}
|
||||
|
||||
|
||||
/// For use in a TileEntityDisplayDollItemSync event.
|
||||
/// </summary>
|
||||
public class DisplayDollItemSyncEventArgs : GetDataHandledEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The player index in the packet who modifies the DisplayDoll item slot.
|
||||
/// </summary>
|
||||
public byte PlayerIndex { get; set; }
|
||||
/// <summary>
|
||||
/// The ID of the TileEntity that is being modified.
|
||||
/// </summary>
|
||||
public int TileEntityID { get; set; }
|
||||
/// <summary>
|
||||
/// The slot of the DisplayDoll that is being modified.
|
||||
/// </summary>
|
||||
public int Slot { get; set; }
|
||||
/// <summary>
|
||||
/// Wether or not the slot that is being modified is a Dye slot.
|
||||
/// </summary>
|
||||
public bool IsDye { get; set; }
|
||||
/// <summary>
|
||||
/// The current item that is present in the slot before the modification.
|
||||
/// </summary>
|
||||
public Item OldItem { get; set; }
|
||||
/// <summary>
|
||||
/// The item that is about to replace the OldItem in the slot that is being modified.
|
||||
/// </summary>
|
||||
public Item NewItem { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Called when a player modifies a DisplayDoll (Mannequin) item slot.
|
||||
/// </summary>
|
||||
public static HandlerList<DisplayDollItemSyncEventArgs> DisplayDollItemSync = new HandlerList<DisplayDollItemSyncEventArgs>();
|
||||
private static bool OnDisplayDollItemSync(TSPlayer player, MemoryStream data, byte playerIndex, int tileEntityID, int slot, bool isDye, Item oldItem, Item newItem)
|
||||
{
|
||||
if (DisplayDollItemSync == null)
|
||||
return false;
|
||||
|
||||
var args = new DisplayDollItemSyncEventArgs
|
||||
{
|
||||
Player = player,
|
||||
Data = data,
|
||||
PlayerIndex = playerIndex,
|
||||
TileEntityID = tileEntityID,
|
||||
Slot = slot,
|
||||
IsDye = isDye,
|
||||
OldItem = oldItem,
|
||||
NewItem = newItem
|
||||
};
|
||||
DisplayDollItemSync.Invoke(null, args);
|
||||
return args.Handled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For use in a LandBallInCup event.
|
||||
/// </summary>
|
||||
|
|
@ -3703,6 +3757,49 @@ namespace TShockAPI
|
|||
return false;
|
||||
}
|
||||
|
||||
private static bool HandleTileEntityDisplayDollItemSync(GetDataHandlerArgs args)
|
||||
{
|
||||
byte playerIndex = args.Data.ReadInt8();
|
||||
int tileEntityID = args.Data.ReadInt32();
|
||||
int slot = args.Data.ReadByte();
|
||||
bool isDye = false;
|
||||
if (slot >= 8)
|
||||
{
|
||||
isDye = true;
|
||||
slot -= 8;
|
||||
}
|
||||
|
||||
Item newItem = new Item();
|
||||
Item oldItem = new Item();
|
||||
|
||||
if (!TileEntity.ByID.TryGetValue(tileEntityID, out TileEntity tileEntity))
|
||||
return false;
|
||||
|
||||
TEDisplayDoll displayDoll = tileEntity as TEDisplayDoll;
|
||||
if (displayDoll != null)
|
||||
{
|
||||
oldItem = displayDoll._items[slot];
|
||||
if (isDye)
|
||||
oldItem = displayDoll._dyes[slot];
|
||||
|
||||
ushort itemType = args.Data.ReadUInt16();
|
||||
ushort stack = args.Data.ReadUInt16();
|
||||
int prefix = args.Data.ReadByte();
|
||||
|
||||
newItem.SetDefaults(itemType);
|
||||
newItem.stack = stack;
|
||||
newItem.Prefix(prefix);
|
||||
|
||||
if (oldItem.type == 0 && newItem.type == 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OnDisplayDollItemSync(args.Player, args.Data, playerIndex, tileEntityID, slot, isDye, oldItem, newItem))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool HandleSyncTilePicking(GetDataHandlerArgs args)
|
||||
{
|
||||
byte playerIndex = args.Data.ReadInt8();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue