Help get Id from Block

Discussion in 'Plugin Development' started by Omel, May 3, 2016.

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

    Omel

    Hello i want to get this Int 322:1 < This int behind the double point how do i get it?
     
  2. Offline

    MatsExe

    new ItemStack(Material.getMaterial(322), 1, (byte) 1);

    the byte value is your number behind the colon.
     
  3. That's called metadata. Maybe search for a method like "getMetadata".

    @MatsExe First, don't spoonfeed, then maybe put your code into Code tags and I don't think that's what Omel wanted to do. I think he wanted to know about getting the metadata value from an existing block, you posted how to create an ItemStack with metadata..
    Oh and instead of getting a Material by an id, use Material.GOLDEN_APPLE :D
     
    Last edited: May 3, 2016
  4. Offline

    Omel

    I want to check if the id behind the double point > 0
     
  5. Offline

    I Al Istannen

    @Omel
    String#split(":") And then grab the second one (i.e. index 1). Make sure the array length is long enough before though. For the future: split takes a RegEx, so be careful with what you put in there or wrap it in a Pattern#quote(String).
    You can then try to parse it with Integer.parseInt(String). This can throw a NumberFormatException if the number is not valid. Handle it.
     
Thread Status:
Not open for further replies.

Share This Page