spawning a mob

Discussion in 'Plugin Development' started by rodituscience, Dec 17, 2017.

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

    rodituscience

    Well im learning and i cant understand how to spawn a mob, because guy who is teaching this explained it so badly.
    I just want to spawn x1 zombie on my custom coordinates when tnt is placed by player anywhere on the map.
    You can just copy the code, but if you could explain how it works it would be awesome :).
     
  2. Offline

    Zombie_Striker

    @rodituscience
    Here is what you want to do:
    1. Listen to the BlockPlaceEvent.
    2. Check if the type of block placed is equal to TNT. If so, tnt has been placed somewhere in the world.
    3. If the above is true, use World#spawnEntity(LOCATION, EntityType.ZOMBIE) to spawn an entity. Replace "World#" with the instance of the world that you want to spawn the zombie in (If it is the same world that the player is in, use Event#getPlayer().getWorld())
     
  3. Offline

    DelfikPro

    Code:
    @EventHandler
    public void onBlockPlace(BlockPlaceEvent e) {
      if (!e.getBlock().getType()  != Material.TNT) return;
      e.getPlayer().getWorld().spawnEntity(new Location(e.getPlayer().getWorld(), X, Y, Z), EntityType.ZOMBIE);
    }
    
    Just put your coordinates instead of X, Y and Z.
     
Thread Status:
Not open for further replies.

Share This Page