Check if player is holding bonemeal

Discussion in 'Plugin Development' started by Bobit, Apr 12, 2014.

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

    Bobit

    I'm trying to make some code that does something when the player is holding bonemeal. I've managed to make something happen if the player is holding, say, string, but bonemeal isn't an actual item, but a variation of one, it seems. Could someone help me with that? This link helps, but it doesn't tell everything.
     
  2. Offline

    Gater12

    Bonemeal is INK_SACK with a data value of 15.
     
  3. Offline

    Bobit

    Yeah, I got that part from the first post. But how do I test for that?
     
  4. Offline

    gorbb

    It'd be better practice to avoid using data values, as they've been deprecated. Here's some code which would get that done. :)


    Code:java
    1. //Get the 'MaterialData' of the item in the player's hand.
    2. MaterialData itemData = player.getItemInHand().getData();
    3.  
    4. //Check if it's a type of dye
    5. if (itemData instanceof Dye) {
    6. //Get the dye
    7. Dye dye = (Dye) itemData;
    8.  
    9. //Check the dye color is right.
    10. if (dye.getColor().equals(DyeColor.WHITE)) {
    11. //Player is holding bonemeal
    12. }
    13. else {
    14. //Not bonemeal (but is some other dye color)
    15. }
    16. }
    17. else {
    18. //Not dye
    19. }
     
    Bobit likes this.
  5. Offline

    Ozcr

    Just use a loop to check the players hand.
    Code:java
    1. if (p.getItemInHand().getType().equals(bonemeal)){
     
  6. Offline

    Funergy

    There isn't a Material.BONEMEAL it is if(p.getItemInhand().getType() == (new ItemStack(Material.INK_SACK, p.getItemInHand().getAmount, (byte)15))
    I didn't test the code
     
Thread Status:
Not open for further replies.

Share This Page