Mob Spawners

Discussion in 'Plugin Development' started by Mycrowut, Jul 31, 2013.

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

    Mycrowut

    Hey Everyone, I was wondering, where could I start with mob spawners? I tried setting the durability of an ItemStack from numbers 1 through 4 and they all are the pig spawners, any idea of how to do this?

    Thank you,
    -Mycro
     
  2. Offline

    Seadragon91

    You can not set the creature type in the itemstack, only if the spawner has been placed.
     
  3. Offline

    Mycrowut

    How would I go about setting the type of creature to spawn? :/
     
  4. Offline

    Seadragon91

    You could use the BlockPlaceEvent:
    Code:
    @EventHandler
    public void onBlockPlace(BlockPlaceEvent event) {
        Block block = event.getBlock();
        if (block.getType() == Material.MOB_SPAWNER) {
            CreatureSpawner cs = (CreatureSpawner) block.getState();
            cs.setSpawnedType(EntityType.SPIDER);
        }
    }
    Dont't forget to register the event.

    Edit: I played a little around with ItemMeta, you could add a display name to the item, then you have a spawner as a item with a display name pig, spider or creeper. If you want to have the display name "Mob Spawner", you can add the mob type to the lore of the ItemMeta. With one of this ways you can then get the display name / lore from the itemstack and set the mob type, works fine ;).
     
  5. Offline

    xTrollxDudex

    Mycrowut
    Get the block and cast to CreatureSpawner. Or
    PHP:
    ((CreatureSpawnere.getBlock()).setSpawnedType(EntityType.YOURTYPE);
    Edit: No way! Seadragon91
     
Thread Status:
Not open for further replies.

Share This Page