how to check block variants

Discussion in 'Spigot Plugin Help' started by kinggoesgaming, May 28, 2015.

  1. Hi

    How do i check for block variants when placing blocks or after breaking:
    For example there are 3 variant of dirt:
    Code (Text):
    DIRT (DIRT:0)
    How do i differentiate between those variants on onBlockPlace and onBlockBreak events

    Any Help Appreciated :D
  2. Code (Java):
    if ((e.getBlock().getType() == Material.DIRT) && (e.getBlock().getData() == 2))
    Would check for podzol.
  3. I tried that method for coarse dirt and didnt work.
    #1 .getType is marked as deprecated ( shows a warning)
    #2 after ignoring the warning and compiling and running the plugin, i was able to place coarse dirt when i set events to cancel coarse dirt placement and allow dirt placement.
    #3 checking on the source after that issue i discovered that .getData part was crossed out. as in strikethrough crossed out.

    Thats the reason i am confused i tried something similar to your code but that didnt work. i am 1.8.3 spigot btw.
    #3 kinggoesgaming, May 28, 2015
    Last edited: May 28, 2015
  4. Deprecation of a method doesn't mean it can't be used/doesn't work.

    This works fine for me:
    Code (Java):
        public void onPlace(BlockPlaceEvent e) {
            if (e.getBlock().getType() == Material.DIRT
                    && e.getBlock().getData() == 2) {
    If that isn't working, you're likely not registering your events.
  5. i am busy atm i was check on this later but thanks