Put block on mobs head...?

Discussion in 'Plugin Development' started by Meatiex, Feb 2, 2015.

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

    Meatiex

    How would I put a block on a non-LivingEntity's head?
    I am able to put a block on Zombies, Skeleton and Villagers with the code below, but nothing els...
    Code:
            @EventHandler
            public void spawn(EntitySpawnEvent event) {
                Entity entity = event.getEntity();
              
                if (entity instanceof LivingEntity) {
                ItemStack skull = new ItemStack(397, 1, (short) 3);
                SkullMeta meta = (SkullMeta) skull.getItemMeta();
                meta.setOwner(randPlayer());
                skull.setItemMeta(meta);
                EntityEquipment ee = ((LivingEntity)entity).getEquipment();
                ee.setHelmet(skull);
                }
    }
    In-case you were wondering, hears what randPlayer() does :p

    Code:
            public String randPlayer() {
                ArrayList<String> list = new ArrayList<String>();
                for (OfflinePlayer p : Bukkit.getOfflinePlayers())
                    list.add(p.getName());
                return list.get(new Random().nextInt(list.size()));
            }
     
  2. You might be able to with NMS, but otherwise I don't think you can.
     
  3. @Meatiex Non-LivingEntity's head. Is there even a non-LivingEntity with a head?
     
  4. Offline

    Meatiex

    Pigs, Cows, Sheep seem to have heads, but I can't put thinks on their heads...
     
  5. They are LivingEntities
     
  6. Offline

    Meatiex

    Strange.... The head doesn't want to go on their head...
    I'll try to make it a block instead of player head and see if it works.
     
  7. @Meatiex Are you sure that this is even possible in MC?
     
  8. Offline

    Meatiex

    Code:
            @EventHandler
            public void spawn(EntitySpawnEvent event) {
                Entity entity = event.getEntity();
                EntityEquipment ee = ((LivingEntity)entity).getEquipment();
                ee.setHelmet(new ItemStack(Material.SAND));
                }
    Still only Zombies, Skeletons and Villagers will spawn will the block on their head...

    i'm not sure... probably not :p

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

Share This Page