Solved Check if player breaks a fern or large fern

Discussion in 'Plugin Development' started by Mr_Gibbles, Jul 12, 2015.

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

    Mr_Gibbles

    I just recently got back into coding and I'm stuck trying to check if a player breaks a fern or a large fern block. I have the basics but I can't find out how to get the material for ferns and large ferns as it doesn't let you give an integer value after the material type like most other materials with damage values.
    Code:
    @EventHandler
        public void onBlockBreak(BlockBreakEvent event) {
            Player player = event.getPlayer();
            Material blockType = event.getBlock().getType();
            Material fern = ?
            if (blockType == fern) {
              
            }
        }
     
  2. Offline

    emericask8ur

    Code:
    if(blockType == Material.Whatever
    
     
  3. Offline

    SuperSniper

    That's what hes trying to figure out, he doesnt know the Fern / Large Fern Material.TYPE, I dont know it either.
     
  4. Offline

    emericask8ur

  5. Offline

    Mr_Gibbles

    I know it's Material.LONG_GRASS, 2 but it doesn't let you put the 2 as a damage value so I'm not sure how to get it because otherwise you just get tall grass which isn't what I want.
     
  6. Offline

    bazsi700

  7. Offline

    Mr_Gibbles

    Last edited by a moderator: Jun 12, 2016
  8. Offline

    bcohen9685

    (short) 2
     
  9. Offline

    Mr_Gibbles

    When I do this
    Code:
    Material fern = Material.LONG_GRASS, (short) 2;
    I get this
    Code:
    Type mismatch: cannot convert from short to Material
     
  10. Offline

    bazsi700

    @Mr_Gibbles Test first for material then for damage.
     
  11. Offline

    bcohen9685

    Sorry my mistake, you do need (byte) in this situation. Try this:
    Code:
    @EventHandler
        public void onBlockBreak(BlockBreakEvent event) {
            Player player = event.getPlayer();
            Block blockType = event.getBlock();
            Material long_grass = Material.LONG_GRASS;
            if(blockType.getType().equals(long_grass) && blockType.getData() == (byte) 2){
               
            }
     
  12. Offline

    Agentleader1

    Consider using Crops, CropState, BlockState, and getting data of a block state.
     
  13. Offline

    Mr_Gibbles

    This is super late but I'm trying out this project again and I get an error on the blockType.getData() == (byte) 2 taht says
    Code:
    Incompatible operand types Class<capture#1-of ? extends MaterialData> and byte
     
  14. @Mr_Gibbles
    Don't use Material#getData(), use Block#getData()
     
  15. Offline

    Mr_Gibbles

    Oh, my bad thank you!
     
Thread Status:
Not open for further replies.

Share This Page