[NMS] Set CreatureSpawner EntityType to custom entity?

Discussion in 'Plugin Development' started by valon750, Apr 21, 2014.

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

    valon750

    Hello all,

    Previously had a post regarding supplying a custom Zombie entity with equipment. However despite having a spawnCustomZombie method, I would was wondering if it were at all possible to cast this custom zombie, to an EntityType that I may apply to a spawner.
     
  2. valon750 Ermm, Im not sure how to do that, but I geuss you could check on creature spawn, if spawnreason == spawner?
    btw! love FlightPack!
     
  3. Offline

    beeselmane

    Well, I don't know of any way to do this normally.. You could override the normal "zombie" class (EntityZombie) with your custom class, say "CustomZombieEntity".. (you might be able to override any class you want, but I've never tested it) You would do this like so:

    Assuming your Custom class(CustomZombieEntity for this example) extends the standard minecraft class:

    function in plugin main class:
    Code:java
    1. private void registerEntity(Class<?> customEntity, Class<?> overridenClass, String name, int overriddenId)
    2. {
    3. String []biomeFields = new String []{"K", "J", "L", "M"};
    4.  
    5. try {
    6. Method register = EntityTypes.class.getDeclaredMethod("a", new Class<?>[] {Class.class, String.class, int.class});
    7. m.setAccessible(true);
    8. m.invoke(null, customEntity, name, overriddenId);
    9. Field f = BiomeBase.class.getDeclaredField("biomes");
    10. f.setAccessible(true);
    11. BiomeBase biomes[] = (BiomeBase []) f.get(null);
    12.  
    13. for (BiomeBase b : biomes)
    14. {
    15. if (b == null) break;
    16.  
    17. for (String s : biomeFields)
    18. {
    19. Field moblist = BiomeBase.class.getDeclaredField(s);
    20. moblist.setAccessible(true);
    21. List<BiomeMeta> mlist = (List<BiomeMeta>) moblist.get(b);
    22.  
    23. for (BiomeMeta meta : mlist)
    24. {
    25. if (meta.b.equals(overridenClass))
    26. {
    27. meta.b = customEntity;
    28. }
    29. }
    30. }
    31. }
    32. } catch (Exception ex) { ex.printStackTrace(); }
    33. }


    and then in onEnable just call this method.. (all entities of the original type will get replaced though.. you could stop them from being spawned by only letting them spawn if spawnreason is set to mob spawner..
     
  4. Offline

    valon750

    Someone_Like_You

    I looked in to that method yes, perhaps checking if the reason was a spawner, but then I'd need to loop through the nearby blocks to find the spawner block.

    If there was just a getSpawnerBlock(); method... It'd make everything just so much easier... :/

    beeselmane
    Now this would be perfect, if I weren't in need of multiple Zombie classes.
    Hmm.. do you think that anyone would be able to create a getSpawner method? I imagine it'd then be as simple as just say, getting the information for the spawner from a file.

    Of course the issue would then be if there's two spawners close together.. considering looping through all the blocks, and returning the block that's a spawner.. could cause a feeeeew issues...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    beeselmane

    valon750 I have a few ideas… but how are you registering your mob with the minecraft server? (Through EntityTypes?)
     
  6. Offline

    valon750

    beeselmane

    Basically I extend EntityZombie, which in fact doesn't alter all zombies, then I have a method in which I can spawn said Zombie, with the use of a tool such as a stick.
     
  7. Offline

    valon750

    Valon used Bump! It's super effective!
     
Thread Status:
Not open for further replies.

Share This Page