Solved Custom recipes

Discussion in 'Spigot Plugin Development' started by eot13, Jul 14, 2018.

Thread Status:
Not open for further replies.
  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):
    @EventHandler(priority=EventPriority.LOWEST)
            public void Core(PrepareItemCraftEvent e){
                @SuppressWarnings("deprecation")
                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");
    result.setItemMeta(resultMeta);
     
    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
    Last edited: Jul 14, 2018
  7. Code (Text):
    Inventory inv = Bukkit.createInventory(player, InventoryType.WORKBENCH, "Your Title");
    player.openInventory(inv);
     
  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.
     
    • Useful Useful x 1
  12. Ok, thx, but I don't understand how to create recipe with items who have custom ItemMeta (displayname, lore, etc)
     
  13. Like in this code example from Fizmo: You have to change the ItemMeta resultMeta object and then set it to the ItemStack result afterwards.
    Here are all methods you can use: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/meta/ItemMeta.html


    If you want to get meta values make sure to check if the current meta has something before getting the value. For example:
    If you want to get the Lore use: if(resultMeta#hasLore()) --> resultMeta#getLore()
     
    • Agree Agree x 1
  14. Ok thank you everyone!
     
  15. So I don't understand why, but the recipes from the GUI don't work... : /
    (All recipes are disabled)

    My code:

    Code (Java):

    @EventHandler
    public void SpecialTable(PlayerInteractEvent e){
     
            if(e.getClickedBlock() != null && e.getAction() == Action.RIGHT_CLICK_BLOCK){
            if(e.getClickedBlock().getType() == Material.STONE && e.getClickedBlock().getData() == 0){
            e.getPlayer().openInventory(Bukkit.createInventory(e.getPlayer(), InventoryType.WORKBENCH, "┬žbSpecial table"));
     
                }
            }
        }
     
  16. It was very simple ;)

    e.getPlayer().openWorkbench(null, true);
     
Thread Status:
Not open for further replies.

Share This Page