[HELP] Edit Recipe

Discussion in 'Plugin Development' started by F4BSE, Nov 28, 2012.

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

    F4BSE

    How can I edit recipes?

    For example I want to edit the bookshelf recipe for my rp server.
    The old recipe is:

    Wood Wood Wood
    Book Book Book
    Wood Wood Wood

    and the new should be:

    Wood Wood Wood
    Wood Paper Wood
    Wood Wood Wood

    How is the java code for this?
     
  2. Offline

    welsar55

  3. Offline

    F4BSE

    This is not that what I'm looking for.

    I don't want to create new recipes.
    I want to delete or edit the old one

    How can I make this?
     
  4. Offline

    welsar55

  5. Offline

    EnvisionRed

    Um, rather than use a plugin that's already created, if you want to see how this would be done if you actually coded it, I think this is how it would be done:
    Code:
    //make sure to import craftbukkit.jar as a source.
            //uses the java reflections :)
            Field field = null;
            CraftingManager manager = null;
            try {
                field = CraftingManager.class.getDeclaredField("a");
                field.setAccessible(true);
                manager = (CraftingManager) field.get(null); //will work because "a" is static.
                field.setAccessible(false);
            }catch(Exception e){
                //for some reason it failed so return, nothing you can do beyond this point.
                return;
            }
            //if manager is null, gonna want to return.
            if (manager == null){
                return;
            }
            for (Object o : manager.recipes){
                try{
                    //will throw error if it's not a shapedrecipes which is fine, because
                    //you are only trying to deal with a shapedrecipes
                    ShapedRecipes recipe = (ShapedRecipes) o;
                    field = recipe.getClass().getDeclaredField("result");
                    field.setAccessible(true);
                    net.minecraft.server.ItemStack stack = (ItemStack) field.get(recipe);
                    if (stack.id == Material.BOOKSHELF.getId()){
                        //remove the current recipe for bookshelf.
                        manager.recipes.remove(o);
                        break;
                    }
                }catch(Exception e) { continue; }
            }
            Object[] args = { "###", "#X#", "###", Character.valueOf('#'), Block.WOOD, Character.valueOf('X'), Item.PAPER};
            manager.registerShapedRecipe(new net.minecraft.server.ItemStack(Block.BOOKSHELF, 1), args);
            //aand you're done.
     
  6. Offline

    welsar55

    but he does not know any java it sounds
     
  7. Offline

    F4BSE

  8. Offline

    EnvisionRed

     
  9. Offline

    F4BSE

    Can I delete recipes and make the old one new, like this?

    Code:
            if (getConfig().getBoolean("chainBoots", true)) {
                ShapedRecipe recipe1 = new ShapedRecipe(new ItemStack(Material.CHAINMAIL_BOOTS, 1));
                recipe1.shape(new String[] { "C C", "B B", "A A" });
                recipe1.setIngredient('A', Material.IRON_INGOT);
                recipe1.setIngredient('B', Material.STRING);
                getServer().addRecipe(recipe1);
            }
     
Thread Status:
Not open for further replies.

Share This Page