Set spawner type

Discussion in 'Spigot Plugin Development' started by MaTaMoR_, May 15, 2015.

  1. Hey, how can i set the spawner type to a itemstack on 1.8 ?
     
  2. I don't think that this is possible, but there's kinda dirty way you could do that. Just use
    Code (Text):
    /setblock ~ ~ ~ mob_spawner 0 replace {EntityId:Creeper}
     
  3. you have to set the NBT of the stack. See the MC wiki for the exact NBT structure.
     
  4. Could you give me a example ?
     
  5. Try
    Code (Text):
    BlockState blockState = block.getState()
    CreatureSpawner spawner = ((CreatureSpawner)blockState);
    spawner.setSpawnedType(EntityType.BLAZE));
    blockState.update();
     
    • Like Like x 2
  6. "how can i set the spawner type to a ITEMSTACK"
     
  7. itemstack.setDurability((short)data);
     
    • Winner Winner x 1
  8. Try this:
    Code (Text):
    BlockState state = <spawnerblock>.getState();
    TileEntityMobSpawner tile = ((CraftCreatureSpawner) state).getTileEntity();
    MobSpawnerAbstract spawner = tile.getSpawner();
    NBTTagCompound tag = new NBTTagCompound();
    NBTTagCompound properties = new NBTTagCompound();
    NBTTagCompound item = new NBTTagCompound();
    item.setString("id", "diamond");
    item.setInt("Count", 10);
    properties.set("Item", item);
    tag.set("Properties", properties);
    MobSpawnerAbstract.a data = new MobSpawnerAbstract.a(tag, "Item");
    spawner.a(data);
    state.update();
     
  9. Yes man, but i dont wanna update the satete of a block, i wanna change the type of a itemstack.
     
  10. What do you mean? You can't do this without updating it
     
  11. It's somewhat similar.
    • Get the NMS ItemStack
    • Get the tag
    • Get the block entity tag
    • Set the data
    • Set the tag
    • Get the CraftBukkit stack
    • Set the ItemStack in the inventory.
     
  12. It sounds good but is my first time using something like that so i need some more help.
     
    #14 MaTaMoR_, May 16, 2015
    Last edited: May 16, 2015
  13. Look around in the Spigot source or in your IDE
     
  14. I will try, but will be good if you could give me a good guide link .