Solved How do I remove the item in hand using EntityEquipment?

Discussion in 'Plugin Development' started by Deleted user, Nov 25, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Deleted user

    I'm trying to set the weapon of a Skeleton.
    Code:java
    1. EntityEquipment inventory = Skeleton.getEquipment();
    2. inventory.setItemInHand(new ItemStack(Material.GOLD_AXE));

    Trying to clear the slot will reset it to the default one (a bow).
    Code:java
    1. EntityEquipment inventory = Skeleton.getEquipment();
    2. inventory.setItemInHand(new ItemStack(Material.AIR));

    Code:java
    1. EntityEquipment inventory = Skeleton.getEquipment();
    2. inventory.setItemInHand(null);
     
    jjssman likes this.
  2. Offline

    Deleted user

  3. Offline

    Dragonphase

    Joiner

    Are you trying to set the item in hand to nothing, or to a Golden Axe? As far as I'm aware, the following should work:

    Code:java
    1. skeleton.getEquipment().setItemInHand(new ItemStack(Material.GOLD_AXE));
     
  4. Offline

    Deleted user

    Dragonphase I am trying to remove it, that is set it to air.
     
  5. Offline

    JordyPwner

    Try to clear the inventory
     
  6. Offline

    Deleted user

  7. Offline

    JordyPwner

  8. Offline

    Deleted user

    JordyPwner I put all the relevant code on the question. Does it work to you?
     
  9. Offline

    mrCookieSlime

    Joiner
    Is Skeleton an instance of Skeleton or are you trying to access it like a static method?
    You can only use that method when having an actual Skeleton e.g. in an EntityDamageEvent.
     
  10. Offline

    Deleted user

    mrCookieSlime In this case it will give a compile error, no?
    However, here is how I get it.
    Code:java
    1. Skeleton mob = (Skeleton)World.spawnEntity(Location, EntityType.SKELETON);
     
  11. Joiner
    Naming variables properly is important. Anyways, in your example, you are doing Skeleton.getEquipment(), however in that piece of code the variable is called 'mob', not Skeleton. This made mrCookieSlime think that you were trying to do a static method call.

    As for your problem, I doubt you can clear their item in hand. Skeletons are made to be wielding a bow. I don't know if there's some NMS magic you can do, but at least I have never seen this done.
     
  12. Offline

    mrCookieSlime

    Assist
    Well for me mob.getEquipment().setItemInHand(null) has always worked.

    Joiner
    Please post your full code. You also need to mob.getEquipment() in this case.
     
  13. Offline

    Deleted user

    Assist mrCookieSlime I used to write variables as their respective type name. It is not that kind of problem.
     
  14. Joiner
    It is when you capitalize the first letter, which doesn't follow the Java naming conventions, and is misleading/confusing.
     
  15. Offline

    Deleted user

    Assist I think it is that kind of problem, but I would like to see it said somewhere.
    mrCookieSlime null does not work. Here is the full relevant code.
    Code:java
    1. Skeleton mob = (Skeleton)Dati.getBoss().getWorld().spawnEntity(Dati.getBoss().getLocation(), EntityType.SKELETON);
    2. mob.setMaxHealth(Dati.getConfig().getDouble("difficolta.soldati.vita", 50D));
    3. mob.setHealth(Dati.getConfig().getDouble("difficolta.soldati.vita", 50D));
    4. EntityEquipment inventario = mob.getEquipment();
    5. inventario.setItemInHand(new ItemStack(Material.GOLD_AXE)); // This works
    6. ItemStack elmo = new ItemStack(Material.SKULL_ITEM);
    7. elmo.setDurability((short)SkullType.WITHER.ordinal());
    8. inventario.setHelmet(elmo);
    9. ItemStack corazza = new ItemStack(Material.LEATHER_CHESTPLATE);
    10. LeatherArmorMeta metaCorazza = (LeatherArmorMeta)corazza.getItemMeta();
    11. metaCorazza.setColor(Color.BLACK);
    12. corazza.setItemMeta(metaCorazza);
    13. inventario.setChestplate(corazza);
    14. mob.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0));
    15. Soldato soldato = new Soldato(mob);
    16. soldato.runTaskTimer(SpHxWOSBoss.getMain(), 0L, 1L);
    17. Dati.getSoldati().add(soldato);
     
  16. Offline

    mrCookieSlime

    Joiner
    Hmmm, which version of Bukkit are you using? Maybe it is a Bukkit related issue since it is working for me.
     
  17. Offline

    Deleted user

    I only do it when posting on the web.
    @mrCookieSlime 1.7.9-R0.2
     
  18. Offline

    Deleted user

  19. Offline

    Deleted user

  20. Offline

    Hex_27

    Joiner
    Try
    Code:java
    1. mob.getEquipment().setItemInHand(null);

    This makes the skeleton hold nothing in its hand. Works for me when I'm using this on a pigman. I know you tried it and it doesn't seem to work... but it won't hurt to try again. Also, it will be easier to check if you use morelogical names: instead of "elmo" for a helmet, use "helmet".
     
  21. Offline

    Deleted user

    Hex_27 It does not work. Have you tried it on a skeleton?
     
  22. Offline

    Hex_27

    Joiner no I haven't. Have you tried setting it to something else? (etc a sword)
     
  23. Joiner Please show your full code.
     
  24. Offline

    Rocoty

    You know...English isn't the only language in the world.
     
    1 person likes this.
  25. Rocoty Most people probably see that and think of this guy

    [​IMG]
     
    Rocoty likes this.
  26. Offline

    Deleted user

    Last edited by a moderator: Jun 13, 2016
  27. Joiner This is not your full code. You don't even set it to null in the snippet you linked. Show the full code, as in the full class.
     
  28. Offline

    Deleted user

    AdamQpzm The entire class is that method.
     
  29. Joiner Then in that case all I can say is that you're never setting it to null, so it never disappears. The more we can see of your plugin, the more likely we are to find why it doesn't work and help you to correct it. Currently, nobody can help you as you do not show an attempt to set it to null, other than the context-less example in your original post.
     
  30. Offline

    Deleted user

Thread Status:
Not open for further replies.

Share This Page