Repository navigation
Apply MerchantRecipe ingredient changes to the live offer immediately (#10708) - #14111
gunjanjaswal wants to merge 2 commits into
Conversation
CraftMerchantRecipe's scalar setters (uses, demand, experience, etc.) write straight through to the NMS MerchantOffer, but the ingredient methods were inherited unchanged from the API MerchantRecipe and only touched the base list. The handle's baseCostA/costB were rebuilt solely inside toMinecraft(), which runs on trade refresh, so setIngredients(...) did not take effect until the trade screen was rebuilt while setExperienceReward(...) applied instantly. Override addIngredient, removeIngredient and setIngredients to sync the ingredient list to the handle right away, extracting the cost-rebuild logic into a shared helper that toMinecraft() reuses. The helper skips the sync while the ingredient list is transiently empty so removing all ingredients does not build an invalid offer.
| // Paper end | ||
|
|
||
| public net.minecraft.world.item.trading.MerchantOffer toMinecraft() { | ||
| // Paper start - write ingredient changes straight through to the handle, |
There was a problem hiding this comment.
We don't need Paper start/end comments for files that aren't rebuilt as patches. Comments explaining what is happening is fine, just don't need the Paper start part
This craftbukkit file isn't rebuilt as a patch, so the // Paper start/end markers aren't needed. Keep the explanatory comment, drop the markers.
|
Good call — dropped the |
|
Gentle bump, @Machine-Maker. I addressed the change requests a while back (applying the MerchantRecipe ingredient changes to the live offer), and it's still mergeable. Whenever you have a moment for a re-review, it's ready. |
|
Thanks @Machine-Maker — I dropped the |
|
@Machine-Maker gentle nudge for a re-review when you get a chance. I dropped the Paper start/end markers on the non-patch file as you asked back in August (7403a85), keeping the explanatory comment without the Paper marker part. Should be ready for another pass. |
Closes #10708.
CraftMerchantRecipe's scalar setters (setUses,setDemand,setExperienceReward,setSpecialPrice, and so on) write straight through to the backing NMSMerchantOffer, so they take effect the moment you call them. The ingredient methods did not:addIngredient,removeIngredient, andsetIngredientswere inherited unchanged from the API'sMerchantRecipeand only touched the base list. The handle'sbaseCostA/costBwere rebuilt exclusively insidetoMinecraft(), which runs on trade refresh, sosetExperienceReward(true)applied instantly whilesetIngredients(...)only landed once the trade screen rebuilt.The issue asks to make this consistent one way or another. This picks write-through, since it matches the eight existing scalar setters and the fact that
getRecipe()hands back a live-backed wrapper. Ingredient changes now sync to the handle immediately; ingredient-agnostic behavior is unchanged.addIngredient,removeIngredient,setIngredientsto sync after the base mutation.syncIngredientsToHandle()helper thattoMinecraft()reuses (no logic change).toMinecraft()keeps its existing "No offered ingredients" check.Heads-up for review: I could not compile this locally (Paper's
paper-serverneeds a JDK 25 paperweight build with decompiled Mojang sources, which I can't run here), so it is verified by code review rather than a local build. The change is confined to one CraftBukkit class. A CI build and an in-game smoke check on a villager trade would confirm it.