Solved Getting all food values?

Discussion in 'Plugin Development' started by shohouku, Jul 30, 2014.

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

    shohouku

  2. shohouku Easiest way is to just make your own list of Materials that are actually food.
     
    shohouku likes this.
  3. Offline

    shohouku


    Sounds like a good idea!

    Thanks
     
    AdamQpzm likes this.
  4. Offline

    Goblom

    shohouku Damn, solved already, but there is a method in the Material that returns true if material is edible...
    Code:java
    1. Material.TYPE.isEdible()

    Code:java
    1. public static List<Material> getFoods() {
    2. List<Material> list = new ArrayList();
    3. for (Material mat : Material.values()) {
    4. if (mat.isEdible()) {
    5. list.add(mat);
    6. }
    7. }
    8.  
    9. return list;
    10. }
     
    AdamQpzm and shohouku like this.
  5. Offline

    shohouku



    Hmh, I tried setting the lore of the items in the function onEnable and it doesn't work. I'v tested it on PlayerJoinEvent and it works when I add it to the players inventory.

    How would it work in onEnable?

    Code:java
    1. Material[] energy =
    2. {Material.APPLE,
    3. Material.GOLDEN_APPLE,
    4. Material.GOLDEN_CARROT,
    5. Material.BREAD,
    6. Material.PORK,
    7. Material.COOKED_BEEF,
    8. Material.COOKED_CHICKEN,
    9. Material.COOKED_FISH,
    10. Material.COOKIE,
    11. Material.RAW_BEEF,
    12. Material.RAW_CHICKEN,
    13. Material.RAW_FISH,
    14. Material.COOKED_FISH,
    15. Material.POISONOUS_POTATO,
    16. Material.POTATO,
    17. Material.MUSHROOM_SOUP,
    18. Material.MELON,
    19. Material.CAKE};
    20.  
    21. for(Material m : energy) {
    22. ItemStack test = new ItemStack(m);
    23. ItemMeta meta = test.getItemMeta();
    24. ArrayList<String> description = new ArrayList<String>();
    25. description.add(ChatColor.ITALIC + "<Food>");
    26. meta.setLore(description);
    27. test.setItemMeta(meta);
    28.  
    29. }
     
  6. shohouku You don't do anything with the ItemStack you create, other than set some meta on it. What are you actually trying to do?
     
  7. Offline

    shohouku


    I'm just setting the food lore to "<Food>" from onEnable,

    and what did you mean by set some meta on it?
     
  8. shohouku Just because you set the lore on a single itemstack, doesn't mean it'll automatically set that on all itemstacks of the same type :)
     
  9. Offline

    shohouku


    I see...

    So best way is to do it manually? (creating 1 stack with the same lore)

    Or is there a better way?
     
  10. shohouku Each ItemStack represents an actual item stack in-game (i.e. the type that you can have in your inventory), so if you wanted their food to have that lore (which is most likely a wasted effort, in my opinion) you need to apply it to the stack that they actually have (i.e. have it applied when you give them the food, or when they pick it up or take it from an inventory)
     
    shohouku likes this.
  11. Offline

    shohouku


    Hmh, I was wondering if you could override the default minecraft items, looks like it would need some packets but I guess I'll have to do it like the way you're saying for the moment.

    Thanks!
     
    AdamQpzm likes this.
Thread Status:
Not open for further replies.

Share This Page