[SPIGOT-7960] World.dropItemNaturally drops items at the wrong postion Created: 19/Nov/24 Updated: 25/Dec/24 Resolved: 20/Nov/24 |
|
Status: | Resolved |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Minor |
Reporter: | Brokkonaut | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 0 |
Labels: | None |
Version: | 1.21.3 |
Guidelines Read: | Yes |
Description |
World.dropItemNaturally does not drop the item at a random position around the given location, but around the location + (0.5,0.5,0.5). This is quite unexpected behavior and when for example using the function to drop items at the players location the item will always be offset in positive direction and possibly be glitched into nearby walls.
Also CraftBukkit itself does not expect that offset, in CraftAbstractInventoryView it tries to drop items at the players location but this will also get offset.
For a fix I would suggest to remove that offset, so plugins are responsible for offsetting the location or, if it should stay like this, at least document it that the item is dropped around location + (0.5,0.5,0.5) and not around the given location (and in this case the dropping in CraftAbstractInventoryView should be fixed to be centered at the player) |
Comments |
Comment by md_5 [ 20/Nov/24 ] |
Sorry the difference between xs/zs was a mistake. I'm not sure I agree with your point about the 0.5 offset but I have made that change for you anyway. |
Comment by Brokkonaut [ 20/Nov/24 ] |
But why should the code for xs (x shift) and zs (z shift) be different? one now has the 0.5 offset and the other has not.
The vanilla method is just for dropping items from broken blocks at integer block coordinates where the 0.5 shift makes sense to center it in the block. dropItemNaturally is not called with integer block coordinates but locations with floating point values, so the calling code can and should should decide where the center is. |
Comment by md_5 [ 20/Nov/24 ] |
It's the same as the vanilla methods as far as I can tell |
Comment by Brokkonaut [ 19/Nov/24 ] |
I think xs is still incorrect: double xs = 0.5D + MathHelper.nextDouble(world.random, -0.25D, 0.25D); double zs = MathHelper.nextDouble(world.random, -0.25D, 0.25D); |
Comment by Brokkonaut [ 19/Nov/24 ] |
Yes, dropItem does not add a random offset, and dropItemNaturally does - but i think it should be centered around the given location and not shifted half a block to the positive direction. it was like that until 2018 and all plugins we use expect that behavior.
See for example here: https://github.com/search?q=repo%3AEssentialsX%2FEssentials%20dropItemNaturally&type=code or https://github.com/search?q=repo%3AEngineHub%2FCraftBook%20dropItemNaturally&type=code or even in cb/spigot: They all use the players/entities location when calling the method and that currently does not drop the items around the player but shifted to the side. |
Comment by md_5 [ 19/Nov/24 ] |
Have you considered the distinction between dropItem and dropItemNaturally? |