Solved Custom generate modify dungeon spawners

Discussion in 'Spigot Help' started by Fahlur, Apr 28, 2017.

  1. I've never really worked with generation before, mob spawning and many other things but never actual generation and I was wondering if there's a way on chunk generation to check for a mob spawner and then if so check what type it is as well as maybe even change it.

    If so I just want to be put in the right direction if possible, please don't spoon feed I love learning new tricks , and some on my own. I just don't know where to look for stuff like this. especially this specific.
     
    #1 Fahlur, Apr 28, 2017
    Last edited: Apr 28, 2017
  2. Well I found this. I know its not the best in the world. But I did notice 1 issue, soon as the initial mob spawns, it resets back to its previous spawner, any ideas?

    Code (Text):

      public void l(org.bukkit.event.world.ChunkLoadEvent q) {
         for (int x = 0; x < 16; x++) {
           for (int y = 0; y < 127; y++) {
               for (int z = 0; z < 16; z++) {
                 Block block = q.getChunk().getBlock(x, y, z);
        if(block.getType().equals(Material.MOB_SPAWNER)){
           
           // Get Spawner
           CraftCreatureSpawner cs = (CraftCreatureSpawner) block.getState();
           cs.setSpawnedType(EntityType.PIG_ZOMBIE);
              }
            }
           }
          }
    }
     
     
  3. Instead of iterate alla blocks in the chunk, why not use the Chunk#getTileEntities method? It's quite faster, also try to update the block entity, using the #update(true) method. I worked with spawner either and work fine for me, the spawner type does not revert back
     
    • Like Like x 1
  4. thanks on the tileEntites yea much much faster. also however having issues with update(true)

    just to be sure did I do this right, because its still resetting the spawner.

    Code (Text):

    public void l(org.bukkit.event.world.ChunkLoadEvent q) {
         for (BlockState e : q.getChunk().getTileEntities()){
           if(e instanceof CreatureSpawner){
             CreatureSpawner c = (CreatureSpawner) e;
             c.setSpawnedType(EntityType.CREEPER);
             c.update(true);
           }
         }
    }
     
    note I even tried e.update(true) as well
     
  5. Using the ChunkLoadEvent i think you change it every time the chunk load, so if there are also others spawner, they change to creeper when chunk load. I am not sure why this does not work, since you say the mob stay there until the first mob spawn
     
    • Like Like x 1
  6. I changed to chunkPopulateEvent and the problem was solved. thanks much for your help!
     
  7. No problem. I've never really used chunk event for this kind of thing, so good to know for the future.
    Mark the thread as solved if it's everything ok