Skip to content

Instantly share code, notes, and snippets.

@Elix-x
Created October 20, 2015 13:42
Show Gist options
  • Save Elix-x/3bdb448ae1d5bbf120d3 to your computer and use it in GitHub Desktop.
Save Elix-x/3bdb448ae1d5bbf120d3 to your computer and use it in GitHub Desktop.
Weird bug with ShapedOreRecipe
public class RecipeStringTranslator {
public static boolean isShaped(String... recipe) {
return !ItemStackStringTranslator.isValidItemstackAdvanced(recipe[0]);
}
public static Object[] fromString(String... srecipe){
Object[] recipe = new Object[srecipe.length];
if(isShaped(srecipe)){
int i;
for(i = 0; i < srecipe.length; i++){
if(srecipe[i].length() == 1 && ItemStackStringTranslator.isValidItemstackAdvanced(srecipe[i + 1])) break;
}
for(int j = 0; j < i; j++){
recipe[j] = srecipe[j];
}
for(int j = i; j < srecipe.length; j++){
if(srecipe[j].length() == 1){
recipe[j] = srecipe[j].charAt(0);
} else {
recipe[j] = ItemStackStringTranslator.fromStringAdvanced(srecipe[j]);
}
}
} else {
for(int i = 0; i < srecipe.length; i++){
recipe[i] = ItemStackStringTranslator.fromStringAdvanced(srecipe[i]);
}
}
return recipe;
}
public static IRecipe fromString(ItemStack result, String... srecipe){
if(isShaped(srecipe)){
return new ShapedOreRecipe(result, fromString(srecipe));
} else {
return new ShapelessOreRecipe(result, fromString(srecipe));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment