Compare Recipe

Discussion in 'Plugin Development' started by surtic, Mar 30, 2012.

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

    surtic

    Hi there,

    I be on working for a Hardcore Plugin. And now i have no Plan how i can check how the Recipe is exactly.

    First i make a new Recipe for Golden Apple with Ingot

    PHP:
    ShapedRecipe goldenApple = new ShapedRecipe( new ItemStack(Material.GOLDEN_APPLE1)).shape(new String[] { "ggg""gag""ggg" }).setIngredient('g'Material.GOLD_INGOT).setIngredient('a'Material.APPLE);
    plugin.getServer().addRecipe(goldenApple);
    And now i will check on CraftItemEvent is the Recipe from Golden Apple with Nuggets ore Ingot.

    Any Idea how i can do this? From the Event i can get the Recipe but not the Shapes :(
     
  2. Offline

    Njol

    check whether the recipe is instanceof ShapedRecipe, and if it is, you can safely cast it:
    Code:java
    1. if (event.getRecipe() instanceof ShapedRecipe) {
    2. ShapedRecipe s = (ShapedRecipe) event.getRecipe();
    3. // check the shape here and do whatever you want
    4. }
     
  3. Offline

    surtic

    Ah thank you so mutch :) than can i get the shapes

    Hm okey not so nice... the Shapes are Strings and every time when i have a Recipe that need all rows i get the same...

    PHP:
    if ( event.getRecipe() instanceof ShapedRecipe ) {
                       
                        
    ShapedRecipe recipe = (ShapedRecipeevent.getRecipe();
                       
                        
    String[] shapes recipe.getShape();
                       
                        for ( 
    String shape shapes ) {
                            
    Helper.log("Shape : " shape );
                        }
                       
                       
                    }
    14:21:11 [INFO] [Hardcore] Shape : abc
    14:21:11 [INFO] [Hardcore] Shape : def
    14:21:11 [INFO] [Hardcore] Shape : ghi

    What can i do that i know witch it is?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  4. Offline

    dsmyth1915

    This is good practice, but why are you making a golden apple when there is already a recipe for it in vanilla?
     
  5. Offline

    surtic

    dsmyth1915 : I make this for Hardcore Mode :) normally you need one Gold Ingot for a Golden Apple but for the Hard mode you need 9 Golden Ingot for it :)
     
  6. Offline

    dsmyth1915

    Looks like I need to play more O.O last I checked it was 9 gold blocks... That might have been before 1.8 beta lol. First off, you were using a for loop, with no actually loop. How that works I have no clue. Second, instead of using the logger to check the shape (why it printed abcdefghi) try checking for the player who is trying to use the recipe. And print his name along with the recipe name. I'm not entirely familiar with recipes, but ill look around and get back to you.
     
  7. Offline

    surtic

    @dsmyth : I look throw the String[] he has three Strings for each Row in the Recipe. I be alone on the Server so i dont need tho log the Player Name :) i know where it is. And the Helper.log() is Loggin on the Server Console.
     
Thread Status:
Not open for further replies.

Share This Page