Solved Set the head slot of a zombie to be a player head

Discussion in 'Spigot Plugin Development' started by Reflxction, Jan 28, 2020.

  1. Hello. As you probably had learnt from the title, I'm trying to set the head/helmet slot of a zombie to be a player head.

    This is the code I'm using to get the ItemStack representation of the skull (I'm abstracting the code so it works across all implementations)

    Code (Java):

        /**
         * Creates a skull of the specified player
         *
         * @param owner Owner of the skull
         * @return The ItemStack representing this skull
         */

        @Override
        public ItemStack skull(OfflinePlayer owner) {
            ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
            SkullMeta meta = (SkullMeta) skull.getItemMeta();
            meta.setOwningPlayer(owner);
            skull.setItemMeta(meta);
            return skull;
        }
    Code (Java):

        /**
         * Creates a skull of the specified player
         *
         * @param owner Owner of the skull
         * @return The ItemStack representing this skull
         */

        @Override
        public ItemStack skull(OfflinePlayer owner) {
            ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
            SkullMeta meta = (SkullMeta) skull.getItemMeta();
            meta.setOwningPlayer(owner);
            skull.setItemMeta(meta);
            return skull;
        }

    And to update the helmet slot for the zombie, I do:
    Code (Java):
    zombie.getEquipment().setHelmet(MaterialCompatibility.INSTANCE.skull(player));
    (MaterialCompatibility is an interface which handles the appropriate implementation for materials, especially after the flattening in 1.13)

    However, when testing with 1.12.2 (it's hard to test on later versions for the heavy usage), the zombie appears with a skeleton skull. Anyone knows why? Thank you in advance.
     
  2. Aren‘t the two implementations identical?
     
  3. Almost, the first uses Material#SKULL and the second uses PLAYER_HEAD

    Edit: found the problem, I forgot to specify the "3" data.
     
  4. That‘s what I was thinking, but the first also uses PLAYER_HEAD, Probably you just forgot to copy the right value...
     
  5. Oh just realized that lol, I think I got bamboozled while making the spoilers and pasted the same code for both