How to get NPC's inventory


#1

I’m working on an NPC plugin, but I don’t seem to be able to get the NPC’s inventory.

My NPC is an Entity of type HUMAN, but when I cast it to “Human” and try to get it’s inventory, I’m greeted with the following error:

[17:25:50 ERROR] [Sponge]: Could not pass GameStartedServerEvent$Impl to Plugin{id=stalls, name=Stalls, version=1.0, description=A random NPC shop plugin, authors=[MGlolenstine], source=mods/StallsSponge-1.0.jar}
java.lang.AbstractMethodError: Method org/spongepowered/common/entity/living/human/EntityHuman.getInventory()Lorg/spongepowered/api/item/inventory/type/CarriedInventory; is abstract
        at org.spongepowered.common.entity.living.human.EntityHuman.getInventory(EntityHuman.java) ~[EntityHuman.class:1.12.2-7.1.6]
        at xyz.mglolenstine.customNPC.onServerStart(customNPC.java:166) ~[Stalls.class:?]
        at org.spongepowered.common.event.listener.GameStartedServerEventListener_Stalls_onServerStart7.handle(Unknown Source) ~[?:?]
        at org.spongepowered.common.event.RegisteredListener.handle(RegisteredListener.java:95) ~[RegisteredListener.class:1.12.2-7.1.6]
        at org.spongepowered.common.event.SpongeEventManager.post(SpongeEventManager.java:433) ~[SpongeEventManager.class:1.12.2-7.1.6]
        at org.spongepowered.common.event.SpongeEventManager.post(SpongeEventManager.java:478) ~[SpongeEventManager.class:1.12.2-7.1.6]
        at org.spongepowered.common.SpongeImpl.postEvent(SpongeImpl.java:252) ~[SpongeImpl.class:1.12.2-7.1.6]
        at org.spongepowered.common.SpongeImpl.postState(SpongeImpl.java:260) ~[SpongeImpl.class:1.12.2-7.1.6]
        at org.spongepowered.server.SpongeVanilla.onServerStarting(SpongeVanilla.java:168) ~[SpongeVanilla.class:1.12.2-7.1.6]
        at net.minecraft.server.dedicated.DedicatedServer.handler$callServerStarting$bbg000(SourceFile:1258) ~[nz.class:?]
        at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(SourceFile:233) ~[nz.class:?]
        at net.minecraft.server.MinecraftServer.run(SourceFile:434) ~[MinecraftServer.class:?]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_202-release]

As far as I can gather, the get inventory hasn’t been implemented yet on Entity of type Human… is there any other way I could get it’s inventory and fill it up, so the NPC wouldn’t be able to pick up the items, as the ChangeInventoryEvent.Pickup isn’t called for HUMAN entities, but only for players(it’d appear).


#2

You are correct in that is not implemented, at least i can not see it in the following link.

As it hasnt been implemented, without using a work around (such as a custom inventory mapped with the humans uuid) the only way would be to use NMS code, however if you are going through that route it would probably be better to make a pull request and have it so no one else has the issue.


#3

It’s weird that it’s not implemented, as the NPCs pick up items without a hitch. Even tho it would seem that they only pick up one item and no more.


#4

My guess is that the item in hand is implemented, but not the rest of the inventory. Do also remember that minecraft code is still present so things that aren’t implemented in sponge still take into affect.


#5

Oh, I’ll check the item in hand… maybe I can set that by itself :smiley:


#6

You may also have the armor slots and secondary hand implemented too. Not sure though