Mob Spawner types

Discussion in 'Plugin Development' started by inventorman101, Jul 29, 2013.

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

    inventorman101

    Hi,

    I am new to spawners and was wondering how do you set a spawner to a specific entity when it is placed?
     
  2. Offline

    xTrollxDudex

    inventorman101
    It's in the CreatureSpawner class.
    PHP:
    //block place
    Block b event.getBlock();
    if(
    b.getType.equals(Material.MOB_SPAWNER){
    CreatureSpawner cs = (CreatureSpawnerb;

    cs.setSpawnedType(EntityType.ZOMBIE)
    }
     
  3. Offline

    inventorman101

  4. Offline

    xxMOxMOxx

    inventorman101
    If you want to set it before its placed I think you can use
    Code:
    item.setDurability()
     
    inventorman101 likes this.
  5. Offline

    inventorman101

    I am getting a weird error when I place the spawner here is my code and the stack trace

    Code:java
    1.  
    2. public class Event implements Listener
    3. {
    4.  
    5. @EventHandler(priority = EventPriority.NORMAL)
    6. public void onBlockPlace(BlockPlaceEvent e)
    7. {
    8. Player p = e.getPlayer();
    9.  
    10. if (p.getItemInHand() != null)
    11. {
    12. if(itemCheck(p, "Creeper Cage")==true)
    13. {
    14. Block creeperspawner = e.getBlock();
    15. if(creeperspawner.getType().equals(Material.MOB_SPAWNER))
    16. {
    17. CreatureSpawner cs = (CreatureSpawner) creeperspawner;
    18.  
    19. cs.setSpawnedType(EntityType.CREEPER);
    20. cs.update();
    21. }
    22.  
    23. }
    24.  
    25.  
    26. else if(itemCheck(p, "Skeleton Cage")==true)
    27. {
    28. p.sendMessage("skelton cage");
    29. }
    30.  
    31. else if(itemCheck(p, "Spider Cage")==true)
    32. {
    33.  
    34. }
    35. }
    36. }
    37.  
    38.  
    39. public boolean itemCheck(Player player, String name)
    40. {
    41.  
    42. boolean returnValue = false;
    43.  
    44. ItemStack i = player.getItemInHand();
    45. if(i == null)return false; // Fail the test if there is no item in hand
    46. if(!i.hasItemMeta())return false; // Fail the test if item does not have metadata
    47. ItemMeta im = i.getItemMeta();
    48. if(!im.hasDisplayName())return false; // Fail the test if the item doesn't have a display name
    49. String dn = im.getDisplayName();
    50. List<String> lore = im.getLore();
    51. if(lore != null)
    52. {
    53. if(dn.indexOf(name) > -1)
    54. {
    55. returnValue = true;
    56. }
    57. }
    58.  
    59. return returnValue;
    60. }
    61.  
    62. }
    63.  


    StackTrace
    Code:
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_6_R2.block.Cr
    aftBlock cannot be cast to org.bukkit.block.CreatureSpawner
            at com.brendannoble.spawnercage.Event.onBlockPlace(Event.java:32)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:425)
            ... 19 more
     
  6. Offline

    foodyling

    You have to use
    for the BlockState
     
  7. Offline

    xxMOxMOxx

    I also think that
    Code:
    cs.setSpawnedType(EntityType.CREEPER)
    should be
    Code:
    cs.setSpawnedType(CreatureType.CREEPER)
     
  8. Offline

    inventorman101

    Thanks foodyling and xxMOxMOxx , it shows the creeper inside the spawner but it won't spawn anything?

    EDIT: Nevermind! I got it to work thanks guys :)
     
Thread Status:
Not open for further replies.

Share This Page