Give players prechanged mob spawners

Discussion in 'Plugin Development' started by Signatured, Apr 28, 2015.

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

    Signatured

    How would I go about giving a player a zombie spawner? I understand how to change a placed spawner, but is it possible to give a player a zombie spawner to hold and place?
     
  2. Offline

    Koobaczech

    Create a zombie spawner item stack and then invoke
    Code:
    p.getInventory().addItem(Spawner ItemStack);
    Or you can do this to set in a specific slot
    Code:
    p.getInventory().setItem(Spawner ItemStack);
    If you are still confused do this, and the last byte is the data, so changing that would change the mob spawner type
    Code:
    p.getInventory().addItem(new ItemStack(Material.MOB_SPAWNER, 1, (short) 0));//MOB_SPANWER is the type, 1 is the amount, short 0 is the data
    
     
    Last edited: Apr 28, 2015
  3. Actually, it's not thát easy. What you can do is set the data value of the itemstack to the right entity, and wait for a blockblaceevent, if the used item type is a mob spawner, you can detect for the datavalue. Then cast the event's block state to CreatureSpawner and use the setSpawnedType to set it to EntityType.fromId(<the item's data value>); e.g.:
    Code:
    ItemStack hand = e.getItemInHand();
    if(hand.getType() == Mataterial.MOB_SPAWNER) { //or test the block's type
      CreatureSpawner spawner = (CreatureSpawner) e.getBlock().getState();
      spawner.setSpawnedType(EntityType.fromId((int) hand.getDurability()));
    }
     
Thread Status:
Not open for further replies.

Share This Page