Block type & data casted to Directional or BlockFace

Discussion in 'Plugin Development' started by Digi, Dec 22, 2011.

Thread Status:
Not open for further replies.
  1. I need to rotate and flip some structures and I got to the point where I need to "rotate" individual blocks by changing their data, basically I need to input block type and data to something and get the Directional or BlockFace class of it.

    I tried a code I found in a search result modified to my needs:
    Code:
    MaterialData mat = Material.getMaterial(stored.type).getNewData(stored.data);
    Directional matDir = ((Directional)mat);
    But it can't cast from MaterialData to Directional :/
    Also, I don't have access to the Block class, I just have the type and data values.
    Anyone got an ideea how to solve this ?

    An alternative would be to store the blockface when I copy the blocks, but that would mean more memory usage that's really unrequired since I have all I need in the "data" field.
     
  2. Offline

    unicode21B9

    Try this:
    Code:
    MaterialData mat = Material.getMaterial(stored.type).getNewData(stored.data);
    if (mat instanceof Directional) { //has a direction, i.e. is rotatable
        Directional matDir = ((Directional)mat);
    } else //not rotatable
    
     
  3. Hmm yeah I forgot to check if each individual block types can be rotated =) damn lack of sleep.
    Well, that works, thanks :}

    Now for the next thing... anyone got an ideea how to quickly "rotate" through the block faces ? I mean *all* block faces: N, NE, NNE, S, SW, etc.
    For flip I think .getOppositeFace() works just fine for signs too... but I'll test that out.

    EDIT: dammit, it doesn't pass the condition on all directional blocks, stairs for example.
    EDIT: it seems smooth and nether stairs don't have directional interface... :/
     
Thread Status:
Not open for further replies.

Share This Page