Repository navigation
feat(script): fire playerCraftRecipe when a grid recipe is crafted - #387
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
world.afterEvents.playerCraftRecipewas bound but never fired. It now fires after a player crafts a recipe on the crafting grid (the 2x2 inventory grid or a crafting table), with the documented fields:player— the crafteritemStack— the crafted item (the recipe's output stack)block— the crafting table when one is open, leftundefinedfor the 2x2 inventory gridPlayerCraftRecipeEventOptionsfiltering is honored:playerFilter(EntityFilter),itemFilter(ItemFilter.includeTypes against the crafted item), andblockFilter(BlockFilter include/exclude types, tags and permutations) applied when the event carries a block.How it was done / checked
ItemStackRequestHandler::executealready runs the request on a working copy and commits only on success. It now reports the crafted recipe output through a new out-param, set in the grid-recipe path (craftRecipe) once the request validates — so the event only fires for a real, committed craft, after the request holds, like the other after-events.InventoryManager, which already tracks the open table's position.@minecraft/server2.12.0-beta.1.26.60.d.ts:PlayerCraftRecipeAfterEvent= { block?, itemStack?, player }, andPlayerCraftRecipeEventOptions= { blockFilter, itemFilter, playerFilter }. In the 26.60 client the event is raised from the vanilla crafting-container completion through the player event coordinator.playerCraftRecipefor the stonecutter, so I did not fire it there rather than guess.itemStackis the recipe's declared output stack (not multiplied by the requested craft count): the count the game reports for a bulk/shift craft is the one value I could not pin down in the binary, so the reported stack is the recipe output as loaded, which is a known value rather than a guess.Test:
player-craft-recipedrives a real one-ingredient shapeless recipe throughexecuteand checks the crafted item reported to scripts is the recipe output with its count, and that a request crafting nothing reports no item.Not built locally (syntax-checked with
clang++ -fsyntax-only); CI runs on the branch.In-game test plan: subscribe to
world.afterEvents.playerCraftRecipe; craft in the 2x2 grid (expect the event withblockundefined) and at a crafting table (expectblock= the table); checkitemStack.typeIdand thatplayerFilter/itemFilter/blockFilternarrow the callbacks.AI disclosure
Code, research in the game binary and this description: Claude Opus 4.8 (
claude-opus-4-8).