Solved Is there a way to get the block's EXACT material name?

Discussion in 'Plugin Development' started by BlueNova, Apr 18, 2020.

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

    BlueNova

    so i was coding today and trying to get the block that i am standing on.

    it came to me that when i stood on an OAK_LOG block, its material is called LOG
    i wanted to check if the material.OAK_LOG was the same as the LOG i got earlier or not
    and ofc, they were not equal.

    i am trying to make a block shuffle plugin where a player must stand on a prompted block under 5 mins

    and if the player is prompted to stand on ANDESITE.. when they find it the block.getType() is called STONE

    this makes the game overly easier and unfun.

    I would LOVE anyone that can tell me how to get the specific material of a block
     
  2. Offline

    KarimAKL

    @BlueNova That was changed in 1.13, you're using an old version.

    For versions below 1.13, check the data/durability as well.
     
  3. Offline

    BlueNova

    i am using Bukkit 1.15.2

    @KarimAKL

    can u please elaborate on how i would do that above 1.13?

    my line of code is exactly so

    Code:
    Block b = loc.getBlock();
    Material blockMat = Material.getMaterial(b.getType().toString())
    
     
  4. Offline

    bowlerguy66

    This shouldn't be a problem in 1.15.2. Can I ask why you're writing it as
    Code:
    Material blockMat = Material.getMaterial(b.getType().toString());
    Why not use
    Code:
    Material blockMat = b.getType()
     
  5. Offline

    BlueNova

    @bowlerguy66
    i was purely trying different ways and checking if this will get me anywhere to where i want it to be.

    i tried it and when i stood on a spruce log it messages me that i am standing on LOG

    OK !!!!

    so i fixed it by getting the block.getBlockData() becuase this contains the phrase "oak_planks" in the data

    i transformed the blockData to string and checked it with the .contains() with whatever block i got. this allowed me to get very VERY specific into the types of blocks i could add to my game!!

    this thread is marked as solved and i hope someone learns smth new from this.

    PS: getting Block.getType() still returns "LOG" and not specific types of log.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 18, 2020
  6. Offline

    bowlerguy66

    Can you confirm what bukkit file that you have in your plugin's build path is 1.15.2? I just tested it myself and I got SPRUCE_LOG.

    LOG doesn't exist in the Material enum

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  7. Offline

    BlueNova

    @bowlerguy66
    I just did. i AM using 1.15.2 and Material SPRUCE_LOG exists but when i check a block at a specific location (the block beneath me) and use Block.getType().toString() it will be LOG for some reason
     
  8. Offline

    KarimAKL

    @BlueNova Try Material#name() instead of Material#toString().
     
Thread Status:
Not open for further replies.

Share This Page