1.15.2 Natural Spawn Of Custom Mobs

Discussion in 'Spigot Plugin Development' started by ChickenStyle, Jun 27, 2021.

  1. Hello, I am currently working on a Pokemon plugin and I need to make it so the pokemon (nms mobs with custom textures) will spawn naturally as they do in the PIxelmon mod, but I don't know a good way to do it so it won't be too laggy or look kinda bad, some ideas that I had and why I think they are bad for my situation:
    - Replacing mobs that spawn on EntitySpawnEvent - Bad because I want the pokemon to spawn also at day.
    - Spawning pokemons randomly around a player with PlayerMoveEvent - Bad because it can become really heavy and may cause a lot of lag when the player base on the server is big.

    So if you have an idea how to do it, please write it down :)
     
  2. Run async task to spawn every desired period. Everytime you're going to spawn a mob base it with the current world border anf highest block point, check if the place is safe then spawn it there. Modify the spawn limits yourself, running this task async means that you're spawning and doing computations in the background which may not affect players' performance.
     
    • Winner Winner x 1
  3. The world border is pretty big in minecraft, so spawning the pokemons in different places in the world is pretty useless, the chance that the player will find them is pretty low, maybe I will run an async task that loops all the players and checks the number of pokemon around them, and if there are almost no pokemon, it will spawn pokemon depending on the biome. :unsure:
     
  4. What I did is listened to MobSpawnEvent and ChunkLoad event, you can insert/replace/offset your own custom mobs and it’s decently unnoticeable.
     
  5. Why listen to MobSpawnEvent, this would cause a lose of vanilla mobs, just listen to the ChunkLoadEvent and spawn a mob with a Random value

    Code (Java):
    //Imagine you just created the event method
    int value = new Random().nextInt(100);

    if (value <= <configured percentage>) {
        //spawn your creature
    }