Recipe Not Working

Discussion in 'Plugin Development' started by CoinSlotGaming, Aug 16, 2015.

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

    CoinSlotGaming

    I'm writing a recipe for cake (in my resource pack, it's pizza, hence "pizzaCrafting") but for some reason it just doesn't work.
    The console doesn't say anything, nor does Eclipse complain about my code.

    From within my onEnable() -
    Code:
        ShapelessRecipe pizzaCrafting = new ShapelessRecipe(new ItemStack(Material.CAKE));
        pizzaCrafting.addIngredient(Material.POTATO);
        pizzaCrafting.addIngredient(Material.WHEAT);
        pizzaCrafting.addIngredient(Material.CARROT);
      
        this.getServer().addRecipe(pizzaCrafting);
        this.getLogger().info("Pizza recipe loaded!");
     
    Last edited: Aug 16, 2015
  2. Offline

    mrgreen33gamer

    Whats the full onEnable void code?

    EDIT: Do you have @Override over the onEnable void?
     
  3. Does the server log "Pizza recipe loaded!" ?
     
  4. Offline

    CoinSlotGaming

    Yeah. Just in case you still need the full code, here it is:
    Code:
    @Override
        public void onEnable() {
            getLogger().info("Loading DinoCraft commands by CoinSlotGaming...");
            getServer().getPluginManager().registerEvents(new EventManager(), this);
    
            Runnable refresh = new Runnable(){
                public void run(){
                    for(Player p : Bukkit.getOnlinePlayers()){
                        if(hasWings(p)) {
                            Location pLoc = p.getLocation();
    
                            double r = 1D;
                            List<Entity> near = p.getNearbyEntities(r,r,r);
    
                            for(Entity e : near) {
    
                                if(e.getLocation().distance(pLoc) <= r && e.getType() == EntityType.ARMOR_STAND && e.getCustomName().equals("Wings")) {
                                    ((ArmorStand)e).setHelmet(new ItemStack(Material.CARPET));
                                    e.teleport(pLoc);
                                }
                                else{
                                    p.getWorld().spawnEntity(p.getLocation(), EntityType.ARMOR_STAND);
                                }
                            }
                        }
                        else if(!hasWings(p)) {
                            Location pLoc = p.getLocation();
                            Location loc = new Location(p.getWorld(), 0, 0, 0);
    
                            double r = 1D;
                            List<Entity> near = p.getNearbyEntities(r,r,r);
                            for(Entity e : near) {
                                if(e.getLocation().distance(pLoc) <= r && e.getType() == EntityType.ARMOR_STAND && e.getCustomName().equals("Wings")) {
                                    e.teleport(loc);
                                }
                            }
                        }
                        else{
    
                        }
                    }
                }};
                Bukkit.getScheduler().scheduleSyncRepeatingTask(this, refresh, 100, 1);
                Runnable part = new Runnable(){
                    public void run(){
                        for(Player p : Bukkit.getOnlinePlayers()){
                            Location pLoc = p.getLocation();
    
                            if(rainbowTrail(p)) {
    
                            }
                        }
                    }};
                    Bukkit.getScheduler().scheduleSyncRepeatingTask(this, part, 100, 1);
       
        ShapelessRecipe pizzaCrafting = new ShapelessRecipe(new ItemStack(Material.CAKE));
        pizzaCrafting.addIngredient(Material.POTATO);
        pizzaCrafting.addIngredient(Material.WHEAT);
        pizzaCrafting.addIngredient(Material.CARROT);
       
        this.getServer().addRecipe(pizzaCrafting);
        this.getLogger().info("Pizza recipe loaded!");
        }
    Yeah. Sorry, forgot to mention that.
     
  5. Offline

    Xtreme727

    @CoinSlotGaming

    I played around with the code and got something that should work.
    First off, change all:
    Code:
    pizzaCrafting.addIngredient(Material m);
    
    to

    Code:
    pizzaCrafting = pizzaCrafting.addIngredient(Material m);
    
    I noticed you want to involve potatoes and carrots, but I saw what you were using from Material to target those.
    Instead of Material.POTATO and Material.CARROT, use Material.POTATO_ITEM and Material.CARROT_ITEM
     
  6. Offline

    pie_flavor

    @CoinSlotGaming The methods do not modify the object, instead they return a modified object. This is so you can chain everything together in one line.
    Code:
    getServer().addRecipe(new ShapelessRecipe(new ItemStack(Material.CAKE)).addIngredient(Material.POTATO_ITEM).addIngredient(Material.CARROT_ITEM).addIngredient(Material.WHEAT));
     
  7. @CoinSlotGaming
    It's because there is a different ID for potato/carrot items and their blocks. You need to use CARROT_ITEM and POTATO_ITEM to get the item, right now it's checking for the block.
     
    CoinSlotGaming likes this.
  8. Offline

    CoinSlotGaming

    Thank you! That was the solution! You get +1 like and the thread will be set to solved!

    I'm having a bit of an issue with recipes again.

    The console says a load of stuff, which is below, but none of it indicates where I made a mistake.
    Console Log (open)

    [14:16:54 FATAL]: Error executing task
    java.util.concurrent.ExecutionException: java.lang.NullPointerException
    at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_45]
    at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_45]
    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:61) [spigot-1.8
    .6.jar:git-Spigot-6a6b839-b0e81a4]
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:7
    18) [spigot-1.8.6.jar:git-Spigot-6a6b839-b0e81a4]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:3
    67) [spigot-1.8.6.jar:git-Spigot-6a6b839-b0e81a4]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:6
    57) [spigot-1.8.6.jar:git-Spigot-6a6b839-b0e81a4]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
    :560) [spigot-1.8.6.jar:git-Spigot-6a6b839-b0e81a4]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.NullPointerException
    at net.minecraft.server.v1_8_R3.ShapelessRecipes.a(ShapelessRecipes.java
    :87) ~[spigot-1.8.6.jar:git-Spigot-6a6b839-b0e81a4]
    at net.minecraft.server.v1_8_R3.CraftingManager.craft(CraftingManager.ja
    va:297) ~[spigot-1.8.6.jar:git-Spigot-6a6b839-b0e81a4]
    at net.minecraft.server.v1_8_R3.ContainerWorkbench.a(ContainerWorkbench.
    java:56) ~[spigot-1.8.6.jar:git-Spigot-6a6b839-b0e81a4]
    at net.minecraft.server.v1_8_R3.InventoryCrafting.setItem(InventoryCraft
    ing.java:129) ~[spigot-1.8.6.jar:git-Spigot-6a6b839-b0e81a4]
    at net.minecraft.server.v1_8_R3.Slot.set(Slot.java:55) ~[spigot-1.8.6.ja
    r:git-Spigot-6a6b839-b0e81a4]
    at org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryView.setItem(C
    raftInventoryView.java:54) ~[spigot-1.8.6.jar:git-Spigot-6a6b839-b0e81a4]
    at net.minecraft.server.v1_8_R3.Container.clickItem(Container.java:196)
    ~[spigot-1.8.6.jar:git-Spigot-6a6b839-b0e81a4]
    at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
    :1568) ~[spigot-1.8.6.jar:git-Spigot-6a6b839-b0e81a4]
    at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:31)
    ~[spigot-1.8.6.jar:git-Spigot-6a6b839-b0e81a4]
    at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:9)
    ~[spigot-1.8.6.jar:git-Spigot-6a6b839-b0e81a4]
    at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:1
    3) ~[spigot-1.8.6.jar:git-Spigot-6a6b839-b0e81a4]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~
    [?:1.8.0_45]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_45]
    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:60) ~[spigot-1.
    8.6.jar:git-Spigot-6a6b839-b0e81a4]
    ... 5 more


    This is my onEnable() -
    Code:
    @Override
        public void onEnable() {
            getLogger().info("Loading DinoCraft commands by CoinSlotGaming...");
            getServer().getPluginManager().registerEvents(new EventManager(), this);
    
            Runnable refresh = new Runnable(){
                public void run(){
                    for(Player p : Bukkit.getOnlinePlayers()){
                        if(hasWings(p)) {
                            Location pLoc = p.getLocation();
    
                            double r = 1D;
                            List<Entity> near = p.getNearbyEntities(r,r,r);
    
                            for(Entity e : near) {
    
                                if(e.getLocation().distance(pLoc) <= r && e.getType() == EntityType.ARMOR_STAND && e.getCustomName().equals("Wings")) {
                                    ((ArmorStand)e).setHelmet(new ItemStack(Material.CARPET));
                                    e.teleport(pLoc);
                                }
                                else{
                                    p.getWorld().spawnEntity(p.getLocation(), EntityType.ARMOR_STAND);
                                }
                            }
                        }
                        else if(!hasWings(p)) {
                            Location pLoc = p.getLocation();
                            Location loc = new Location(p.getWorld(), 0, 0, 0);
    
                            double r = 1D;
                            List<Entity> near = p.getNearbyEntities(r,r,r);
                            for(Entity e : near) {
                                if(e.getLocation().distance(pLoc) <= r && e.getType() == EntityType.ARMOR_STAND && e.getCustomName().equals("Wings")) {
                                    e.teleport(loc);
                                }
                            }
                        }
                        else{
    
                        }
                    }
                }};
                Bukkit.getScheduler().scheduleSyncRepeatingTask(this, refresh, 100, 1);
                Runnable part = new Runnable(){
                    public void run(){
                        for(Player p : Bukkit.getOnlinePlayers()){
                            //Location pLoc = p.getLocation();
    
                            if(rainbowTrail(p)) {
    
                            }
                        }
                    }};
                    Bukkit.getScheduler().scheduleSyncRepeatingTask(this, part, 100, 1);
       
        ShapelessRecipe pizzaSlice = new ShapelessRecipe(new ItemStack(Material.COOKIE));
        pizzaSlice.addIngredient(Material.POTATO_ITEM);
        pizzaSlice.addIngredient(Material.WHEAT);
        pizzaSlice.addIngredient(Material.CARROT_ITEM);
       
        ShapelessRecipe pizza = new ShapelessRecipe(new ItemStack(Material.CAKE));
        pizza.addIngredient(Material.COOKIE);
        pizza.addIngredient(Material.COOKIE);
        pizza.addIngredient(Material.COOKIE);
        pizza.addIngredient(Material.COOKIE);
        pizza.addIngredient(Material.COOKIE);
        pizza.addIngredient(Material.COOKIE);
        pizza.addIngredient(Material.COOKIE);
       
        ShapelessRecipe slices = new ShapelessRecipe(new ItemStack(Material.COOKIE, 7));
        slices.addIngredient(Material.CAKE);
       
        ShapelessRecipe cupcake = new ShapelessRecipe(new ItemStack(Material.BREAD));
        cupcake.addIngredient(Material.MILK_BUCKET);
        cupcake.addIngredient(Material.EGG);
        cupcake.addIngredient(Material.SUGAR);
        cupcake.addIngredient(Material.COCOA);
        cupcake.addIngredient(Material.WHEAT);
       
        ShapelessRecipe cheese = new ShapelessRecipe(new ItemStack(Material.POTATO));
        cheese.addIngredient(Material.MILK_BUCKET);
       
        ShapelessRecipe pepperoni = new ShapelessRecipe(new ItemStack(Material.CARROT, 16));
        pepperoni.addIngredient(Material.RAW_BEEF);
       
        Iterator<Recipe> it = getServer().recipeIterator();
        Recipe recipe;
        while(it.hasNext())
        {
        recipe = it.next();
        Material result = recipe.getResult().getType();
        if (recipe != null && result == Material.CAKE || recipe != null && result == Material.COOKIE || result == Material.BREAD || result == Material.POTATO || result == Material.CARROT)
        {
        it.remove();
        }
        }
       
        this.getServer().addRecipe(pizzaSlice);
        this.getServer().addRecipe(pizza);
        this.getServer().addRecipe(slices);
        this.getServer().addRecipe(cupcake);
        this.getServer().addRecipe(cheese);
        this.getServer().addRecipe(pepperoni);
       
        this.getLogger().info("Pizza recipe loaded!");
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  9. Offline

    pie_flavor

    @CoinSlotGaming
    Code:
    ShapelessRecipe pizza = new ShapelessRecipe(new ItemStack(Material.CAKE)).addIngredient(8, Material.COOKIE);
    ShapelessRecipe cupcake = new ShapelessRecipe(new ItemStack(Material.BREAD)).addIngredient(Material.MILK_BUCKET).addIngredient(Material.EGG).addIngredient(Material.SUGAR).addIngredient(Material.COCOA).addIngredient(Material.WHEAT);
    ShapelessRecipe pizzaSlice = new ShapelessRecipe(new ItemStack(Material.COOKIE)).addIngredient(Material.POTATO_ITEM).addIngredient(Material.WHEAT).addIngredient(Material.CARROT_ITEM);
     
Thread Status:
Not open for further replies.

Share This Page