I want to get the location of where a item is. So if the ItemStack is the Item entity, i can grab the location, same goes if its in someones inventory, i just grab the location of the player. I have worked out how to grab the inventory that’s the item maybe held in, just need help with converting ItemStacks to Item entity if the itemStack is a Entity.
If that was not clear here is a example.
My plugin holds the data for a ItemStack, but a player throws that item on the floor turning that ItemStack into a Entity. I want to be able to grab that Entity.
-Edit-
I know I could grab all the Entities in the server then check if that entity is a Item entity. Then check if the ItemStack is the ItemStack I hold, but that seems a bit inefficient
An Item entity holds an ItemStack, so you could just grab the Item object and ask for the ItemStack.
You can also test around to see if the item drop triggers something like EntitySpawnEvent. If it does, you’ll be able to grab it from there. Though, this seems like we can improve the current ItemDropEvent by changing the returned set to be the Item as opposed to the ItemStack.
ItemDropEvent is called before the Item entity is spawned in the event the event is cancelled, no Item entity is created unnecessarily. The correct way to listen for this is with the EntitySpawnEvent.