Getting what spawner a mob was spawned from

Discussion in 'Plugin Development' started by Hoolean, Feb 8, 2013.

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


    ^ ^ ^ ^ ^ ^
    | | | | | | | |
    | | | | | | | |
  2. Offline


    You could always record mob spawner mob spawns
  3. Offline


    Sorry, I'll rephrase that :)

    On the spawnevent, how can I get what mob spawner the mob is from?
  4. Offline



    There is CreatureSpawnEvent

    But that won't get you the actual spawner...
  5. Offline


    It depends on how accurate you want to be. You could simply iterate the nearby chunk's tile entities and find the closest spawner, but that will just be an estimate.

    There is another way, but it's very complicated and hacky. Essentially, it's possible to make a spawner assign pre-determined NBT values after it has spawned a mob. You could use that to set the entities UUID to a constant value that is created from the spawner's x, y and z coordinate - for instance by using 3 bytes (or 3.5) from x, 3 bytes from z and 1 byte from y.

    Then, when the mob has been spawned, you read this UUID, extract the x, y and z, and assign it a random UUID instead.
  6. Offline


    If the spawner hasn't been customized to spawn mobs further than default, all I did was search each block around the spawn location of the entity, 4 blocks out in each direction, 1 layer above, and 1 layer below. Found it every time. However, if there is more than one spawner, they would have to be at least 9 blocks away from each other for this to work accurately.
Thread Status:
Not open for further replies.

Share This Page