Spawners

Discussion in 'Plugin Development' started by DoggyCode™, Jul 27, 2015.

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

    DoggyCode™

    Do anyone know how I can convert a ItemStack MOB_SPAWNER to a specific mob spawner? How should I make the instances? If anyone have any examples then that would be great!

    Cheers!
     
  2. Offline

    SuperOriginal

  3. Offline

    DoggyCode™

  4. Offline

    SuperOriginal

    Well that's the CreatureSpawner class, which is a blockstate and even has a method to set spawn types. Not sure what else you need.
     
  5. Offline

    DoggyCode™

    @SuperOriginal It's not a block I'm talking about.. it's a ItemStack.
     
  6. Offline

    lilian58660

    Code:
        @EventHandler
        public void onPlace(BlockPlaceEvent e) {
            if ((e.getBlockPlaced().getType().equals(Material.MOB_SPAWNER))
                    && (e.getItemInHand().hasItemMeta())
                    && (e.getItemInHand().getItemMeta().hasDisplayName())
                    && (CreatureType.fromName(e.getItemInHand().getItemMeta()
                            .getDisplayName().replace(" SPAWNER", "")) != null))
                ((CreatureSpawner) e.getBlockPlaced().getState())
                        .setCreatureTypeByName(e.getItemInHand().getItemMeta()
                                .getDisplayName().replace(" Spawner", ""));
    
        }
      
      
      
      
      
        @EventHandler
        public void onBreakez(BlockBreakEvent e) {
              
                if ((e.getBlock().getType().equals(Material.MOB_SPAWNER))){
                        ItemStack spawnerStack = new ItemStack(e.getBlock().getType());
                        ItemMeta im = spawnerStack.getItemMeta();
                        im.setDisplayName(((CreatureSpawner) e.getBlock().getState())
                                .getCreatureTypeName().toUpperCase() + " SPAWNER");
                        spawnerStack.setItemMeta(im);
                        spawnerStack.setDurability(((CreatureSpawner) e.getBlock()
                                .getState()).getSpawnedType().getTypeId());
                  
                }
        }
      
      
        
    I used these methods for do it ^^
    I just give you general lines ^^
     
    Last edited: Jul 27, 2015
  7. Offline

    DoggyCode™

    Yea, ItemStack xD

    @lilian58660 Thanks! But can you tell me how that works?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
Thread Status:
Not open for further replies.

Share This Page