Solved CraftLivingEntity and ItemStacks

Discussion in 'Spigot Plugin Development' started by Igasi, May 6, 2017.

  1. [​IMG]
    The underlined part of setEquipment() says "Change to dropEquipment()"

    I checked what would happen if I did and it said "Change to setEquipment()"

    and the second line is just to show yall what it says about using setEquipment().
     

    Attached Files:

  2. Bump to page one because this is throwing a wrench at my plugin
     
  3. I do not understand why you are not using the Bukkit API for this, nor why you are ignoring the fact that it asks for EnumItemSlot and you instead supply an int.

    Not to mention that you might possibly be mixing NMS code with Bukkit ItemStacks without converting (though I could be wrong about this, I don't have experience creating new NMS item stacks from scratch).
     
  4. If I put 0 it does the same thing as SlotType.ARMOR, and that is innaccurate, it doesnt specify if I want a helmet or pants, chestplate or boots.

    Also, this is how some google search results said it is done. And I dont think there were any major changes
     
  5. SlotType, myEntity, and new ItemStack(Material) are all bukkit code.
    CraftLivingEntity is craftbukkit code.
    getHandle().setEquipment and EnumItemSlot are NMS (net.minecraft.server) code.

    For a task like this, you only need bukkit code, and you certainly cannot mix them together as you wish when you do need to use the others.

    Seeing as you're already expecting the entity to be an instanceof LivingEntity, this is likely what you'd be looking to do:
    Code (Java):
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.Material;
    Code (Java):
    LivingEntity li = (LivingEntity)myEntity;
    li.getEquipment().setHelmet(new ItemStack(Material.IRON_HELMET));
    li.getEquipment().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
    li.getEquipment().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
    li.getEquipment().setBoots(new ItemStack(Material.IRON_BOOTS));
     
    #5 iPyronic, May 6, 2017
    Last edited: May 6, 2017
    • Like Like x 1
  6. Thanks! This was more useful than all the other posts I've read regarding this category
     
    • Friendly Friendly x 1