PaperMC / Paper

The most widely used, high performance Minecraft server that aims to fix gameplay and mechanics inconsistencies
https://papermc.io/
Other
9.34k stars 2.2k forks source link

Mutating the list returned by getDrops() in PlayerShearBlockEvent has no effect #10955

Closed TothAdam0012 closed 1 week ago

TothAdam0012 commented 1 week ago

Expected behavior

Since clearing the drop list results in no item drops, mutating the list should also change the items dropped by the event.

Observed/Actual behavior

Changing the contents of the list has no effect (the list is probably a copy?) the same items are dropped that would drop otherwise.

Steps/models to reproduce

register the following event handler

    public void onPlayerShearBlock(PlayerShearBlockEvent e) {
        e.getDrops().clear();
        e.getDrops().add(new ItemStack(Material.DIAMOND));
    }

This should make it so for example carving a pumpkin drops a diamond but it still only drops the pumpkin seeds. If I change the code to just:

    public void onPlayerShearBlock(PlayerShearBlockEvent e) {
        e.getDrops().clear();
    }

then no item is dropped, as expected.

Plugin and Datapack List

Empty/only test plugin

Paper version

[14:39:26 INFO]: Checking version, please wait...
[14:39:26 INFO]: This server is running Paper version 1.21-25-master@19105a9 (2024-06-21T19:03:48Z) (Implementing API version 1.21-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21-9-4ea696f (MC: 1.21)

Other

We either should be able to mutate the drop list, or there should be a setDrops method.

electronicboy commented 1 week ago

https://github.com/PaperMC/Paper/commit/2d9d0d8b1dcf64e8790b17119b7480361d5f33e3#diff-32f29d79533d2521c86a9d2b04509df00e48ed03f7a7e9c98c5a8c111df55d1aL67