Skip to content

Conversation

@GriffinCodes
Copy link
Contributor

Ran into an issue on my server where I couldn't modify items spawned by mcMMO double drops

@nossr50 nossr50 requested review from Copilot and nossr50 August 24, 2025 18:28
Copy link

Copilot AI left a 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.

Comment on lines +146 to +154
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);
Copy link

Copilot AI Aug 24, 2025

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.

Suggested change
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());

Copilot uses AI. Check for mistakes.
@SrBedrock
Copy link
Contributor

@nossr50 Hi, I’d like to point out an issue related to the way mcMMO handles treasure generation using the BlockDropItemEvent.

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:

  • use a lower event priority, or
  • decouple treasure generation from the actual drop list state, so that plugins modifying or removing drops don’t unintentionally block treasure generation.

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,
Copy link
Member

@nossr50 nossr50 Aug 24, 2025

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.

@nossr50
Copy link
Member

nossr50 commented Aug 24, 2025

@nossr50 Hi, I’d like to point out an issue related to the way mcMMO handles treasure generation using the BlockDropItemEvent.

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:

  • use a lower event priority, or
  • decouple treasure generation from the actual drop list state, so that plugins modifying or removing drops don’t unintentionally block treasure generation.

This would make mcMMO more compatible with auto-pickup and similar plugins.

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.

@nossr50
Copy link
Member

nossr50 commented Aug 24, 2025

feel free to tag me in discord if you want to discuss or ask questions

@nossr50
Copy link
Member

nossr50 commented Sep 21, 2025

Haven't heard from you in a while, I will probably impl a fix myself, thanks for putting up a PR though 👍

@nossr50 nossr50 closed this Sep 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants