-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecipeConverter.java
More file actions
122 lines (106 loc) · 5.01 KB
/
RecipeConverter.java
File metadata and controls
122 lines (106 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
import java.io.File;
import java.io.FileWriter;
//Converts old genesis recipes to new ones
class RecipeConverter
{
public static void main(String[] args) throws IOException
{
RecipeConverter foo = new RecipeConverter();
//File oldRecipes = new File("oldRecipes.txt");
//Scanner scanner = new Scanner(oldRecipes);
FileWriter myWriter = new FileWriter("newRecipes.txt");
Scanner scanner = new Scanner(System.in);
System.out.print("Input old Genesis item NBT or -1 to stop: ");
String userInput = scanner.nextLine();
while(!userInput.equals("-1")) {
foo.convertLootTableGear(userInput, myWriter);
System.out.print("Input old Genesis item NBT or -1 to stop: ");
userInput = scanner.nextLine();
}
/*while(scanner.hasNextLine())
{
String data = scanner.nextLine();
foo.convertRecipe(data, myWriter);
}*/
scanner.close();
myWriter.close();
}
private void convertRecipe(String input, FileWriter myWriter) throws IOException
{
if(input.length() == 0 || input.substring(0,1).equals("#"))
return;
//Gets item name in Pascal Case
String itemName = input.substring(input.lastIndexOf("/")+1);
itemName = snakeToPascal(itemName);
//Split recipe into array of individual ingredients
input = input.substring(input.indexOf("{0:[{Slot:") + 13, input.indexOf("]} ") - 1);
String regex = "\\},\\{Slot:\\d+b,|}\\],\\d+:\\[\\{Slot:\\d+b,";
String[] ingredients = input.split(regex);
//Print out new recipe
myWriter.write("# " + itemName + "\n");
myWriter.write("@add_custom_recipe([\n");
for(int i = 0; i<ingredients.length; i++) {
String ingredient = ingredients[i];
if(i%3==0) myWriter.write(" [");
if(ingredient.indexOf("tag:") != -1)
myWriter.write(snakeToPascal(ingredient.substring(ingredient.indexOf("name:")+6, ingredient.length()-3)));
else
myWriter.write("\"" + ingredient.substring(ingredient.indexOf("minecraft:")+10, ingredient.length()-1) + "\"");
if(i%3==2) myWriter.write("],\n");
else myWriter.write(", ");
}
myWriter.write("])\n");
}
//Does not completely convert the loot table to new custom item format, but saves some grunt work
private void convertLootTableGear(String input, FileWriter myWriter) throws IOException
{
String itemName = input.substring(input.indexOf("name:\\")+7,input.indexOf("\\\",type:"));
//myWriter.write("@add_loot_table\n@bolt_item\nclass ");
myWriter.write("@add_loot_table\n@bolt_item\nclass " + snakeToPascal(itemName) + "(GenesisItem):\n");
myWriter.write(" item_name = (\"" + snakeToPascal(itemName) + "\", {\"color\":\"COLOR\"})\n");
myWriter.write(" rarity = \"RARITY\"\n");
myWriter.write(" category = [\"" + input.substring(input.indexOf("type:\\\"")+7,input.indexOf(",stat:{")-2).toLowerCase() + "\"]\n");
myWriter.write(" stats = (\"mainhand\", {" + parseStats(input.substring(input.indexOf(",stat:{")+7,input.indexOf("},"))) + "})\n");
myWriter.write(" item_model = texture_path_to_item_model(\"genesis:item/dagger/" + itemName + "\", True)\n");
if(input.indexOf("ability:") != -1) {
myWriter.write(" @right_click_ability(\n");
myWriter.write(" name = \"" + input.substring(input.indexOf("ability/data/")+13,input.indexOf("\\\"}}")) + "\",\n");
myWriter.write(" description = ,\n");
myWriter.write(" mana = ,\n");
myWriter.write(" cooldown = ,\n )\n");
myWriter.write(" def " + input.substring(input.indexOf("ability/data/")+13,input.indexOf("\\\"}}")) + "():\n");
}
}
private void convertLootTableNotGear(String input, FileWriter myWriter) throws IOException
{
return;
}
private String snakeToPascal(String str) {
StringBuilder pascalCase = new StringBuilder();
for (String word : str.split("_")) {
if (!word.isEmpty()) {
pascalCase.append(Character.toUpperCase(word.charAt(0)))
.append(word.substring(1).toLowerCase());
}
}
return pascalCase.toString();
}
private String parseStats(String stats)
{
StringBuilder output = new StringBuilder();
output.append("\"");
for(int i = 0; i<stats.length(); i++)
{
if(stats.substring(i,i+1).equals(":"))
output.append("\"");
output.append(stats.substring(i,i+1));
if(stats.substring(i,i+1).equals(","))
output.append("\"");
}
return output.toString();
}
//physical_power:50,attack_speed:110,armor_toughness:60,speed:30
}