CreatureSpawnEvents aren't monitoring Animal spawns?

Discussion in 'Plugin Development' started by DrBoweNur, Nov 6, 2011.

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

    DrBowe

    Alright, I'll go ahead and post the portion of my code that simply refuses to work:
    Code:java
    1.  
    2. //events for apocalyptic mode
    3. else if(Config.APOCALYPTIC){
    4. System.out.println("Apocalypse Spawning");
    5. Entity e = event.getEntity();
    6. if(e instanceof Pig || e instanceof Sheep || e instanceof Cow){
    7. e.getWorld().spawnCreature(e.getLocation(), CreatureType.ZOMBIE);
    8. e.remove();
    9. System.out.println("Adding zombie");
    10. }
    11.  


    Now, for whatever reason, nothing is being recognized as an animal. Everything spawns as normal, and my first debug message prints whereas the second does not.

    Now, to cover some of the obvious answers:
    • Yes, CreatureSpawnEvent is registered
    • Yes, Config.APOCALYPTIC is true, hence my debug message displaying
    • Yes, I've tried using instanceof Animals as well (first, actually), and came up empty handed
    So is this a bug with Bukkit itself? Is anyone else having issues using the instanceof operator on Animals?


    EDIT:
    Animal Spawns aren't being recognized at all through onCreatureSpawn. Only Monster spawns. Any thoughts?
     
  2. try e instanceof Creature? Not quite sure why that wouldn't work...
     
  3. Offline

    DrBowe

    Neither am I, and it's extremely frustrating.
    One day, I have a working method to spawn an over-abundance of zombies --much more complicated than what I posted here-- and the next day (rather, 2 months after I come back from a coding exodus), I'm left with broken code for no apparent reason. :/

    I'll try Creature and post back, though Creature encapsulates all of the Monsters, right? Meh, I'll do some hacky workarounds and see what I come with.
     
  4. I don't really remember. I don't know why instanceof [Insert animal] wouldn't work. Try checking the CreatureType instead of instanceof?
     
  5. Offline

    DrBowe

    Yeah, I'm using instanceof for all of the Monsters and it works fine. That's why I'm coming here out of confusion.

    I'll try CreatureType, seems like the next best bet.
     
  6. Infact, I think your supposed to use CreatureType. Don't ask my why, I have no clue :/
     
  7. Offline

    DrBowe

    @tips48
    CreatureType doesn't work either...

    Um.
    What.
     
  8. Offline

    nisovin

    You're using event.getCreatureType()?
     
  9. Offline

    DrBowe

    Yes, was using instanceof before (which has never failed me), and this is only a problem for Animals.

    Using it with any Monster works fine.

    ...Just did some more debugging.
    CreatureSpawnEvent literally can not catch Animal spawns.
    So, did something drastic change while I was gone? :|

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  10. What? It doesn't?

    Thats BS! Don't know why it wouldn't.... Check for a new event? Bleh
     
  11. Offline

    undeadmach1ne

    i think they changed recently due to animal persistence and breeding?
     
  12. Offline

    DrBowe

    So they were completely removed from the spawning cycle then? Christ, this is not going to make my job easy or efficient.
     
  13. Offline

    undeadmach1ne

    im not entirely sure what is happening 'behind the scenes', i just noticed some strangeness with that plugin i am working on. i was grabbing onCreatureSpawn and setting health of the mobs. to 'remember' them i put them and their heath into a hashmap, and then saving/loading that map back up onDisable/onEnable. i remove them onEntityDeath, but over time the hashmap swelled up because some of them are removed/despawned by bukkit and i couldnt figure out how/when/where to catch that event and remove those ones from my map...so i made a method to go through and find the ones that didnt exist and remove them from my map. i throw 'x was not in the hashmap' for debugging when something dies that i dont 'remember' spawning (not in my map). i constantly get 'pig/cow/chicken was not in the hashmap' now, but when i first started working on this it was normal (all the animals and mobs were treated the same). no idea why though...it doesnt effect my plugin because i only care about monster health.
     
  14. Offline

    DDoS

    Just to be sure:

    Did you register the event in you onEnable()?

    If you want to fix your hash map swelling problem, make a new async repeating task and iterate over the entities, and remove those that return true to isDead().

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  15. Offline

    undeadmach1ne

    @DDoS interesting. where were you when i made a thread about this? lol i use a for loop through worlds/entities and make a map of them then retainAll on my map...im not 100% sure if its working properly though. i do in onDisable and part of me thinks its too late at that point, but again, it seems to work so...just sucks being a noob and not understanding 100% of whats going on. lots of guessing and hoping. ill look into your suggestion. its all kinda moot anyway since in 1.9 dev builds i cant set their health higher than 20 any more so my plugin is pretty much useless once that build is a rb.

    anyway sorry to derail your thread DrBoweNur ill shut up now :p
     
  16. Offline

    DrBowe

    @DDoS
    Please see the first post again :)

    @undeadmach1ne
    Don't worry, I've resigned to the fact that they just aren't registed in onCreatureSpawn.

    This really does not bode well for my zombie plugin. Apocalyptic mode will pretty much only apply to night now, without the possibility of zombies spawning in lit up areas. Crap
     
  17. Offline

    DDoS

    Well, that sucks! I guess we might need to wait until the next recommended build, and see if it's just a bug.
     
  18. Offline

    undeadmach1ne

    lol you could be a dick and kill all the animals in the region when the apocalypse starts >:)

    "sorry about your farm...zombies must have eaten your livestock"
     
  19. Offline

    DrBowe

    I actually did that in the original version :p (killed all mobs when event started)

    But the problem lies in the fact that Apocalyptic mode was only 'apocalyptic' because animal spawns were converted to zombie spawns, allowing zombies to spawn in lit areas.
     
  20. Offline

    undeadmach1ne

    yeah people would get mad now cause animals are not unlimited any more from what i gather...the only way to maintain a steady food supply is to make a farm and breed them. ppl would be mad if you wiped them.
     
  21. Offline

    bergerkiller

    @DrBoweNur you can try keeping a WeakHashmap (WeakHashSet?) for the spawned animals and use a scheduled repeating task to spawn your monsters. Downside is that you can't disable them to spawn, so animals will be visible for a few seconds.

    Alternative is using Spout to listen for spawned or move entity packets...
     
  22. Offline

    DrBowe

    I am using Spout heavily with this plugin, so that could be a good alternative.
    I'm just not sure what Notch was thinking when he went through with this, though.
     
  23. Offline

    DrAgonmoray

    This is late, but..

    I had this exact problem a couple months ago. I gave up re-worked the entire plugin system so I wouldn't have to do that >.>
     
  24. Offline

    DrBowe

    @DrAgonmoray
    Yeah, seems like I'll be doing the same thing. I can understand making animals consistent and what not, but why would he unhook them from the server's spawning events?
     
  25. Offline

    DrAgonmoray

    Well they don't spawn like normal (now they're spawned when the chunk generates) so maybe he forgot to re-hook it. \_(:confused:)_/
     
Thread Status:
Not open for further replies.

Share This Page