getMaterial(0) doesn't return Material.AIR?

Discussion in 'Plugin Development' started by CaptainBern, May 18, 2013.

Thread Status:
Not open for further replies.
  1. Hello all,

    With BackPacks++ you are able to set recipes yourself. You can do this by (as example)
    Code:
    recipe line 1: 334|334|334
    recipe line 2: 334|0|334 < 0 represents air.
    recipe line 3: 334|334|334
    Everything works fine except the 0, when I use 0 in a recipe it gives an npe (that just says the recipe can't be added and the lines where the "recipeLoad" method is called.
    I don't know of this is a bukkit issue or if you want to have an empty slot in your recipe you just have to use " " (since you have to do it like that when making mods), if so what is the shortest way of checking if it is 0 and replace it by " " ?
    This is the code (just a snipet)
    Code:
                    ShapedRecipe backpack = new ShapedRecipe(item);
     
                    String[] base1 = yml.getString("recipe line 1").split("\\|");
                    String[] base2 = yml.getString("recipe line 2").split("\\|");
                    String[] base3 = yml.getString("recipe line 3").split("\\|");
     
                    int a = Integer.parseInt(base1[0]);
                    int b = Integer.parseInt(base1[1]);
                    int c = Integer.parseInt(base1[2]);
     
                    int d = Integer.parseInt(base2[0]);
                    int e = Integer.parseInt(base2[1]);
                    int f = Integer.parseInt(base2[2]);
     
                    int g = Integer.parseInt(base3[0]);
                    int h = Integer.parseInt(base3[1]);
                    int i = Integer.parseInt(base3[2]);
     
                    backpack.shape("abc","def","ghi");
     
                    backpack.setIngredient('a', Material.getMaterial(a));
                    backpack.setIngredient('b', Material.getMaterial(b));
                    backpack.setIngredient('c', Material.getMaterial(c));
     
                    backpack.setIngredient('d', Material.getMaterial(d));
                    backpack.setIngredient('e', Material.getMaterial(e));
                    backpack.setIngredient('f', Material.getMaterial(f));
     
                    backpack.setIngredient('g', Material.getMaterial(g));
                    backpack.setIngredient('h', Material.getMaterial(h));
                    backpack.setIngredient('i', Material.getMaterial(i));
     
                    Bukkit.getServer().addRecipe(backpack);
    Thanks.
     
  2. Offline

    GodzOfMadness

    CaptainBern Each slot is considered null if there is not an item placed on the slot. So yes, you do need to use " ". I would suggest just use .replace("0", " ");
     
    CaptainBern likes this.
  3. But since the it has to be " ", then where do I have to use replce(0, " ")?
     
  4. Offline

    GodzOfMadness

    CaptainBern When you have the string value replace the 0 with " " just before you start to set values or use it in the recipe
     
    CaptainBern likes this.
  5. Do you mean after the: int i = Integer.parseInt(base3[2]); ? (and for all the other values..)
     
  6. Offline

    GodzOfMadness

    CaptainBern When you use the shape method you replace the letter you want as null with " " and then remove the line with the corresponding key letter for setting the ingredient
     
    CaptainBern likes this.
  7. But hmm, how do I know if a token represents 0? (since it's value get assigned to it after the shape method) But I hope you know that every slot can be empty, like they have 2 recipes, in one recipe they have slot 3 empty and in recipe 2 the middle slot is empty...So idk if what you say can solve this?
     
  8. Offline

    GodzOfMadness

    CaptainBern I'm not to sure. Try to single out the empty boxes. Yea i know like
    backpack.shape("abc","d f","ghi");
    The middle slot is empty. But you can possibly get the ingredient map and some how check which boxes are empty? Or possibly get the shape and it would return the above values ("abc", "d f", "ghi").
     
  9. Hmm, or I can just store the 0 values in a array (like if a is 0 it gets added to the array) and then just replace the array by " ". If that's possible (very unclear ewplained I know)
     
  10. Offline

    GodzOfMadness

    CaptainBern What would be the reason you want to save the empty slots for the crafting grid?
     
  11. That I know wich token to replace by " " in the shape method?
    edit: nevermind, bad idea... If you or anybody alse know something then please provide an example...My brains are hurting...
     
  12. Offline

    GodzOfMadness

    CaptainBern The space is a token by default it equals null or in other terms, an empty box.
     
  13. I know but because the empty token can be diffrent each time, I need to do something like this:
    Check for the int's that are 0,
    Store those somehow (so i have, as example: int a = 0 so , store int a)
    then in the shape method i need to replace token a by " " because a is 0, with another recipe where , lets say e is 0 I need to do the same bu with e...

    Thanks for your help tough...
     
  14. Offline

    GodzOfMadness

Thread Status:
Not open for further replies.

Share This Page