Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Instanceof food?

Comments in 'Plugin Development' started by thebigsmileXD, Oct 20, 2015.

  1. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Is there a way to test if an item is food?
    I'll use the item on an entity, so its not PlayerItemConsumeEvent
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    if($item->getId() === Item::TheFoodYouWant){
    // Do something
    }
    You'll need to define $item as the item of the Player/Entity.
  3. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Where is the downvote button?
    No. I want to test IF and item is food, not checking every food by myself
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Well.. then put all foods you know in an array.
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    There's no way to check it like that, as all the food only is instanceof Item.
    thebigsmileXD likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    There is plan to make it possible through an `instanceof Food` check, but not possible yet currently.

Share This Page

Advertisement