Solved Cancelling mobs spawning from mob-spawners

Discussion in 'Spigot Plugin Development' started by JacksonHogan, Jan 8, 2018.

Thread Status:
Not open for further replies.
  1. I am trying to work on a plugin that cancels out mobs spawning from a mob spawner unless they have an emerald block underneath it.
    Code (Text):
    @EventHandler
        public void onEntitySpawn(SpawnerSpawnEvent e){
            Location emeraldLoc = e.getSpawner().getLocation();
            emeraldLoc.setY(emeraldLoc.getY()-1);
            if(emeraldLoc.getBlock().getType()!=Material.EMERALD_BLOCK){
                e.setCancelled(true);
            }else{
                e.setCancelled(false);
            }
        }
    So far that is what I have, and it does not seem to be working...
    The issue that I've come across is that when there is no emerald block underneath a zombie spawner(The only hostile mob spawner I've tested so far), it will spawn chickens that attack you.
     
  2. Your code should apply to every Spawner currently.
    If you want to use it for hostile spawners only, you need to implement a check for the spawners EntityType to spawn.

    Are you sure you've picked the right spawner for your testing (assuming you've used creative or give command)?
     
  3. ryu

    ryu

    Code (Text):
        @EventHandler
        public void onEntitySpawn(SpawnerSpawnEvent event) {
            Location location = event.getSpawner().getLocation().subtract(0, 1, 0);
            if (!(location.getBlock().getType() == Material.EMERALD_BLOCK)) event.setCancelled(true);
        }
    https://gyazo.com/54bd3912dc711c795a974d68183b37d3
     
  4. That is basically the same thing I had just simplified. I am still getting chickens coming out of the zombie spawner that attack me
    https://gyazo.com/c2933fb5939ae34032caf157364faee0
     
  5. ryu

    ryu

    Did you try using the snippet of code I sent you instead of yours and if so and you're still having that issue is there possibly any other plugin on the server that can be controlling spawners spawning?
     
  6. I'm not running the server, but only by reading "SilkSpawners" plugin page I can already smell that it might the problem.
    (Always) test your plugins in a fresh and clean setup, please.
     
  7. It appears to still be spawning chickens. With just the plugin installed.
     
  8. This is a bit harder but it still should work. Maybe the chicken are not detected as mobspawner spawns (which would have sense because the spawner is a zombie one). Try checking if the spawner has spawned a chicken and then kill it.
     
  9. If this behaviour is not created by anything inside your or any other plugin installed (and no I don't think it's the Spigot API being the cause), then it appears that something is really messed up with your game / server.

    What version of Spigot are you running?
    Are you using any mods in your client?
    Did you make sure to use a fresh mobspawner block after editing your setup?

    It shouldn't really matter which creature gets spawned by the SpawnerSpawnEvent as they are handled the same (naturally and because his code doesn't differentiate between them).
    Killing any spawned chickens is just a temporary fix for a problem that shouldn't exist in the first place.
     
    • Agree Agree x 1
  10. I tried this..
    Code (Text):
    @EventHandler
        public void onEntitySpawn(SpawnerSpawnEvent event) {
            Location location = event.getSpawner().getLocation().subtract(0, 1, 0);
            if(!(location.getBlock().getType() == Material.EMERALD_BLOCK)){
                event.getEntity().remove();
                event.setCancelled(true);
            }
        }
    Still am getting the same result.
     
  11. Do the zombies spawn?

    Edit: take a look at this https://minecraft.gamepedia.com/Chicken_Jockey#Spawning
     
  12. @darkshadow22mc
    If I have the EmeraldBlock placed underneath the spawner, the zombies spawn but not the chickens.
    If I do not have the EmeraldBlock placed underneath the spawner, the zombies do not spawn, but the chickens do spawn.
     
  13. Look my previous message, edited
     
  14. I still don't understand how the chickens are spawning from a zombie spawner if I am cancelling the event.

    EDIT: After setting the event priority to HIGHEST, The chickens do not seem to be spawning anymore.
    Thank you all for your help, I hope this has solved it completely.
     
Thread Status:
Not open for further replies.