Water and Creeper Spawners

Discussion in 'Spigot Plugin Development' started by bmac20, May 10, 2017.

  1. How would I go about checking to see if water was protecting a spawner from tnt or creeper explosions? Basically I want the spawner to blow up even if it is surrounded by water.
  2. This is something that is commonly used while making obsidian breaker plugins.
    Check if a tnt blast effects the spawner by checking all blocks in a radius. If it's a spawner, ignore any water and break it.
    Hint: The event you need to use doesn't check for water by default.
  3. Oh alright. Thank you very much :)
  4. Of course. Let me know if you need further help with this or anything else.
  5. Hey so this is what I have so far:
    Code (Text):
        public void onExplode(EntityExplodeEvent e) {

            for (Block b : e.blockList()) {

                if (b.getType() == Material.MOB_SPAWNER) {
                    e.getEntity().getWorld().dropItem(b.getLocation(), new ItemStack(Material.OBSIDIAN));



    I'm using the obsidian for testing purposes atm, but the spawner does not break when in water, and the obsidian does not drop either.
  6. Don't check the block list, just have a method to check blocks within X amount of blocks from the entity and if they are mob spawners, break them/drop them.
  7. The issue with #blockList() is that it only gets the affected blocks. You need to create a radius of blocks (Should probably use 1, but can be anything really) and check if each block is a mob spawner. If it is, break/drop it.

    That was probably confusing, so to clarify, define a radius using 3 nested for loops.
    Code (Text):
    for (blocks in x radius) {
      for (blocks in y radius) {
        for (blocks in z radius) {
          if (is mob spawner) {
            break it
  8. Thank you. This is what I have so far, but I'm a bit confused on how I would actually get the blocks. And couldn't this cause issues because blowing up blocks because the explosion does not create a perfect radius?
  9. Use the for loop to go through all the blocks around the tnt that explodes, if it is a spawner, break it.
  10. Exactly what @Futurize said. Without spoonfeeding, here's what I'll give you:
    Use the X, Y, Z numbers from the loop to adjust the Block (capitalized on purpose :)) that you are checking. Then check if the block type is a mob spawner. If it is, break it, if it isn't ignore it.