Solved No way to Set a block data without using Block.Setdata() ?

Discussion in 'Plugin Development' started by SunShe, Dec 23, 2013.

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

    SunShe

    Hi, im trying to change the wool color of an existent white wool block without using the old deprecated method.

    I have tryed something like that, but seeing no changes in the game.

    At the change part of my code:

    Code:java
    1. MaterialData state = block.getState().getData();
    2. if (state instanceof Wool) {
    3. ((Wool) state).setColor(DyeColor.RED);
    4. block.getState().setType(Material.WOOL);
    5. block.getState().setData(state);
    6. block.getState().update(true);
    7. }


    Did i something wrong? Or maybe my approach is wrong, if someone can lighting me about that please...
     
  2. Offline

    Eniripsa96

    I haven't done too much with this but try getting the BlockState once, setting everything to that instance, and updating that instead of getting it each time. If it's anything like ItemMeta, each time you use getState() it would be a new instance.
     
  3. Offline

    SunShe

    How to do that? in one instance...
     
  4. Offline

    Eniripsa96

    Code:java
    1. BlockState state = block.getState();
    2. MaterialData data = state.getData();
    3. if (data instanceof Wool) {
    4. ((Wool) data).setColor(DyeColor.RED);
    5. state.setData(data);
    6. state.update(true);
    7. }
     
  5. Offline

    SunShe

    Ok nice, it works, you were right! Thank you so much.
     
Thread Status:
Not open for further replies.

Share This Page