Tutorial How to make custom crafting recipes...

Discussion in 'Resources' started by JTGaming2012, Aug 9, 2014.

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

    Exit151

    Does anyone know if this still works with 1.10/1.11? I'm running 1.10.2 server, and started with this code and changed it all up for my own items.. Long story short, I started fresh with a brand new plugin, copy/pasted both the main and the plugin.yml, exported and get the same result.. Which is:

    Compiles fine. When I start the server it shows that it's enabling the plugin (with no errors). But when I try putting the stuff on the crafting table, it doesn't work (top 2x ink 1 sugar, 2x ink - middle 1sugar 1glass bottle 1sugar - bottom 2x ink 1sugar 2x ink). Additionally, I cannot use /give <playername> recipes:expBottle (or just expBottle without the recipe: bit..
    /plugins lists my plugin. /ver recipe shows the plugin.yml shows the help for it.. There are no errors in the log file at all, but it's not working. Not sure what I'm doing wrong?

    EDIT: After messing around and looking at a similar (but different) project that was on git, I found that for me, this plugin will not work if you use the quantity.. (Line number 18 "expBottle.setIngredient('*', Material.INK_SACK, 2);"
    if I remove the ",2" from the end it works perfectly. Any idea why, and what I can do to force it to use more than one of an item while crafting? Also curious if there's a way to /give the item still.. I can craft it, but still wasn't able to /give one no matter what I tried. Thanks in advance!
     
  2. Offline

    Zombie_Striker

    @Exit151
    How would that even work? If you mean you are requiring the player to put two inksacks in the same slot for the recipe to be crafted, then there is no way to do that using this system. This tutorial is only meant to show you how to use the default crafting system to create your crafting recipe. What you want would require you to make your own crafting system to work alongside the existing one. If you want to know how to do this, I would recommend you create a plugin dev thread (that way this thread stays on topic).
     
  3. Offline

    Exit151

    Then what is that line specifying by the ",2" part after the ink sack? Is it not saying to use 2 ink sacks in that slot on the crafting table?
    I'm not trying to do anything other than what this plugin does. What I said is when I copied it exactly as it appears, it did not work for me. When I removed the ",2" it works. I assumed the comma 2 meant two ink sacks, but maybe not? All I know is without it, the plugin worked for me, with it, it does not. I've no idea why that is.
    EDIT: Ugh. Re-read the tutorial.. Noted now that the ink_sack line actually is telling it to use green dye. Not sure why it wouldn't just call for cactus_green "green dye" but I get it now.. By removing the 2, which wasn't quantity, it was telling what variant of that item id to use.. Got it (and understand why mine now works with actual ink sack instead of 2x ink sacks, and when I put the ,2 back in - Actually, it gives me an error in the code - The setIngredient strikes itsself out when I add the ", 2" and mousing over it states "The method setIngredient(char, Material, int) from the type ShapedRecipe is deprecated" and it doesn't work (recipe in-game). When I remove the ", 2" the strikeout goes away. Tried adding that bit to the other two lines and when I do they also appear invalid and break the recipe from working (yes, I'm aware it's not telling me to use 2 of that ingredient, that it's saying like for wood log, use the oak or spruce variant etc)..
     
    Last edited: Jan 7, 2017
  4. I can't get this to work - no recipes can be used in a crafting table - so here are my plugin.yml and Main.java files:
    Code:
    main: org.dyndns.starbright.starwort.spawncrafting.Main
    name: SpawnerCrafting
    version: 1.0
    author: Starwort
    description: Allows crafting of spawn eggs and mob spawners.
    commands:
      test:
        description: Test
        usage: /test
    
    Code:
    package org.dyndns.starbright.starwort.spawncrafting;
    
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.EntityType;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.Recipe;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.ShapelessRecipe;
    import org.bukkit.inventory.meta.*;
    import org.bukkit.material.SpawnEgg;
    @SuppressWarnings("deprecation")
    public class Main extends JavaPlugin {
        String msg = "";
        public void initializeAddRecipes(){
            Material spawnEgg = Material.MONSTER_EGG;
            Material egg = (Material.EGG);
            SpawnEgg spawnEggDefault = new SpawnEgg();
            Material flesh = (Material.ROTTEN_FLESH);
            Material bone = (Material.BONE);
            Material pearl = (Material.ENDER_PEARL);
            Material string = (Material.STRING);
            Material eye = (Material.SPIDER_EYE);
            Material shell = (Material.SHULKER_SHELL);
            Material ink = (Material.INK_SACK);
            Material beef = (Material.COOKED_BEEF);
            Material mutton = (Material.COOKED_MUTTON);
            Material chickenItem = (Material.COOKED_CHICKEN);
            Material skull = (Material.SKULL_ITEM);
            Material gold = (Material.GOLD_INGOT);
            Material tnt = (Material.TNT);
            Material slimeBall = (Material.SLIME_BALL);
            Material blazeRod = (Material.BLAZE_ROD);
            Material pork = (Material.GRILLED_PORK);
            Material emerald = (Material.EMERALD_BLOCK);
            Material glowstone = (Material.GLOWSTONE);
            Material iron = (Material.IRON_BLOCK);
            ItemStack spawner = new ItemStack(Material.MOB_SPAWNER);
            ItemStack spawnEggTemplate = spawnEggDefault.clone().toItemStack();
            ItemMeta meta = spawnEggTemplate.getItemMeta();
            meta.setDisplayName("§rSpawn Egg Template");
            spawnEggTemplate.setItemMeta(meta);
            SpawnEgg zombie,skeleton,enderman,spider,caveSpider,shulker,squid,cow,sheep,chicken,wither,pigZombie,creeper,slime,blaze,pig,villager,witch;
            zombie=skeleton=enderman=spider=caveSpider=shulker=squid=cow=sheep=chicken=wither=pigZombie=creeper=slime=blaze=pig=villager=witch=spawnEggDefault.clone();
            zombie.setSpawnedType(EntityType.ZOMBIE);
            skeleton.setSpawnedType(EntityType.SKELETON);
            enderman.setSpawnedType(EntityType.ENDERMAN);
            spider.setSpawnedType(EntityType.SPIDER);
            caveSpider.setSpawnedType(EntityType.CAVE_SPIDER);
            shulker.setSpawnedType(EntityType.SHULKER);
            squid.setSpawnedType(EntityType.SQUID);
            cow.setSpawnedType(EntityType.COW);
            sheep.setSpawnedType(EntityType.SHEEP);
            chicken.setSpawnedType(EntityType.CHICKEN);
            wither.setSpawnedType(EntityType.WITHER_SKELETON);
            pigZombie.setSpawnedType(EntityType.PIG_ZOMBIE);
            creeper.setSpawnedType(EntityType.CREEPER);
            slime.setSpawnedType(EntityType.SLIME);
            blaze.setSpawnedType(EntityType.BLAZE);
            pig.setSpawnedType(EntityType.PIG);
            villager.setSpawnedType(EntityType.VILLAGER);
            witch.setSpawnedType(EntityType.WITCH);
            ShapedRecipe template = new ShapedRecipe(spawnEggTemplate);
            ShapedRecipe spawnerBlock = new ShapedRecipe(spawner);
            ShapelessRecipe z = new ShapelessRecipe(zombie.toItemStack());
            ShapelessRecipe sk = new ShapelessRecipe(skeleton.toItemStack());
            ShapelessRecipe e = new ShapelessRecipe(enderman.toItemStack());
            ShapelessRecipe sp = new ShapelessRecipe(spider.toItemStack());
            ShapelessRecipe ca = new ShapelessRecipe(caveSpider.toItemStack());
            ShapelessRecipe su = new ShapelessRecipe(shulker.toItemStack());
            ShapelessRecipe sq = new ShapelessRecipe(squid.toItemStack());
            ShapelessRecipe co = new ShapelessRecipe(cow.toItemStack());
            ShapelessRecipe se = new ShapelessRecipe(sheep.toItemStack());
            ShapelessRecipe ch = new ShapelessRecipe(chicken.toItemStack());
            ShapelessRecipe ws = new ShapelessRecipe(wither.toItemStack());
            ShapelessRecipe pz = new ShapelessRecipe(pigZombie.toItemStack());
            ShapelessRecipe cr = new ShapelessRecipe(creeper.toItemStack());
            ShapelessRecipe sl = new ShapelessRecipe(slime.toItemStack());
            ShapelessRecipe b = new ShapelessRecipe(blaze.toItemStack());
            ShapelessRecipe pi = new ShapelessRecipe(pig.toItemStack());
            ShapelessRecipe v = new ShapelessRecipe(villager.toItemStack());
            ShapelessRecipe wi = new ShapelessRecipe(witch.toItemStack());
            template.shape("AAA","ABA","AAA");
            template.setIngredient(toChar("A"), flesh);
            template.setIngredient(toChar("B"),egg);
            spawnerBlock.shape("AAA","ABA","AAA");
            spawnerBlock.setIngredient(toChar("A"), iron);
            spawnerBlock.setIngredient(toChar("B"), spawnEgg);
            z.addIngredient(spawnEgg);
            z.addIngredient(flesh);
            sk.addIngredient(spawnEgg);
            sk.addIngredient(bone);
            e.addIngredient(spawnEgg);
            e.addIngredient(pearl);
            sp.addIngredient(spawnEgg);
            sp.addIngredient(string);
            ca.addIngredient(spawnEgg);
            ca.addIngredient(eye);
            su.addIngredient(spawnEgg);
            su.addIngredient(shell);
            sq.addIngredient(spawnEgg);
            sq.addIngredient(ink);
            co.addIngredient(spawnEgg);
            co.addIngredient(beef);
            se.addIngredient(spawnEgg);
            se.addIngredient(mutton);
            ch.addIngredient(spawnEgg);
            ch.addIngredient(chickenItem);
            ws.addIngredient(spawnEgg);
            ws.addIngredient(skull,1);
            pz.addIngredient(spawnEgg);
            pz.addIngredient(gold);
            cr.addIngredient(spawnEgg);
            cr.addIngredient(tnt);
            sl.addIngredient(spawnEgg);
            sl.addIngredient(slimeBall);
            b.addIngredient(spawnEgg);
            b.addIngredient(blazeRod);
            pi.addIngredient(spawnEgg);
            pi.addIngredient(pork);
            v.addIngredient(spawnEgg);
            v.addIngredient(emerald);
            wi.addIngredient(spawnEgg);
            wi.addIngredient(glowstone);
            getServer().addRecipe(template);
            getServer().addRecipe(spawnerBlock);
            getServer().addRecipe(z);
            getServer().addRecipe(sk);
            rec(e);
            rec(sp);
            rec(ca);
            rec(su);
            rec(sq);
            rec(co);
            rec(se);
            rec(ch);
            rec(ws);
            rec(pz);
            rec(cr);
            rec(sl);
            rec(b);
            rec(pi);
            rec(v);
            rec(wi);
            msg = "Initialised recipes!";
        }
        public char toChar(String str){
            if(str.length()==1){
                return str.toCharArray()[0];
            } else {
                throw new IllegalArgumentException(str+" is longer than one character, therefore cannot be converted to one!");
            }
        }
        public void rec(Object recipe){
            if(recipe instanceof Recipe){
                getServer().addRecipe((Recipe) recipe);
            } else {
                throw new IllegalArgumentException("Input is not a valid recipe of type Recipe.");
            }
        }
        @Override
        public void onEnable(){
            initializeAddRecipes();
        }
        @Override
        public void onDisable(){
     
        }
        @Override
        public boolean onCommand(CommandSender sender,
                Command command,
                String label,
                String[] args){
            if(command.getName().equalsIgnoreCase("test")){
                sender.sendMessage(msg);
                return true;
            }
            return false;
        }
    }
    
    
    Also, the test command returns "Initialised recipes!"...
    Help would be very much appreciated!
     
    Last edited: Apr 8, 2017
Thread Status:
Not open for further replies.

Share This Page