How do I get the data value from a block?

Discussion in 'Plugin Development' started by Codex Arcanum, Dec 24, 2011.

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

    Codex Arcanum

    Thread title says it all. How do I get the data value of a block that has already been placed? I don't believe the .getdata() method is what I'm looking for (since it returns a byte rather than an integer), and I'd really appreciate it if someone would answer my beginner question. Thanks.
     
  2. Offline

    coldandtired

    Do you mean for example the colour of a block of wool? If so then it is getData().
     
  3. Offline

    Chiller

    block.getTypeId();
     
  4. That gets the ID of the block. So if were any color of wool, it would return 35.
     
  5. Offline

    Codex Arcanum

    OK. In that case, how do I convert the result of .getdata() (which is a byte, if you notice) to an integer I can use?
     
  6. Offline

    Sagacious_Zed Bukkit Docs

  7. Offline

    Codex Arcanum

    Thanks. Think that clears t his up :).
     
  8. Offline

    bergerkiller

    @Codex Arcanum if you ever want to use one of the Material classes around, you can do that too:
    Code:
    Rails rails = (Rails) block.getType().getNewData(block.getData());
     
  9. Offline

    Codex Arcanum

    I'm sure that'll come in handy at some point, thanks.
     
  10. You don't even need the casting, you can just do this:
    Code:
    int data = block.getData();
    Because you can store smaller numbers into bigger ones, short and byte into integer.
    But, byte uses alot less memory than int, you could just store it as byte as well.
     
Thread Status:
Not open for further replies.

Share This Page