[SPIGOT-6890] Add a way to specify the amount of sacrifice Items used in the Anvil Created: 06/Jan/22  Updated: 25/Jan/22  Resolved: 25/Jan/22

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: Kilian Nixda Assignee: Doc
Resolution: Fixed Votes: 0
Labels: event, spigot

Version: 1.18.1-R0.1-SNAPSHOT
Guidelines Read: Yes

 Description   

If you modify a PrepareAnvilEvent, you can currently specify a new result for the given input and modify the state of the AnvilInventory.

But if you want to add a recipe, which uses a stack with size > 1 in the sacrifice slot (like f.ex. a new repair recipe), the recipe will simply remove the entire stack when taking out the result.

 

I have searched multiple Forums for a more elegant solution (more elegant than stressing the server with an additional item stack being thrown out of the anvil) for this issue, but i havent found one. I therefore would propose to add a modifiable integer value usedSacrificeAmount to the PrepareAnvilEvent (or maybe the AnvilInventory) along with all relevant methods, which would specify the maximum amount of items taken from the stack in the sacrifice slot. If sacrifice.getAmount() <= usedSacrificeAmount, the stack would be removed. The value should be initialized to the proper vanilla value (f.ex. 4 if a nearly depleted diamond pick is repaired with diamonds or 1 if it is repaired/enchanted with another diamond pick). If there is no vanilla result, the value would be 0.

 

Thank you for all the work you have put into this API and sorry for my bad english. (I'm german)



 Comments   
Comment by Doc [ 22/Jan/22 ]

Based in the comment about "repairItemCountCost" i make the PR for expose this.

 

https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/pull-requests/715/overview

https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/pull-requests/998/overview

Comment by Kilian Nixda [ 21/Jan/22 ]

Ok I digged a bit deeper into the undelying code and it seems it would be enough to expose 

repairItemCountCost from AnvilMenu to AnvilInventory.

Generated at Sun Mar 30 02:32:24 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.