Solved Carrots/Potatoes Not Recognized

Discussion in 'Plugin Development' started by Smeary_Subset, Sep 12, 2022.

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

    Smeary_Subset

    I'm making a plugin that harvests crops and puts them in your inventory when you right click them with a hoe. I have a method that checks whether a player right clicked wheat, carrots, potatoes or beetroot. However, it only correctly returns true when the player clicks wheat. When the player clicks carrots, potatoes, or beetroots, it returns false even though they are clearly clicking them.

    I set up some testing messages that displays what's going on in the backround (see screenshot). It clearly shows that even though the clicked block type is carrots, potatoes or beetroot it returns false.

    upload_2022-9-12_17-8-15.png

    The code for the method:

    Code:
        private boolean rightClickedCrop(Action action, Material clickedBlockMat) {
            return action == Action.RIGHT_CLICK_BLOCK &&
                    (clickedBlockMat == Material.WHEAT || clickedBlockMat == Material.CARROT ||
                            clickedBlockMat == Material.POTATO || clickedBlockMat == Material.BEETROOT);
        }
    The code that sends the messages:
    Code:
            player.sendMessage("Clicked block: " + crop);
            player.sendMessage("Right Clicked Crop: " + rightClickedCrop(event.getAction(), crop));
    The 'crop' variable is the material of the clicked block in PlayerInteractEvent.


    I find this super weird. Am I missing something obvious?
     
  2. Offline

    CraftCreeper6

  3. Offline

    Smeary_Subset

    Woah, didn't even realize there were two different materials for each. That worked. Thank you so much you're goated
     
Thread Status:
Not open for further replies.

Share This Page