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
|
|
@ -26,6 +26,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
|
||||||
* Cleaned up a check in Bouner OnTileEdit where it checks for using the respective item when placing a tile to make it clearer. This change also fixed the issue in a previous commit where valid replace action was caught. Moved the check for max tile/wall types to the beginning of the method. (@Patrikkk)
|
* Cleaned up a check in Bouner OnTileEdit where it checks for using the respective item when placing a tile to make it clearer. This change also fixed the issue in a previous commit where valid replace action was caught. Moved the check for max tile/wall types to the beginning of the method. (@Patrikkk)
|
||||||
* Improved clarity for insufficient permission related error messages. (@moisterrific)
|
* Improved clarity for insufficient permission related error messages. (@moisterrific)
|
||||||
* Remove redundant Boulder placement check that prevented placing chests on them, as it is no longer possible to place a chest on a boulder, so nothing crashes the server. "1.2.3: Boulders with Chests on them no longer crash the game if the boulder is hit." (@kevzhao2, @Patrikkk)
|
* Remove redundant Boulder placement check that prevented placing chests on them, as it is no longer possible to place a chest on a boulder, so nothing crashes the server. "1.2.3: Boulders with Chests on them no longer crash the game if the boulder is hit." (@kevzhao2, @Patrikkk)
|
||||||
|
* Adding DisplayDollItemSync event. An event that is called when a player modifies the slot of a DisplayDoll (Mannequin). This event provides information about the current item in the displaydoll, as well as the item that the player is about to set. (@Patrikkk)
|
||||||
|
|
||||||
## TShock 4.4.0 (Pre-release 11)
|
## TShock 4.4.0 (Pre-release 11)
|
||||||
* New permission `tshock.tp.pylon` to enable teleporting via Teleportation Pylons (@QuiCM)
|
* New permission `tshock.tp.pylon` to enable teleporting via Teleportation Pylons (@QuiCM)
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,7 @@ namespace TShockAPI
|
||||||
{ PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 },
|
{ PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 },
|
||||||
{ PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 },
|
{ PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 },
|
||||||
{ PacketTypes.Emoji, HandleEmoji },
|
{ PacketTypes.Emoji, HandleEmoji },
|
||||||
|
{ PacketTypes.TileEntityDisplayDollItemSync, HandleTileEntityDisplayDollItemSync },
|
||||||
{ PacketTypes.SyncTilePicking, HandleSyncTilePicking },
|
{ PacketTypes.SyncTilePicking, HandleSyncTilePicking },
|
||||||
{ PacketTypes.SyncRevengeMarker, HandleSyncRevengeMarker },
|
{ PacketTypes.SyncRevengeMarker, HandleSyncRevengeMarker },
|
||||||
{ PacketTypes.LandGolfBallInCup, HandleLandGolfBallInCup },
|
{ PacketTypes.LandGolfBallInCup, HandleLandGolfBallInCup },
|
||||||
|
|
@ -1945,7 +1946,60 @@ namespace TShockAPI
|
||||||
Emoji.Invoke(null, args);
|
Emoji.Invoke(null, args);
|
||||||
return args.Handled;
|
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>
|
/// <summary>
|
||||||
/// For use in a LandBallInCup event.
|
/// For use in a LandBallInCup event.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -3703,6 +3757,49 @@ namespace TShockAPI
|
||||||
return false;
|
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)
|
private static bool HandleSyncTilePicking(GetDataHandlerArgs args)
|
||||||
{
|
{
|
||||||
byte playerIndex = args.Data.ReadInt8();
|
byte playerIndex = args.Data.ReadInt8();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue