-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Extend HumanEntity#dropItem API #11689
base: master
Are you sure you want to change the base?
Conversation
Thanks for that PR, I was too lazy to do it myself 😄 |
I don't think slot related methods are a good idea |
The issue with that is that dropping by ItemStack pretty much always forces the first ItemStack to be dropped. Dropping by slot allows to choose an explicit one, like the one current held, as example |
That sadly not the case for items equipped on armor. I am not quite sure why, but in my testing, armor items did not get cleared by themselves |
in my tests it worked (1.21.1 and 1.21.3) |
I did not think of that |
When I remove that line, it turns into an dupe glitch 😥 2024-11-30_14-24-31.mp4@EventHandler
public void onInventoryClick(final InventoryClickEvent event) {
if (!event.getClickedInventory().equals(event.getWhoClicked().getInventory())) {
return;
}
event.setCancelled(true);
event.getWhoClicked().dropItem(event.getSlot());
} |
hmm i see |
Oops, the patch has a problem. Give me a second to fix it |
…ayer-dropItem # Conflicts: # patches/api/0501-Extend-HumanEntity-dropItem-API.patch # patches/server/1073-Extend-HumanEntity-dropItem-API.patch
Now let's wait for a maintainer for review |
Instead of the |
Closes #11656
Motive
Developers currently have to either use NMS or copy-paste the already existing NMS implementation. This PR aims to fix that by exposing ways to call that NMS implementation more easily by extending onto the (Human)Player#dropItem method to provide more extensive ways of making the player drop items.
What does it add?
The following overloads to the
HumanPlayer#dropItem(...)
method have been added:Item dropItem(ItemStack itemStack)
Item dropItem(ItemStack itemStack, boolean persistThrower)
Item dropItem(ItemStack itemStack, boolean persistThrower, boolean throwRandomly)
Item dropItem(int slot)
Item dropItem(int slot, boolean persistThrower)
Item dropItem(int slot, boolean persistThrower, boolean throwRandomly)
Item dropItem(EquipmentSlot slot)
Item dropItem(EquipmentSlot slot, boolean persistThrower)
Item dropItem(EquipmentSlot slot, boolean persistThrower, boolean throwRandomly)
Implementation details
Internally, the implementation calls
net.minecraft.world.entity.player.Player#dropItem(...)
, making it a fairly maintainable API. But as that method does not remove the item, I have added that by callingthis.inventory.setItem(slot, null)
.JavaDocs status
I have added simple JavaDocs, but the methods should be fairly self explanatory.
Usage example
Note
I am not 100% certain that the methods work in every possible scenario, as I don't know how to test that. If somebody finds a bug, make sure to tell me and I will make sure to fix it.