diff --git a/.github/workflows/test b/.github/workflows/test deleted file mode 100644 index 8b137891..00000000 --- a/.github/workflows/test +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/serenity/src/handlers/inventory-transaction.ts b/packages/serenity/src/handlers/inventory-transaction.ts index 2f93c11c..e2d900b9 100644 --- a/packages/serenity/src/handlers/inventory-transaction.ts +++ b/packages/serenity/src/handlers/inventory-transaction.ts @@ -7,7 +7,8 @@ import { Vector3f, type ItemUseInventoryTransaction, Gamemode, - type ItemUseOnEntityInventoryTransaction + type ItemUseOnEntityInventoryTransaction, + type ItemReleaseInventoryTransaction } from "@serenityjs/protocol"; import { ItemUseCause, type Player } from "@serenityjs/world"; import { BlockIdentifier, BlockPermutation } from "@serenityjs/block"; @@ -64,6 +65,18 @@ class InventoryTransaction extends SerenityHandler { this.handleItemUseOnEntityTransaction(itemUse, player); break; } + + case ComplexInventoryTransaction.ItemReleaseTransaction: { + // Get the itemRelease object from the transaction + const itemRelease = packet.transaction.itemRelease; + + // Check if the itemRelease object is valid, if not throw an error that the itemRelease object is missing. + if (!itemRelease) throw new Error("ItemRelease object is missing."); + + // Handle the itemRelease transaction + this.handleItemReleaseTransaction(itemRelease, player); + break; + } } } @@ -193,6 +206,11 @@ class InventoryTransaction extends SerenityHandler { // Set the player's using item player.usingItem = usingItem; + // Trigger the onStartUse method of the item components + for (const component of usingItem.components.values()) { + component.onStartUse?.(player, ItemUseCause.Use); + } + // Break the switch statement break; } @@ -234,6 +252,25 @@ class InventoryTransaction extends SerenityHandler { component.onInteract?.(player, transaction.type); } } + + public static handleItemReleaseTransaction( + transaction: ItemReleaseInventoryTransaction, + player: Player + ): void { + // Get the using item of the player + const usingItem = player.usingItem; + + // Check if the using item is valid + if (!usingItem) return; + + // Trigger the onRelease method of the item components + for (const component of usingItem.components.values()) { + component.onStopUse?.(player, ItemUseCause.Use); + } + + // Set the player's using item to null + player.usingItem = null; + } } export { InventoryTransaction };