Solved ItemMeta Is So Hard

Discussion in 'Plugin Development' started by MagicMan, Mar 26, 2014.

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

    MagicMan

    Solved!
     
    Kiaeyi likes this.
  2. MagicMan You don't need to bump 7 minutes after making your first post. This isn't an instant free help section for any problems you're having.

    As for the problem you mentioned: Just because you add a recipe, doesn't mean that it's added to the Material enum. You can't do things like new ItemStack(iron_chest) or Material.iron_chest

    Quick question: Have you learned much about Java? You need to learn some of it, because then you'll understand the reasons why you can't do the above and it will help you quite a bit. :)
     
  3. Offline

    MagicMan


    Sorry about the bump I accidentally bumped the wrong post without noticing and as I said on my other post I just started out and I just learnt about itemmeta today :/ Sorry mate but I'm still looking for a help?
     
  4. Offline

    phildachil

    You should probably try a much easier plugin to get started with, not that this is hard but you made lots of mistakes (such as no closing brackets), it seems that this is your first plugin. I suggest learning java before learning the bukkit api.
     
  5. Offline

    MagicMan


    Actually no this isn't my plugin this is just a example of what I'm writing in my plugin but its very similar, Im recreating EE3 plugin style and don't want the code to be out until maybe I give up on the project and no one else wants to update it so I just copied and pasted a bit and changed it alot but anyway I fixed the closing brackets problem and btw my actual plugin 133 lines and thats with a extra tinkering on how to make it as small as possible without it, it would be at least over 266 :3
     
  6. MagicMan If you say so. Try something like this:
    PHP:
    ItemStack iron_chest = new ItemStack(Material.CHEST);
    ItemMeta meta iron_chest.getItemMeta();
    meta.setDisplayName("Iron Chest");
    iron_chest.setItemMeta(meta);
     
     
    ShapedRecipe recipe = new ShapedRecipe(new ItemStack(iron_chest)).shape("###""#%#""###").setIngredient('#'Material.IRON_INGOT).setIngredient('%'Material.CHEST);
    getServer().addRecipe(recipe);
     
    ShapelessRecipe a = new ShapelessRecipe(new ItemStack(Material.BEDROCK8)).addIngredient(iron_chest.getData()).addIngredient(Material.GOLD_INGOT);
    getServer().addRecipe(a);
     
  7. Offline

    MagicMan



    Works like a charm thanks mate I have question for you though, I was trying to do this but failed. Is it possible that only Iron chest will be able to craft BEDROCK not normal chests? Do anything to it add enchants, add lores as long as you can get the code it will be fine. If you can do this and it works I will definitely add you to the project credit :) Thanks Bro you've done so much for me
     
  8. Offline

    desht

  9. Offline

    MagicMan

  10. Offline

    desht

    No, I can't "post it in the format above" - that doesn't even make sense.

    If you want to restrict crafting by item meta, you must hook the PrepareItemCraftEvent. In that event handler, you need to:
    1. Check if the crafting result is the item you want to apply the restriction to (your BEDROCK item) - event.getInventory().getResult()
    2. Get the list of crafting ingredients - event.getInventory().getMatrix()
    3. If you find a chest in the ingredients which doesn't have the metadata you want (display name of "Iron Chest"), then stop the crafting - event.getInventory().setResult(null)
    The Javadocs will be helpful here, and you have enough to be going on with from the three steps above and the post I linked to - I'm not going to spoonfeed you any more code, sorry.
     
    Garris0n likes this.
  11. Offline

    MagicMan

    Oh ok thanks much better an simpler!
     
    desht likes this.
  12. Offline

    MagicMan


    Ok I kept trying but eclipse counts "event" as a mistake? What should I do ? The automatic helping thingy just loops it into more mistakes.

    Edit: You know what I just give up. This whole thing is to hard for me anyway.
     
  13. Offline

    TheLunarFrog

    That's probably because you don't know the Java language well enough. Learn it and then maybe it won't be so hard.
     
  14. Offline

    AoH_Ruthless

    MagicMan
    Learn the basics of Java first before working at all with Bukkit. You don't need to spend months learning the whole language then learn bukkit, you just need to have a grasp of the basics.
     
  15. Offline

    MagicMan

    I know I know but the only problem is I'm the type of person that will never learn unless his shown it so unless someone shows me the code for this specific code then I will never learn. Don't get me wrong I'm the smartest person in my grade but thats because I have a great memory and I can remember anything. I can never learn anything without the Hands On Experience.
     
  16. Offline

    AoH_Ruthless

    MagicMan
    Being given code isn't the hands-on experience. The hands-on experience is literally practicing. What you have to do to learn code is learn something, and then immediately go and practice with it. It's like learning a language - You will never be fluent without practice. The same goes with programming.

    Being the smartest person in your grade is completely irrelevant. A complete retard can learn Java if they demonstrate the will and the work ethic necessary to succeed.
     
  17. Offline

    MagicMan


    Ok one more question. Do you have any videos or text that will teach me how to code Java for Minecraft?
    I watched a couple of videos but they don't help learning java they just write it out for us. I tried lots of sites but they teach me how to use parts of Java that aren't important to Minecraft. Could you send me a specific video thanks!
     
  18. Offline

    Juicyzbox

    All those parts are important to Minecraft. Try YouTube or even the main java website.
     
  19. Juicyzbox Actually disagreed. The standard Java library is rather vast indeed, I very much doubt that everything you could learn about Java are important to minecraft.

    MagicMan At least look at the basics. You could use Oracle's official tutorial. http://docs.oracle.com/javase/tutorial/
     
  20. Offline

    Juicyzbox

    AdamQpzm well I'm not actually sure what he watched but most likely if it is a beginning tutorial which seems the first place people would logically start would be something like imports, classes, variables, data structures, statements. I was assuming these would be the videos.

    I do agree that java is a ton of the library would not be needed for mine craft but who starts out a java tutorial on say something like GUI or graphics. I'm sure he started somewhere basic and he seems to think it is not important to java possibly.

    Of course this all hinges on what exactly he watched.
     
    AdamQpzm likes this.
  21. Offline

    MagicMan

    Thanks guys <3
     
  22. Offline

    MagicMan




    Hey guys since you helped me so greatly before I thought you could do it again. So I went ahead and learnt java and fixed my code but there is one problem.

    Show Spoiler
    @EventHandler
    public void restrictCrafting;PrepareItemCraftEvent event; {


    String minium_stone = ChatColor.RED + "Minium Stone";

    if (event.getRecipe().getResult().hasItemMeta() && MINIUM_STONE.equals(event.getRecipe().getResult().getItemMeta().getDisplayName())) {
    // this is our custom item - make sure all three ingredients are found
    boolean found1 = false, found2 = false, found3 = false;
    for (ItemStack item: event.getInventory().getMatrix()) {
    if (item != null && item.hasItemMeta()) {
    if (MINIUM_STONE.equals(item.getItemMeta().getDisplayName())) {

    }
    }
    }
    if (!found1) {
    event.getInventory().setResult(null);
    }
    }
    }


    In eclipse it tells me that public void is a invalid type of restrictCrafting so could you tell me what the correct version is? I tried static, class (THAT DOES NOT END WELL) ect ect. Also could you point out any other mistakes that eclipse could've missed. Thanks you guys are the best!
     
  23. Offline

    Juicyzbox

    public void restrictCrafting(PrepareItemCraftEvent event) {
    //code
    }
     
  24. Offline

    MagicMan


    Thank you so much <3

    But someone still has to tell me its not public void so what is it?

    NVM I SOLVED IT

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page