-
-
Notifications
You must be signed in to change notification settings - Fork 921
Modify itemstack directly instead of spawning a new one #5212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR modifies the block drop item handling in mcMMO to directly modify existing ItemStack objects instead of spawning separate new ones for bonus drops. This addresses a server issue where items spawned by mcMMO double drops couldn't be modified by other plugins.
- Changes bonus drop mechanics to modify the original ItemStack amount instead of spawning individual duplicate items
- Introduces a new McMMOItemSpawnEvent to allow other plugins to intercept and modify the spawning behavior
- Optimizes metadata checking by using isEmpty() instead of size() comparison
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| ItemStack copy = is.clone(); | ||
| copy.setAmount(newAmount); | ||
|
|
||
| final McMMOItemSpawnEvent spawnEvent = new McMMOItemSpawnEvent(centeredLocation, | ||
| copy, ItemSpawnReason.BONUS_DROPS, event.getPlayer()); | ||
| mcMMO.p.getServer().getPluginManager().callEvent(spawnEvent); | ||
|
|
||
| if (!spawnEvent.isCancelled()) { | ||
| is.setAmount(newAmount); |
Copilot
AI
Aug 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a logical inconsistency in the event handling. The McMMOItemSpawnEvent is fired with a copy of the ItemStack, but if the event is not cancelled, the original is ItemStack is modified. This means other plugins listening to the event cannot actually modify the final ItemStack that gets used, as their changes to copy are ignored.
| ItemStack copy = is.clone(); | |
| copy.setAmount(newAmount); | |
| final McMMOItemSpawnEvent spawnEvent = new McMMOItemSpawnEvent(centeredLocation, | |
| copy, ItemSpawnReason.BONUS_DROPS, event.getPlayer()); | |
| mcMMO.p.getServer().getPluginManager().callEvent(spawnEvent); | |
| if (!spawnEvent.isCancelled()) { | |
| is.setAmount(newAmount); | |
| ItemStack eventStack = spawnEvent.getItemStack(); | |
| is.setType(eventStack.getType()); | |
| is.setAmount(eventStack.getAmount()); | |
| is.setItemMeta(eventStack.getItemMeta()); |
|
@nossr50 Hi, I’d like to point out an issue related to the way Currently, the event is registered with priority HIGHEST, and the treasure logic depends on the list of block drops being intact. This creates a problem for other plugins that also need to modify or even clear items from that list. For example, an auto-pickup plugin uses the same event to check whether the player can collect the drops, and if allowed, removes the items from the drop list. When this happens, mcMMO is no longer able to generate treasures, since it depends on those drops still being present in the list. In practice, this means mcMMO is preventing other plugins from safely altering the drop list without breaking treasure generation. It might be better if mcMMO could either:
This would make mcMMO more compatible with auto-pickup and similar plugins. |
| ItemStack copy = is.clone(); | ||
| copy.setAmount(newAmount); | ||
|
|
||
| final McMMOItemSpawnEvent spawnEvent = new McMMOItemSpawnEvent(centeredLocation, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it makes sense for this event to fire if all we are doing is modifying the amount of the itemStack in this event. Instead, maybe we need a new event, something like McMMOAddBonusDrops, and it shows the items, the number of items that will be added and is cancellable. If it goes uncancelled, or modified, the result affects the outcome of this listener.
I see the problem, we shouuld probably adjust priority to Lowest, change the event to reporting mcMMO adding item quantity, and that would satisfy the requirements. EDIT: I just thought about it more, LOWEST is probably not appropriate, we probably should just stick with NORMAL or LOW. |
|
feel free to tag me in discord if you want to discuss or ask questions |
|
Haven't heard from you in a while, I will probably impl a fix myself, thanks for putting up a PR though 👍 |
Ran into an issue on my server where I couldn't modify items spawned by mcMMO double drops