Solved Skull_Item Skin not setting?

Discussion in 'Plugin Development' started by kayc01, Oct 26, 2016.

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

    kayc01

    Hey, very quickly (I hope).
    For some reason when I add a SKULL_ITEM to a players Helmet, it only shows the default SKULL_ITEM.

    However if I use the command /skull MHF_Zombie and place it is the correct skin.
    Am I not applying the owner correctly or Is it failing to apply the owner with the .setHelmet?


    Code:
    ItemStack ZSkull = new ItemStack(Material.SKULL_ITEM, 1);
                 SkullMeta meta = (SkullMeta) ZSkull.getItemMeta();
                 meta.setOwner("MHF_Zombie");
                 meta.setDisplayName(ChatColor.DARK_GREEN + "Zombie " + p.getName());
                 ZSkull.setItemMeta(meta);
                p.getInventory().setHelmet(ZSkull);
    There are no Errors.
    Thanks
     
  2. Offline

    AlvinB

    @kayc01
    The problem here is datavalues. If you create a skull without specifying the metadata value it defaults to 0. But to have a custom owner, it needs to be a player skull with data value 3, no other types can have custome owners.

    Also, if you just want it to look like a zombie, you don't need to load a custom skin, since there already is a built in zombie skull in minecraft. It's the one with datavalue 2.
     
  3. Offline

    kayc01

    Modifying my code, could you show me how to format and anything extra I need for the data value format.
    I saw something of it but was a bit confused by "(byte)3)".

    Thanks
     
  4. Offline

    AlvinB

    @kayc01
    I won't modify your code, you're the one coding your plugin, but I'll give you a brief explanation.

    The metadatavalue is just a short you pass into the ItemStack constructor after the amount, so you should actually be casting to short, instead of byte (the reason byte works is because short, and all primitives are a subtype of byte).
    Code:java
    1. new ItemStack(material, amount, (short) datavalue)
     
    kayc01 likes this.
  5. Offline

    kayc01

    That worked, thanks! :)
     
Thread Status:
Not open for further replies.

Share This Page