Adjusting Mob Equipment

Discussion in 'Resources' started by Scizzr, Oct 29, 2012.

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

    Scizzr

    Here's how I adjust the equipment of newly spawned mobs.

    Code:
    //First of all, listen to the CreatureSpawnEvent
    @EventHandler(priority = EventPriority.NORMAL)
    public void onCreatureSpawn(final CreatureSpawnEvent e) {
    //Now, check if it's a Zombie for example
        if (e.getEntityType() == EntityType.ZOMBIE) {
            //Next, we need to get the Minecraft version of the zombie
            Zombie zomb = (Zombie)e.getEntity();
            CraftZombie zombC = (CraftZombie)zomb;
            net.minecraft.server.EntityZombie zombMC = zombC.getHandle();
       
            //Okay, so let's make all zombies have a diamond sword and full diamond armor
            //item slots: 0=sword, 4=boots, 3=legplate, 2=chestplate, 1=helmet
            zomb.setEquipment(0, new net.minecraft.server.ItemStack(net.minecraft.server.Item.DIAMOND_SWORD));
            zomb.setEquipment(1, new net.minecraft.server.ItemStack(net.minecraft.server.Item.DIAMOND_BOOTS));
            zomb.setEquipment(2, new net.minecraft.server.ItemStack(net.minecraft.server.Item.DIAMOND_LEGGINGS));
            zomb.setEquipment(3, new net.minecraft.server.ItemStack(net.minecraft.server.Item.DIAMOND_CHESTPLATE));
            zomb.setEquipment(4, new net.minecraft.server.ItemStack(net.minecraft.server.Item.DIAMOND_HELMET));
        }
    }
    
    I do find it odd that the numbers for the armor start with boots. I tested it though using broadcastMessage() when a zombie died and every time, that is the order that the items were in.
    Code:
    Entity entt = e.getEntity();
    CraftEntity enttC = (CraftEntity)entt;
    net.minecraft.server.Entity enttMC = enttC.getHandle();
     
    net.minecraft.server.ItemStack[] items = enttMC.getEquipment();
     
    if (items.length > 0) {
        for (int i = 0; i < items.length; i++) {
            if (items[i] != null) {
                Bukkit.broadcastMessage(ChatColor.GREEN + "" + i + "=" + items[i].getItem().getName());
            }
        }
    }
    
    Anyways, have fun guys. Make some well-geared mobs and get your butt whooped. :)
     
  2. Offline

    AlphaRLee

    Hi, I found a more convenient way of doing this tutorial (maybe it was implemented in a more recent Bukkit version) (I'm using 1.7.9 Beta), and I thought I'd share it. This style is completely bukkit friendly, and does not rely on NMS coding (though luckily, there is hardly any in this tutorial)
    Code:java
    1. //This method spawns these entities only when you call it, change as you need
    2. //(I haven't actually tested this with the CreatureSpawnEvent event, change as necessary)
    3. //Spawn the entity. Change location to wherever you like
    4. LivingEntity livingEntity = (LivingEntity) player.getWorld().spawnEntity(location, EntityType.ZOMBIE);
    5. //Check if entity is skeleton or zombie (your choice)
    6. if (livingEntity.getType == EntityType.ZOMBIE) {
    7. livingEntity.getEquipment().setItemInHand(new ItemStack(Material.DIAMOND_SWORD, 1));
    8. livingEntity.getEquipment().setBoots(new ItemStack(Material.DIAMOND_BOOTS, 1));
    9. livingEntity.getEquipment().setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS, 1));
    10. livingEntity.getEquipment().setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE, 1));
    11. livingEntity.getEquipment().setHelmet(new ItemStack(Material.DIAMOND_HELMET, 1));
    12. }
    13. }

    I hope this helps! :)
     
  3. Offline

    MiniDigger

    AlphaRLee you should open your own thread insted of bumping 2 year old ones.

    what you are posting are just bukkit api methods, everybody can lookup in the jds (which apperently nobody does...)
     
  4. Offline

    AlphaRLee

    MiniDigger
    Ok, thank you. I just googled how to do this and this was the only tutorial I could find. I'll make new threads next year. However, interesting point is how many views this thread got before I bumped it.

    Nonetheless, I will try not to repeat any more mistakes like this one. Sorry all!
     
  5. Offline

    MiniDigger

    AlphaRLee if you want to achive anything with bukkit or java, your first looks should be the javadocs. Developer don't write all the documentation for nothing. It will speed up your development and help you to learn new stuff.
     
  6. Offline

    AlphaRLee

    MiniDigger, thank you for the tip, but I'm already aware. That's how I found out about this stuff like .getEquipment().setChestplate anyways, but thanks again.
     
Thread Status:
Not open for further replies.

Share This Page