Custom recipes

Discussion in 'Spigot Plugin Development' started by eot13, Jul 14, 2018 at 1:44 AM.

  1. Hello, so I would like to create a custom recipe that if the player points a block of gold with his cursor, here is my code, but I do not know what to do next ...
    Thank you in advance!

    Code (Java):
            public void Core(PrepareItemCraftEvent e){
                Block block = e.getView().getPlayer().getTargetBlock((HashSet<Byte>) null, 6).getLocation().getBlock();
                if(block.getType() != null && block.getType() == Material.GOLD_BLOCK){

  2. What you're asking doesn't really make sense, nor does your code. You mean you want the gold block to open a crafting GUI, and then have a special recipe only in that crafting GUI opened from the gold block?
  3. Here I found a good guide on how to make recipes in Bukkit/Spigot. It's important that you understand what you're doing rather than copy-pasting.
  4. Outdated, If you're using 1.12+ then use new ShapedRecipe(NamespacedKey, ItemStack)
    • Agree Agree x 1
  5. Code (Java):
    // Here's an example of making a custom recipe
    ItemStack result = new ItemStack(Material.CHEST); // making item which the below recipe crafts
    ItemMeta resultMeta = result.getItemMeta();
    resultMeta.setDisplayName(ChatColor.GREEN + "Emerald Chest");
    ShapedRecipe shapedRecipe = new ShapedRecipe(result); // creating recipe object
    shapedRecipe.shape(new String[] { EEE", "ECE", "EEE" }); // E is for emerald and C is for chest. this makes it so the top row is all emeralds, middle is emerald, chest, emerald, and bottom is all emeralds
    shapedRecipe.setIngredient('E', Material.EMERALD); // specifics what E is
    shapedRecipe.setIngredient('C', Material.CHEST); // specifies what C is
    plugin.getServer().addRecipe(shapedRecipe); // adds recipe to server
    • Like Like x 1
  6. Yes, but I know to do how to open the crafting table on interaction.

    Sorry for my very bad english
    #6 eot13, Jul 14, 2018 at 2:17 PM
    Last edited: Jul 14, 2018 at 4:13 PM
  7. Code (Text):
    Inventory inv = Bukkit.createInventory(player, InventoryType.WORKBENCH, "Your Title");
  8. I know that
  9. When you right click a gold block, add a player UUID to a list and open crafting GUI. On Inventory close, remove the uuid.
    Inside PrepareItemCraftEvent, check if the player's uuid is in the list. That will verify if the crafting GUI was opened from a gold block or not.
    • Like Like x 1
  10. Yes thx, but how can I add a new recipe, when the player has opened the custom table?
  11. Instead of adding a new one everytime, add one directly onEnable, and manipulate PrepareItemCraftEvent to only show the crafted item when the player is in the list.

Share This Page