Solved ItemMeta & ItemStacks

Discussion in 'Plugin Development' started by amatokus, Jan 31, 2015.

Thread Status:
Not open for further replies.
  1. Hi bukkit users!
    I'm posting here because I'm have some problems with 2 pieces of my code.

    I'm using Bukkit 1.7.10.
    The first one: (open)

    Code:
        ItemStack IMine = new ItemStack(Material.IRON_PICKAXE);
        ItemMeta meta = IMine.getItemMeta().setDisplayName("test");
    I'm having an error on the .setDisplayName("test");
    Type mismatch: cannot convert from void to ItemMeta



    The second preblem: (open)

    first possibility:
    Code:
        ItemStack rails = new ItemStack(Material.RAILS,64);
    
        [...] .setIngredient('R', rails);
    I'm having the error on the .setIngredient('R', rails);
    The method setIngredient(char, MaterialData) in the type ShapedRecipe is not applicable for the arguments (char, ItemStack)

    So how should I make an ItemStack become MaterialData?


    second possibility:
    Code:
                .setIngredient('R', Material.RAILS, 64)
    The method setIngredient(char, Material, int) from the type ShapedRecipe is deprecated.
    Is this ok? :s



    Thanks poeple.
     
  2. Offline

    RainoBoy97

    1. ItemMeta#setDisplayName is void, it doesnt return anything.
    2. Yes, its fine to use it even though it's deprecated.
     
    amatokus likes this.
  3. Offline

    mine-care

    Error one:
    U assign a itemMeta class variable to a method that returns nothing... (Read about Java methods and objects)

    Error two:
    Deprivation doesn't mean it's not working, read documentarians to find out why it is deprecated also u can use setIngredietn('R',new ItemStack(type,amount));
     
  4. Thanks for question 2. but how should I do it for the first one? I just want to create a new item and rename it...

    By the way I'm having a problem with bukkit.

    Does someone knows how to fix it? ^^' thanks!

    @RainoBoy97 @mine-care thanks!

    @mine-care actually this doesn't work:


    .setIngredient('R', new ItemStack(Material.RAILS,64))

    The method setIngredient(char, MaterialData) in the type ShapedRecipe is not applicable for the arguments (char, ItemStack)
     
    Last edited by a moderator: Jan 31, 2015
  5. Offline

    mine-care

    Oh my fault it accepts MaterialData look it up on da web you'll find more =] I only played with crafting recipes once in my life ;3
     
  6. @mine-care I don't see what I can do with it ><
     
  7. Offline

    leon3001

  8. @leon3001 Thank you. But I still don't see how to rename my new item.
     
  9. Offline

    nverdier

    @amatokus ItemMeta#setDisplayName(String name)
     
  10. Offline

    caderape

    ItemMeta ita = item.getitemMeta();
    ita.setdisplayname("");
    item.setitemmeta(ita);

    @amatokus
     
  11. @caderape It's what I'm doing! But it gives me an error, see post 1 problem1
     
  12. Offline

    caderape

    It's not what you're doing in your post.
    getitemMeta.setdisplayname() will do nothing if u dun assign after the meta to the item.
    item.setitemmeta(ita);
    @amatokus
     
  13. @caderape I tried this:

    Code:
        ItemStack IMine = new ItemStack(Material.IRON_PICKAXE,1);
        ItemMeta IMMeta = IMine.getItemMeta().setDisplayName("test");
        IMine.setItemMeta(IMMeta);
    But I'm having errors... :

    line2: Type mismatch: cannot convert from void to ItemMeta
    line3:
    Multiple markers at this line
    - Syntax error on token "IMMeta", VariableDeclaratorId expected after
    this token
    - Syntax error on token(s), misplaced construct(s)

    :-/

    Ok I just fixed it, I forgot to put it in the onEnable() ...

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Feb 1, 2015
  14. Offline

    MiniDigger

    Use this
    Code:
    ItemStack IMine = new ItemStack(Material.IRON_PICKAXE,1);
    ItemMeta IMMeta = IMine.getItemMeta();
    IMMeta.setDisplayName("test");
    IMine.setItemMeta(IMMeta);
     
Thread Status:
Not open for further replies.

Share This Page