Solved Custom crafting recipes help

Discussion in 'Plugin Development' started by iLiveorLose, Apr 15, 2016.

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

    iLiveorLose

    Hi, so I've created a custom crafting recipe that creates a shiny emerald block (no big deal, it works) then when I try to use that emerald block in another recipe it doesn't work. I searched the internet for solutions, none found, so I'm resorting to here! Please help. Thanks in advance, iLiveorLose.
     
  2. Offline

    opd02

  3. Offline

    iLiveorLose

    I know how to craft items with custom names... I'm just trying to use those items that I craft in other crafting recipes.
     
  4. Offline

    opd02

  5. Offline

    iLiveorLose

    Its fine man, but I used that link and I still have the same problem. On line 67, where it says "sbrecipe.setIngredient('E', emeraldblock);"
    It says "Change type of 'emeraldblock' to 'MaterialData'", and the reason for this error is because
    "The method setIngredient(char, MaterialData) in the type ShapedRecipe is not applicable for the arguments (char, ItemStack)" Please help!
     
  6. Offline

    opd02

    So what you have to is make a CraftItemEvent and check if the Item you want, like named ItemStack is in the location of the crafting bench. Its totally different then the ShapedRecipie methods. So in the ShapedRecipie methods that you make, just set it as a NORMAL Material.Emerald_Block, then in the CraftItemEvent put an if statement checking if the item in the middle slot(Or where ever you want the named item to be) is equal to an ItemStack that is the Named EmeraldBlock. Im not that good at explaining, want to me made some code? If so, give me your code please!
     
  7. Offline

    iLiveorLose

    Code:
    package me.liveorlose.megaslime;
    
    import java.util.Arrays;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.EntityType;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MegaSlime extends JavaPlugin implements Listener {
    
        public static ItemStack emeraldblock = new ItemStack(
                Material.EMERALD_BLOCK, 1);
        {
            emeraldblock.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta emeraldmeta = emeraldblock.getItemMeta();
            emeraldmeta.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD
                    + "Shiny emerald block");
            emeraldmeta.setLore(Arrays.asList(ChatColor.GREEN
                    + "This emerald block", ChatColor.GREEN + "is enchanted with",
                    ChatColor.GREEN + "an odd " + ChatColor.GOLD.toString()
                            + ChatColor.BOLD + "presence" + ChatColor.GREEN + "."));
            emeraldblock.setItemMeta(emeraldmeta);
        }
    
        public static ItemStack slimeball = new ItemStack(Material.SLIME_BALL, 1);
        {
            slimeball.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta slimeballmeta = slimeball.getItemMeta();
            slimeballmeta.setDisplayName(ChatColor.GREEN.toString()
                    + ChatColor.BOLD + "Mega slimeball");
            slimeballmeta.setLore(Arrays.asList(ChatColor.GREEN
                    + "This mega slimeball",
                    ChatColor.GREEN + "came directly from",
                    ChatColor.GREEN + "the " + ChatColor.GREEN.toString()
                            + ChatColor.BOLD + ChatColor.UNDERLINE + "Mega Slime "
                            + ChatColor.RESET.toString() + ChatColor.GREEN
                            + "itself."));
            slimeball.setItemMeta(slimeballmeta);
        }
    
        public void onEnable() {
            shrecipe();
            sbrecipe();
        }
    
        @SuppressWarnings("deprecation")
        public void shrecipe() {
            ShapedRecipe shrecipe = new ShapedRecipe(emeraldblock);
            shrecipe.shape("@@@", "@[email protected]", "@@@");
            shrecipe.setIngredient('@', Material.MONSTER_EGG,
                    EntityType.SLIME.getTypeId());
            shrecipe.setIngredient('X', Material.EMERALD_BLOCK);
            Bukkit.getServer().addRecipe(shrecipe);
        }
    
        public void sbrecipe() {
            ShapedRecipe sbrecipe = new ShapedRecipe(slimeball);
            sbrecipe.shape("EEE", "ESE", "EEE");
            sbrecipe.setIngredient('S', Material.SLIME_BALL);
            sbrecipe.setIngredient('E', emeraldblock);
        }
    }
    
    That's my code so far, how would I do this?

    @opd02
    Okay, I fixed the original issue. In the area where it takes a material, I did shrecipe.getRecipe().getData(). I looked at the guy's thread a few below mine, which I should have done a while ago. Except, the hilarious thing is, now I have the same exact problem as HIM, which is that I can just use 8 NORMAL slimeballs around the slime egg to create the Slime King egg, instead of using 8 mega slimeballs (which are much harder to get, you have to go through a lot of crafting).
    Does anyone know a fix for this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 17, 2016
  8. Offline

    iLiveorLose

  9. Offline

    opd02

    Here:
    Code:
    package me.opd02.help;
    
    import java.util.Arrays;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.CraftItemEvent;
    import org.bukkit.inventory.CraftingInventory;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Core extends JavaPlugin implements Listener{
        public void onEnable(){
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            //
            ShapedRecipe shrecipe = new ShapedRecipe(emeraldblock);
            shrecipe.shape("@@@", "@[email protected]", "@@@");
            shrecipe.setIngredient('@', Material.MONSTER_EGG);
            shrecipe.setIngredient('X', Material.EMERALD_BLOCK);
            Bukkit.getServer().addRecipe(shrecipe);
            //
            ShapedRecipe sbrecipe = new ShapedRecipe(slimeball);
            sbrecipe.shape("EEE", "ESE", "EEE");
            sbrecipe.setIngredient('S', Material.SLIME_BALL);
            sbrecipe.setIngredient('E', Material.EMERALD_BLOCK);
        }
        public void onDisable(){
            Bukkit.getServer().clearRecipes();
        }
        public static ItemStack emeraldblock = new ItemStack(
                Material.EMERALD_BLOCK, 1);
        {
            emeraldblock.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta emeraldmeta = emeraldblock.getItemMeta();
            emeraldmeta.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD
                    + "Shiny emerald block");
            emeraldmeta.setLore(Arrays.asList(ChatColor.GREEN
                    + "This emerald block", ChatColor.GREEN + "is enchanted with",
                    ChatColor.GREEN + "an odd " + ChatColor.GOLD.toString()
                            + ChatColor.BOLD + "presence" + ChatColor.GREEN + "."));
            emeraldblock.setItemMeta(emeraldmeta);
        }
        public static ItemStack slimeball = new ItemStack(Material.SLIME_BALL, 1);
        {
            slimeball.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta slimeballmeta = slimeball.getItemMeta();
            slimeballmeta.setDisplayName(ChatColor.GREEN.toString()
                    + ChatColor.BOLD + "Mega slimeball");
            slimeballmeta.setLore(Arrays.asList(ChatColor.GREEN
                    + "This mega slimeball",
                    ChatColor.GREEN + "came directly from",
                    ChatColor.GREEN + "the " + ChatColor.GREEN.toString()
                            + ChatColor.BOLD + ChatColor.UNDERLINE + "Mega Slime "
                            + ChatColor.RESET.toString() + ChatColor.GREEN
                            + "itself."));
            slimeball.setItemMeta(slimeballmeta);
        }
        @EventHandler
        public void itemCraft(CraftItemEvent e){
            if(e.getInventory() instanceof CraftingInventory){
                ShapedRecipe shrecipe = new ShapedRecipe(emeraldblock);
                shrecipe.shape("@@@", "@[email protected]", "@@@");
                shrecipe.setIngredient('@', Material.MONSTER_EGG);
                shrecipe.setIngredient('X', Material.EMERALD_BLOCK);
                Bukkit.getServer().addRecipe(shrecipe);
                //
                ShapedRecipe sbrecipe = new ShapedRecipe(slimeball);
                sbrecipe.shape("EEE", "ESE", "EEE");
                sbrecipe.setIngredient('S', Material.SLIME_BALL);
                sbrecipe.setIngredient('E', Material.EMERALD_BLOCK);
            CraftingInventory inv = (CraftingInventory) e.getInventory();
            if(inv.getSize() != 4 && e.getRecipe()==shrecipe){
                org.bukkit.inventory.ItemStack middle = inv.getMatrix()[4];
                if(middle.hasItemMeta()){
                    if(middle.getItemMeta().getDisplayName().equals("§l§aMega slimeball")){
                    } else{
                        e.setCancelled(true);
                    }
                } else {
                    e.setCancelled(true);
                }
            }
        }
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("thisis")){
                ItemStack slimeball = new ItemStack(Material.SLIME_BALL);
                slimeball.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
                ItemMeta slimeballmeta = slimeball.getItemMeta();
                slimeballmeta.setDisplayName(ChatColor.GREEN.toString()
                        + ChatColor.BOLD + "Mega slimeball");
                slimeballmeta.setLore(Arrays.asList(ChatColor.GREEN
                        + "This mega slimeball",
                        ChatColor.GREEN + "came directly from",
                        ChatColor.GREEN + "the " + ChatColor.GREEN.toString()
                                + ChatColor.BOLD + ChatColor.UNDERLINE + "Mega Slime "
                                + ChatColor.RESET.toString() + ChatColor.GREEN
                                + "itself."));
                slimeball.setItemMeta(slimeballmeta);
                Player p = (Player) sender;
                Inventory pi = p.getInventory();
                pi.addItem(slimeball);
            }
            return true;
        }
    }
    (Un-tested) But you get what I mean?
     
  10. Offline

    JoelyBob

    Hey there!

    Check out my thread on custom crafting recipes and events :)

    https://bukkit.org/threads/custom-crafting-recipes-name-and-lore.355799/

    Edit:

    Once you have done so, you might be able to set the ingredient to a symbol. E.g:

    Code:
        customItem2.shape("%*%");
        customItem2.setIngredient('*', Material.EMERALD);
        customItem2.setIngredient('%', customItem);
        getServer().addRecipe(customItem2);
    Havent tried it out though :/
     
  11. Offline

    opd02

    @JoelyBob That actually wouldn't work seeing as the .setIngrediant method calls for a material for the second argument, not an item stack
     
  12. Offline

    mcdorli

    Can you please not spoonfeed?
     
    Zombie_Striker and Lordloss like this.
  13. Offline

    iLiveorLose

    @opd02
    Thank you very much! I will now try your code and I will edit this post to tell you if it works

    @JoelyBob
    I see you must have misread my question, (twice), I do not have a problem with creating custom recipes, but I do have a problem with using my custom items in recipes. I tried exactly what you showed me (way before you posted that reply) and it wasn't working, but I found a solution for that particular thing, and now it doesn't work because I can use plain emerald blocks to create my custom item instead of "Shiny emerald blocks". I do not mean to be rude, just next time please read the whole question :)
     
  14. Offline

    opd02

    @mcdorli
    Please don't say things like that. Some people need to actually SEE the code. I have been explaining how the code works without giving @iLiveorLose the actual code. He just needed to actually see it, no bit deal. By the way @iLiveorLose thank you for being so patient and polite, @mcdorli could learn a thing or two from you.
     
  15. Offline

    mythbusterma

    @opd02

    Seeing code is not the same as doing it for someone, and there is a difference. Especially when you don't explain what you do at all, and have serious issues with your code.

    Why are you using class init blocks?
    What happens when an item in the 5th spot has item metadata but no name?
    Why have an empty if block instead of negating the condition?
    Why are you using the equality operator on Objects?
    Why are you using ItemStack's fully qualified name?
    Avoid using the section sign to indicate color, use ChatColor instead.

    The reason we don't usually like someone giving code wholesale is that it encourages them to return here to ask their code to be written for them again, and that generates more hyper-specific threads that are not applicable to anyone. Whereas answers to general questions can be reapplied by anyone who views those threads.

    While I disagree with the way @mcdorli goes about it, he does have a point.

    TL;DR in general, prefer true example code or pseudo-code


    @iLiveorLose

    I would recommend fixing the issues I pointed out in the code before using it. There's also a way to add a recipe which requires metadata to the server's recipe list directly using reflection, but I can't find it now.
     
  16. Offline

    mcdorli

    No, there's no one, who needs to look at code to actually understand it, except if it is a very hard topic, or has close to 0 explanation (I recently worked on a project like that, but had nothing to do with Bukkit). Bukkit isn't part of the above mentioned 2 categories, it's well documented and is easy to use.

    Giving someone code missfires 70% of the time, as the one, who receives the "example" can find it overwhelming, and he /she either stops with the project completely, or simply copies the code, and learns nothing either way.

    If you really want to give code away, then post it as a util (separate class with credits and such, maybe dropbox download) or as pseudo code.

    Ask anyone, who frequently answers questions (mythbusterma, zombie_striker, lordloss, timtower, bfwcwalshy, etc.), what he thinks of spoonfeeding, and you pretty much will receive the same answer every time.

    We also don't recommend spoonfeeding, because people here mostly don't know how to code. You too have problems with it as @mythbusterma already pointed out.
     
  17. Offline

    iLiveorLose

    @opd02
    Your code wasn't very good, but I used it, also, I found another thread that had the same issue as I, but the solution isn't working for me. Here's the code:
    Code:
    package me.liveorlose.megaslime;
    
    import java.util.Arrays;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.PrepareItemCraftEvent;
    import org.bukkit.inventory.CraftingInventory;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Test extends JavaPlugin implements Listener {
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
    
        public void onDisable() {
            Bukkit.getServer().clearRecipes();
        }
    
        public static ItemStack emeraldblock = new ItemStack(
                Material.EMERALD_BLOCK, 1);
        {
            emeraldblock.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta emeraldmeta = emeraldblock.getItemMeta();
            emeraldmeta.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD
                    + "Shiny emerald block");
            emeraldmeta.setLore(Arrays.asList(ChatColor.GREEN
                    + "This emerald block", ChatColor.GREEN + "is enchanted with",
                    ChatColor.GREEN + "an odd " + ChatColor.GOLD.toString()
                            + ChatColor.BOLD + "presence" + ChatColor.GREEN + "."));
            emeraldblock.setItemMeta(emeraldmeta);
        }
        public static ItemStack slimeball = new ItemStack(Material.SLIME_BALL, 1);
        {
            slimeball.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta slimeballmeta = slimeball.getItemMeta();
            slimeballmeta.setDisplayName(ChatColor.GREEN.toString()
                    + ChatColor.BOLD + "Mega slimeball");
            slimeballmeta.setLore(Arrays.asList(ChatColor.GREEN
                    + "This mega slimeball",
                    ChatColor.GREEN + "came directly from",
                    ChatColor.GREEN + "the " + ChatColor.GREEN.toString()
                            + ChatColor.BOLD + ChatColor.UNDERLINE + "Slime King"
                            + ChatColor.RESET.toString() + ChatColor.GREEN
                            + " itself."));
            slimeball.setItemMeta(slimeballmeta);
        }
    
        @SuppressWarnings({ "deprecation" })
        @EventHandler
        public void onPrepareCraft(PrepareItemCraftEvent e) {
            ShapedRecipe shrecipe = new ShapedRecipe(emeraldblock);
            shrecipe.shape("@@@", "@[email protected]", "@@@");
            shrecipe.setIngredient('@', Material.MONSTER_EGG,
                    EntityType.SLIME.getTypeId());
            shrecipe.setIngredient('X', Material.EMERALD_BLOCK);
            Bukkit.getServer().addRecipe(shrecipe);
            //
            ShapedRecipe sbrecipe = new ShapedRecipe(slimeball);
            sbrecipe.shape("EEE", "ESE", "EEE");
            sbrecipe.setIngredient('S', Material.SLIME_BALL);
            sbrecipe.setIngredient('E', Material.EMERALD_BLOCK);
            Bukkit.getServer().addRecipe(sbrecipe);
            if (e.isRepair() || !e.getRecipe().equals(sbrecipe)) {
                return;
            }
            CraftingInventory inv = e.getInventory();
            for (ItemStack item : inv.getMatrix()) {
                if (item == null
                        || item.getItemMeta() == null
                        || item.getItemMeta().getDisplayName() == null
                        || !item.getItemMeta()
                                .getDisplayName()
                                .equals(ChatColor.GREEN.toString() + ChatColor.BOLD
                                        + "Shiny emerald block")) {
                    return;
                }
                inv.setResult(slimeball);
            }
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label,
                String[] args) {
            if (cmd.getName().equalsIgnoreCase("thisis")) {
                ItemStack slimeball = new ItemStack(Material.SLIME_BALL);
                slimeball.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
                ItemMeta slimeballmeta = slimeball.getItemMeta();
                slimeballmeta.setDisplayName(ChatColor.GREEN.toString()
                        + ChatColor.BOLD + "Mega slimeball");
                slimeballmeta.setLore(Arrays.asList(ChatColor.GREEN
                        + "This mega slimeball", ChatColor.GREEN
                        + "came directly from",
                        ChatColor.GREEN + "the " + ChatColor.GREEN.toString()
                                + ChatColor.BOLD + ChatColor.UNDERLINE
                                + "Mega Slime" + ChatColor.RESET.toString()
                                + ChatColor.GREEN + " itself."));
                slimeball.setItemMeta(slimeballmeta);
                Player p = (Player) sender;
                Inventory pi = p.getInventory();
                pi.addItem(slimeball);
            }
            return true;
        }
    }
    
    @mcdorli
    I agree with your points about spoonfeeding, but maybe instead of just going to my thread and correcting people who are actually trying to help me, you could actually help too?
     
  18. Offline

    mcdorli

    @opd02 Are you happy now? He copied it.

    What do you mean by "doesn't work"? Errors? Have you tried to debug?
     
  19. Offline

    iLiveorLose

    @mcdorli
    Well, it did the exact same thing as before. It enables me to use plain ordinary emerald blocks to create a mega slimeball, instead of using "Shiny emerald blocks". Yes, I've tried debugging. I've moved around the "addrecipes" to see if I added it later it would apply the changes, and I've tried moving the inv.setResult(slimeball). No luck for either of these.
     
  20. Offline

    opd02

    @mcdorli
    The code I gave him doesn't work if you didn't figure that out. I didn't solve any problem nor did I do the work for him. I simply showed him that he needed an ItemCraftEvent. I simply showed him the structure with some code here and there. Go ahead, grab the code and export it, it doesn't do anything. And I had no idea that the people on here were so harsh and rude.
     
  21. Offline

    iLiveorLose

    opd02
    I think the PrepareItemCraftEvent should be used instead. Do you know how to fix the problem I have though?
     
  22. Offline

    iLiveorLose

  23. Offline

    opd02

    We solved it didnt we?
     
  24. Offline

    Zombie_Striker

    @iLiveorLose @opd02

    As @mcdorli already said, you should never spoonfeed anyone. If you want a better explaination why you should never spoonfeed, click HERE and HERE. In my opion, the worst thing you can ever do is spoonfeed because it helps the member Now, not Later. You are giving some a huge block of code to someone who barely (if at all) understands what you posted. Sure, their current problem is fixed, but what if the wanted to modify it, use it for another plugin, or understand how it works. Simply put, they can't.

    Reasons why the code that was posted would not work:
    1. You are adding an itemstack only AFTER an itemstack has been crafted, and adding it EVERY SINGLE TIME the itemstack has been crafted. You should only do it once in the onEnabled.
    2. You are using Letters for the crafting format. This is something you should not do. Only use characters that are not letters or numbers.
    3. You are clearing all the itemstacks once your plugin is disabled. First, you do not need to do this at all since bukkit already handles clean-up when the server shuts down. Second, this may affect reloads as onDisabled is called when the server reloads*. (*do not know if this is entirely accurate as I have never done this). Finally, all you want to do is remove your recipe. There is no need to clear every single recipe in the game.
    4. You are abusing static. All you need to do is set all the variables on in the onEnabled. Simply move the whole "setting of itemstacks" to a new method, and call that method in the onEnabled.
    5. You are doing null checks on objects that cannot be null. If the ItemMeta does not exist, getItemMeta returns a new itemMeta. The Displayname should never be null.
    6. You are blindly casting the sender to a Player. How do you know the sender is a Player? You don't. Check if the sender is an instanceof Player before casting.
    7. If you look at the code it is FAR more complex and messy than it should be. It is extremely hard to read and understand. Because of this, there must be more mistakes than what I can see.
     
  25. Offline

    iLiveorLose

    @opd02
    Tell me where I said it was solved? I have a problem where I can use normal emerald blocks instead of "Shiny emerald blocks" to create a Mega Slimeball. Your code didn't help. I know you spent lots of time on it, and thank you, but even you yourself said it wouldn't work if I exported it, which makes no sense because what is the point of giving me code that wont work? I understand you wanted to show me which method to use, but even so, the method was not the proper one. Thanks for your help and effort though, you've helped me since this thread was created and I appreciate that! :)

    @Zombie_Striker
    Thank you, I've polished up the code, but my ItemStack names are underlined when I try to use them in the PrepareItemCraftEvent. Here is what I've got:
    Code:
    package me.liveorlose.megaslime;
    
    import java.util.Arrays;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.PrepareItemCraftEvent;
    import org.bukkit.inventory.CraftingInventory;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Test extends JavaPlugin implements Listener {
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            items();
        }
    
        private void items() {
            ItemStack emeraldblock = new ItemStack(Material.EMERALD_BLOCK, 1);
    
            emeraldblock.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta emeraldmeta = emeraldblock.getItemMeta();
            emeraldmeta.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD
                    + "Shiny emerald block");
            emeraldmeta.setLore(Arrays.asList(ChatColor.GREEN
                    + "This emerald block", ChatColor.GREEN + "is enchanted with",
                    ChatColor.GREEN + "an odd " + ChatColor.GOLD.toString()
                            + ChatColor.BOLD + "presence" + ChatColor.GREEN + "."));
            emeraldblock.setItemMeta(emeraldmeta);
            /**********/
            ItemStack slimeball = new ItemStack(Material.SLIME_BALL, 1);
    
            slimeball.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
            ItemMeta slimeballmeta = slimeball.getItemMeta();
            slimeballmeta.setDisplayName(ChatColor.GREEN.toString()
                    + ChatColor.BOLD + "Mega slimeball");
            slimeballmeta.setLore(Arrays.asList(ChatColor.GREEN
                    + "This mega slimeball",
                    ChatColor.GREEN + "came directly from",
                    ChatColor.GREEN + "the " + ChatColor.GREEN.toString()
                            + ChatColor.BOLD + ChatColor.UNDERLINE + "Slime King"
                            + ChatColor.RESET.toString() + ChatColor.GREEN
                            + " itself."));
            slimeball.setItemMeta(slimeballmeta);
        }
    
        @SuppressWarnings({ "deprecation" })
        @EventHandler
        public void onPrepareCraft(PrepareItemCraftEvent e) {
            ShapedRecipe shrecipe = new ShapedRecipe(emeraldblock);
            shrecipe.shape("@@@", "@[email protected]", "@@@");
            shrecipe.setIngredient('@', Material.MONSTER_EGG,
                    EntityType.SLIME.getTypeId());
            shrecipe.setIngredient('X', Material.EMERALD_BLOCK);
            Bukkit.getServer().addRecipe(shrecipe);
            //
            ShapedRecipe sbrecipe = new ShapedRecipe(slimeball);
            sbrecipe.shape("EEE", "ESE", "EEE");
            sbrecipe.setIngredient('S', Material.SLIME_BALL);
            sbrecipe.setIngredient('E', Material.EMERALD_BLOCK);
            Bukkit.getServer().addRecipe(sbrecipe);
            if (e.isRepair() || !e.getRecipe().equals(sbrecipe)) {
                return;
            }
            CraftingInventory inv = e.getInventory();
            for (ItemStack item : inv.getMatrix()) {
                if (!item
                        .getItemMeta()
                        .getDisplayName()
                        .equals(ChatColor.GREEN.toString() + ChatColor.BOLD
                                + "Shiny emerald block")) {
                    return;
                }
                inv.setResult(slimeball);
            }
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label,
                String[] args) {
            if (cmd.getName().equalsIgnoreCase("thisis")) {
                ItemStack slimeball = new ItemStack(Material.SLIME_BALL);
                slimeball.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
                ItemMeta slimeballmeta = slimeball.getItemMeta();
                slimeballmeta.setDisplayName(ChatColor.GREEN.toString()
                        + ChatColor.BOLD + "Mega slimeball");
                slimeballmeta.setLore(Arrays.asList(ChatColor.GREEN
                        + "This mega slimeball", ChatColor.GREEN
                        + "came directly from",
                        ChatColor.GREEN + "the " + ChatColor.GREEN.toString()
                                + ChatColor.BOLD + ChatColor.UNDERLINE
                                + "Mega Slime" + ChatColor.RESET.toString()
                                + ChatColor.GREEN + " itself."));
                slimeball.setItemMeta(slimeballmeta);
                Player p = (Player) sender;
                Inventory pi = p.getInventory();
                pi.addItem(slimeball);
            }
            return true;
        }
    }
    Lines 61, 68, and 85 are underlined. Please help :(
     
  26. Offline

    mcdorli

    Because you never declare them. I suggest reading this. https://docs.oracle.com/javase/tutorial/
     
  27. Offline

    iLiveorLose

  28. Offline

    Zombie_Striker

    @iLiveorLose
    Yeah, if you think that should have worked (I.e if you even attempted to do that), you do not fully understand Java. Knowing Java is a requirement for working on bukkit. Please go to the tutorial @mcdorli posted and learn Java. You should be able to figure out why what you posted should not work after you read the first few chapters in the tutorial.
     
  29. Offline

    iLiveorLose

    Well.. can you at least tell me how to fix this problem? I know how to code java, I'm just rusty. Can you please help?
     
  30. Offline

    Zombie_Striker

    @iLiveorLose
    Move the itemstack instances out of the method (I.e turn those variables into fields), and set the values inside the method.
     
Thread Status:
Not open for further replies.

Share This Page