Make Entity/Villager have an Inventory open on right click.

Discussion in 'Plugin Development' started by euller12, Aug 11, 2013.

?

Make Entity/Villager have an Inventory open on right click.

  1. Can help me.

    0 vote(s)
    0.0%
  2. Knows what to do.

    1 vote(s)
    100.0%
Thread Status:
Not open for further replies.
  1. Offline

    euller12

    Hi, I would like to be able to make a village named Bob have an inventory when right click on.

    To make the NPC I am using Remote Entities. Bob does spawn and stays in a building.

    Here is my code:
    Code:java
    1. private EntityManager manager;
    2.  
    3. public void onEnable() {
    4. manager = RemoteEntities.createManager(this);
    5. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    6. }
    7.  
    8. public void spawnNPC(String name, Location loc) {
    9. CreateEntityContext c = manager
    10. .prepareEntity(RemoteEntityType.Villager)
    11. .asPushable(true)
    12. .asStationary(true)
    13. .atLocation(loc)
    14. .withName(name);
    15.  
    16.  
    17. RemoteEntity re = c.create();
    18.  
    19. }
    20.  
    21. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    22. Player player = (Player)sender;
    23.  
    24. if(commandLabel.equalsIgnoreCase("spawnnpc")){
    25.  
    26. spawnNPC("Bob", player.getPlayer().getLocation());
    27. }
    28. return false;
    29. }


    Please help!
     
  2. Offline

    chasechocolate

    Use this (taken from the RemoteEntities thread):
    Code:java
    1. entity.getMind().addBehaviour(new InteractBehaviour(entity)
    2. {
    3. @Override
    4. public void onInteract(Player inPlayer)
    5. {
    6. //Open inventory
    7. }
    8. });
     
  3. Offline

    euller12

    Okay I will try it!

    Um? Where do I put this in my code?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  4. Offline

    chasechocolate

    euller12 in your spawnNPC() method.
     
  5. Offline

    euller12

    Yeah I don't have a variable for entity nor do I know how to make that variable.
     
  6. Offline

    chasechocolate

    You actually do... it's "re".
     
  7. Offline

    euller12

    Oh okay.

    Yeah, it worked but now he gets hurt aka he dies.

    How do I make the NPC not die.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page