Player's inventory + NPC?

Hello, i’m creating a serveur roleplay, but it needs to have some player’s inventory, i saw this is not implemented and i have to wait… i’m going to do my shiter (french expression) but i want to know where is the api in the developpement? When will it go out ?
and i have an another question, i want to create a npc (a human like you and me). but i don’t know can i do it? can you help me?

The inventory API is currently being worked on. It will be finished when it is finished.

1 Like

Yes, you can create a human.

Location<World> l = ...;
Human human = l.getWorld().spawnEntity(EntityTypes.HUMAN, l.getPosition());
1 Like

i get this error in eclipse:
The method spawnEntity(Entity, Cause) in the type EntityUniverse is not applicable for the arguments (EntityType, Vector3d)

The method should take a cause (Cause.of(myCause)) as argument instead of a location which should be defined with entity.setLocation(myLocation)

and how i get entity?
i have entitytype , but i need entity…

world.createEntity(EntityType, Vector3d)

in your case:

public void spawnHuman(Location<World> location) {
  final Entity entity = location.getExtent().createEntity(EntityTypes.HUMAN, location.getPosition()).get();
  location.getExtent().spawnEntity(entity, Cause.of(myPlugin));
}
4 Likes

thx, and how can i change the name (over the head) and the skin
and where can i found the list i can do with him? (modify position, modify head rotations, how can i make he move, (run?))

To change the name:

human.offer(Keys.DISPLAY_NAME, "Insert name here");

To change the skin, you need to provide the UUID of a player you want the NPC to look like. This is not currently implemented, though. It will end up looking like this.

human.offer(Keys.SKIN, UUID.fromString("e66b9fa0-3709-47b6-8a04-693fd526add7"));

Replace e66b9fa0-3709-47b6-8a04-693fd526add7 with the UUID of the player you want. Try http://mcuuid.net.

To move the NPC, use setLocation and setPosition.

1 Like

what is the list of all modification what can i do?

Unfortunately, it’s hard to figure that out. You can try adding this code:

try {
    for (Field f : Keys.class.getDeclaredFields()) {
        if (human.supports(f.get(null)) {
            System.out.println(f.getName()) + " = " + f.get(null));
        }
    }
} catch (Exception e) {
    e.printStackTrace();
}

This will print out the list of what changes are currently implemented. For each changeable value, you will see a line in this form:
SOME_KEY = Key{Value: org.spongepowered.api.data.key.KeyFactory$1<java.lang.String>, Query: SomeKey}
The part before the = is the field name, and the part between < and > is the class of the value. Use human.offer(Keys. <insert field name here> , <insert value here> ) to change it.

it’s doens’t work
i have this:

and i have an another question:

  • how can i make my human invincible? no-damage?
    i try invulnaribility
    but without success…
    and for rotation of head? and leg? and arm? can i do it?

if (human.supports((Key)f.get(null)) should fix your issue

If something doesn’t work, it’s likely not implemented. Run the code snippet I posted (with @NeumimTo’s modification) to see what is supported.

For head rotation, you can use setRotation. Minecraft doesn’t allow you to control leg and arm rotation. Invulnerability is available (see the Keys class), but it is not implemented yet.

Is already implemented?

Is already implimented, and works great

Shure?? I am using this:

    	if (args[0].equalsIgnoreCase("profile")) {
    		Entity ent = player.getWorld().createEntity(EntityTypes.HUMAN, player.getLocation().getPosition()).get();
    		ent.offer(Keys.AI_ENABLED, true);
    		ent.offer(Keys.DISPLAY_NAME, Text.of(player.getName()));
    		ent.offer(Keys.SKIN_UNIQUE_ID, UUID.fromString(args[1]));
    		player.getWorld().spawnEntity(ent, Cause.of(NamedCause.simulated(player)));
    		
    		RedProtect.logger.warning("Spawn Entity");
    		return cmdr;
    	}

And didnt worked, the NPC still steve/alex!

Other than the keyname Keys.SKIN changing to Keys.SKIN_UNIQUE_ID, this feature was working in api 2.1.something…
Pics or it didn’t happen? – Roaming Zombie Gangs - YouTube A video I made using 15 humans specifically decorated, posted just before Christmas. It took me 1 minute to modify that old code with key and various method name changes and get the same result now.

It works regardless of offering the skin uuid before or after spawning the entity as well.
http://prntscr.com/avf9kh showing code

Debug by spitting out the offer return values - if it is not a success offering the skin, then there is something wrong with the argument format.

IF you are running your test server in offline mode, then it will not work, since offline mode has no regard for licensed uuids, and the skin comes from the minecraft skinservers, which will ignore requests from offline mode servers.

2 Likes

Yes, on my tests i need more than one player online to test and i need to use on offline mode. But anyway, if in offline mode theres no API or MojangAPI to get real skins by nick like Bukkit do?

Edit: On your code you make Micheal dancers? :smile: :smile: :smile: :smile:

Depends how long ago you had it working on Bukkit, have you got this in a current spigot 1.8 plugin under the same conditons? Because it was changes that Mojang made to the fundamental ways the skins are served back sometime around or after 1.8 came out that the skinservers will now no longer issue a skin out based on name, only UUIDs, and only if those UUIDs exist in the on the skinserver, and they supposedly ignore requests from offline servers – so if the process works on a spigot 1.8 offline server right now, then that ignore-requests part must be wrong. But if you’re referring back to 1.7s or before behaviors that you saw working a year or two ago or longer, the changes at mojang end make that no longer possible.