Solved How to create custom naturally spawning mobs 1.9

Discussion in 'Spigot Plugin Development' started by cgameing, May 30, 2016.

  1. I have searched the Internet for custom spawning mob tutorials, yet haven't found one.
    Most are either non natural, or event based (e.g. Bosses/Arena)

    I need this for an RPG plugin, and I would prefer not to use a premade plugin.

    Thanks, anyhelp is good help.
     
  2. Do you mean this?

    LOCATION.getWorld().spawnEntity(LOCATION, EntityType.TYPE);
     
  3. Location loc = new Location(Bukkit.getServer.getWorld("SampleText"), x, y, z);
    loc.getWorld.spawnEntity(loc, EntityType.Creeper);
     
  4. I'm assuming you are talking about custom entities. If you want custom naturally spawning mobs you have two options:
    - use mob spawners (e.g. creating your custom "mob spawner" like a sign or something)
    - use nms to change the biome meta for each biome in the registry.
     
    • Agree Agree x 1
  5. You could simply get the event when a mob spawn for example a pig and then randomize wether it's going to be the custom mob or the pig.. :D
     
  6. I might be wrong but I consider that as "event based"...
    Also, that will override any default spawning mob limit/rule.
     
  7. Yeah I know but there's not a lot of options.. :D
     
  8. The NMS option is the better one though;)
    But a bit more complicated. I think I followed this tutorial and it worked well for 1.9.
     
  9. How would that tutorial work for 1.9 since they changed all the variables names and implemented a biome registry? o_O It's outdated.
     
  10. I fixed the outdated parts...I just don't remember how exactly. But because I know that I forget things, I did leave a note in my code leading to this. I think the rest of the tutorial worked mostly.
     
  11. That link still leads to an outdated version (1.8).

    Edit: I might be wrong but I'm thinking you haven't tested that with 1.9.
     
    #11 Grimerlin, May 30, 2016
    Last edited: May 30, 2016
  12. However it worked in 1.9 when using the a-method I linked inside the for loop of the registerEntites method.
    Also the second for loop has to iterate over BiomeBase.i instead of BiomeBase.biomes. And the fields there changed to "u", "v", "w", "x"
    So just try it and ask if you have problems instead of simply saying that it's outdated^^
     
  13. Actually that link is really outated and you didn't provide a new solution but now, saying
    You are funny.
     
  14. Wat?
    I did send a tutorial and told you how to fix the outdated parts. Whats wrong with that?
     
  15. There's nothing wrong with that, but you could have just shared your solution in the first post instead of providing outdated tutorials asking me to solve the dilemma when you already knew the answer.
     
  16. I thought you were the op and I didn't want to spoonfeed you ;) Also I didn't remember the answer so I thought it would be best for all of us to provide you some starting points and let you figure out the missing parts. Again, I thought you were the op, my bad.
     
  17. Overriding Mobs is fine, this plugin will only effect one world, and will replace all normally naturally spawning mobs
     
  18. NMS is more complicated then expected. . .
    It doesnt matter If i can customise these properties of a already spawned mob

    Custom Name
    Custom HP
    Potion Effects
    (Make them peaceful with villagers)
    Damage
    Armor+Weapon
     
    #18 cgameing, May 30, 2016
    Last edited: May 31, 2016
  19. I managed to solve it with this


    @SuppressWarnings("deprecation")
    @EventHandler(priority = EventPriority.HIGH)
    public void onCreatureSpawn(CreatureSpawnEvent e) {
    LivingEntity entity = e.getEntity();

    ItemStack ninjaBlade = new ItemStack(Material.DIAMOND_SWORD);
    ItemMeta metaNinjaBlade = ninjaBlade.getItemMeta();
    metaNinjaBlade.setDisplayName(ChatColor.RED + "Mages Bane");
    ninjaBlade.setItemMeta(metaNinjaBlade);

    entity.setCustomName(ChatColor.RED + "Custom Zombie");
    entity.setCanPickupItems(false);
    entity.getEquipment().setItemInHand(ninjaBlade);
    entity.getEquipment().setItemInMainHandDropChance(1);

    }

    Which is fine for what it does
     
  20. If you don't wanna go the NMS way you should start at the spawn event and change the spawned entity to your liking (name, potion effects etc). Then damage events will be the next part. If an entity is damaged by another entity this event gets fired. You could simply cancel it if the attacker is your mob and the target a villager. Not the best way of doing it because zombies will still go to villagers, simply not kill them. Maybe you could also do the same thing for this event (so that that zombies don't target villagers at all).
    For changed hp/damage you could also modify the EntityDamageByEntityEvent increasing/decreasing the dealt damage. Keep in mind that there's also an EntityDamageEvent. Maybe use the second one for decreasing/increasing the hp of your custom entity while changing the dealt damage in the EntityDamageByEntityEvent.

    Edit: To slow :(