Using Directional.setFacingDirection doesn't turn the block

Discussion in 'Plugin Development' started by ChrisixStudios, Jul 19, 2013.

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

    ChrisixStudios

    I have been working on this for a while and I can't seem to get why the Block isn't turning. Here is the code I am using.

    Code:java
    1. public BlockChange draw(World w, int x, int y, int z){
    2. Block b = w.getBlockAt(x + pt.getX(), y + pt.getY(), z + pt.getZ());
    3. BlockChange change = new BlockChange(new BlockRef(new Point3D(x + pt.getX(), y + pt.getY(), z + pt.getZ()), b));
    4. b.setType(type);
    5. b.setData(data);
    6. if(b.getState().getData() instanceof Directional){
    7. Bukkit.broadcastMessage("Applying Direction " + face.toString() + "...");
    8. ((Directional)b.getState().getData()).setFacingDirection(face);
    9. Bukkit.broadcastMessage("Block is Facing " + ((Directional)b.getState().getData()).getFacing());
    10. }
    11. return change;
    12. }


    I get an output of

    Applying Direction NORTH...
    Block is Facing SOUTH
     
  2. Offline

    Polaris29

    ChrisixStudios
    Editing the return value of "block.getState().getData()" doesn't edit the BlockState
    You have to set MaterialData with "block.getState().setData(MaterialData data)"
    The after that, you might have to use "block.getState().update(true);"
     
  3. Offline

    ChrisixStudios


    So I have to get the data and store it in a instance. Then set the state data to the instance?
    And then force the update.


    Code:java
    1. Bukkit.broadcastMessage("Applying Direction " + face.toString() + "...");
    2. Directional d = (Directional)b.getState().getData();
    3. d.setFacingDirection(face);
    4. b.getState().setData((MaterialData) d);
    5. b.getState().update(true);
    6. Bukkit.broadcastMessage("Block is Facing " + ((Directional)b.getState().getData()).getFacing());


    Same output.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  4. Offline

    Kazzababe


    I use:
    Code:
    block.setData((byte) value);
    Data values: http://www.minecraftwiki.net/wiki/Data_values
     
  5. Offline

    ChrisixStudios

Thread Status:
Not open for further replies.

Share This Page