Set "BlockData" for a block.

Discussion in 'Spigot Plugin Development' started by victor2748, May 14, 2015.

  1. I am looking for a way to set the data for a block, just like the vanilla /blockdata command would do. Not the setData(byte) but the actual block properties (whether it is via json, or setting each property manually). How can I do that?

    Thank you,

    Victor
     
    • Like Like x 1
  2. Take a look at Block#getState() (the BlockState class), you can also cast that to stuff like Chest to set a chest block's contents
     
  3. I need to set a spawner to spawn withers with a certain nametag /blockdata x y z {EntityId:WitherBoss,SpawnData:{CustomName:"Name"}} I am looking for an analogy to do that with bukkit code. Casting BlockState to CreatureSpawner does not provide me that feature. is there a way to set a spawner to a certain entity (with it's characteristics)?
     
  4. Nope, sadly enough there isn't that much support for spawners.
     
  5. Actually, using some NMS it's pretty doable:
    Code (Text):
    TileEntityMobSpawner tile = ((CraftCreatureSpawner) <blockstate>).getTileEntity();
    MobSpawnerAbstract spawner = tile.getSpawner();
    NBTTagCompound tag = new NBTTagCompound();
    NBTTagCompound properties = new NBTTagCompound();
    properties.setString("CustomName", "Name");
    tag.set("Properties", properties);
    MobSpawnerAbstract.a data = new MobSpawnerAbstract.a(tag, "WitherBoss");
    spawner.a(data);
    <blockstate>.update();
    I'm not sure if it will work, because I just looked this up in the spigot jar, but I think it should work fine.
     
    • Useful Useful x 1