#(nooooooooah) NPC drop items on death via API

16 messages · Page 1 of 1 (latest)

gloomy imp
#

How can I make an NPC drop its inventory and armor on death using the API? The NPC already has all the items I need it to drop but I cant get it to drop them on death. Thanks in advance!

shell quartzBOT
#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.
You can block this bot if you don't want to see these messages, I won't mind.
<@&525394568410038282>

rugged dew
#

can use the dropstrait or implement it yourself in the NPCDeathEvent

#

actually, maybe just implement it yourself in the death event

hidden gardenBOT
#
Thread Closing Reminder

Has your issue been resolved, or your question been answered?
If so, please use the </resolved:1028673926114594866> command to close your thread.
Or </invalid:1028673926898909185> if it's not possible to resolve.

If not yet resolved, please reply below to tell us what you still need.

(Note that if there is no reply for a few days, this thread will eventually close itself.)

#

@gloomy imp

gloomy imp
#

doing it myself in the death event is what I'm currently doing but no matter what I try it somehow still never drops anything. This is probably me missing something obvious but I just cant find out what

#

This is my current approach, am I doing something basic wrong?

`@EventHandler
public void onNPCDeath(NPCDeathEvent event) {
NPC npc = event.getNPC();
if (npc.isSpawned()) {
Entity npcEntity = npc.getEntity();
if (CitizensAPI.getNPCRegistry().isNPC(npcEntity)) {
Inventory npcInventory = npc.getOrAddTrait(Inventory.class);
Equipment npcEquipment = npc.getOrAddTrait(Equipment.class);

            ItemStack[] items = npcInventory.getContents();
            event.getDrops().addAll(Arrays.asList(items));
            
            ItemStack[] armor = npcEquipment.getEquipment();
            event.getDrops().addAll(Arrays.asList(armor));
        }
    }
}`
#

Just found it, I shouldnt have done if (npc.isSpawned()). Removing this fixed it.