Skip to content

Instantly share code, notes, and snippets.

@Draco18s
Created August 29, 2017 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Draco18s/6398d3b94a4c07ded26eb641639a2ce2 to your computer and use it in GitHub Desktop.
Save Draco18s/6398d3b94a4c07ded26eb641639a2ce2 to your computer and use it in GitHub Desktop.
public static void setupDir(Configuration config) {
RECIPE_DIR = null;
if (RECIPE_DIR == null) {
RECIPE_DIR = config.getConfigFile().toPath().resolve("../recipes/").toFile();
ADVANCE_DIR = config.getConfigFile().toPath().resolve("../advancements/").toFile();
String dir = config.getConfigFile().toPath().resolve("../recipes/").toString();
String pattern = "config\\\\(.*)\\.cfg\\\\\\.\\.\\\\recipes";
Pattern p = Pattern.compile(pattern);
Matcher matcher = p.matcher(dir);
while (matcher.find()) {
DOMAIN = matcher.group(1);
break;
}
}
if (!RECIPE_DIR.exists()) {
RECIPE_DIR.mkdir();
}
if (!ADVANCE_DIR.exists()) {
ADVANCE_DIR.mkdir();
}
}
private static void writeAdvancement(String result) {
Map<String, Object> json = new HashMap<>();
json.put("parent", "minecraft:recipes/root");
Map<String, Object> rewards = new HashMap<>();
List<String> recipes = new ArrayList<String>();
recipes.add(DOMAIN+":"+result);
rewards.put("recipes",recipes);
Map<String, Map<String, Object>> criteria = new HashMap<>();
Map<String, Object> has_item = new HashMap<>();
Map<String, Object> conditions = new HashMap<>();
Map<String, Object> conditions2 = new HashMap<>();
Map<String, Object> has_the_recipe = new HashMap<>();
ArrayList<ArrayList<String>> requirements = new ArrayList<ArrayList<String>>();
has_item.put("trigger", "minecraft:inventory_changed");
conditions.put("items", new ArrayList<String>());
conditions2.put("recipe", result);
has_the_recipe.put("trigger", "minecraft:recipe_unlocked");
has_the_recipe.put("conditions", conditions2);
has_item.put("conditions", conditions);
criteria.put("has_item", has_item);
criteria.put("has_the_recipe", has_the_recipe);
ArrayList<String> reqs = new ArrayList<String>();
reqs.add("has_item");
reqs.add("has_the_recipe");
requirements.add(reqs);
json.put("requirements", requirements);
json.put("criteria", criteria);
json.put("rewards", rewards);
String suffix = "";
File f = new File(ADVANCE_DIR, result + suffix + ".json");
while (f.exists()) {
suffix += "_alt";
f = new File(ADVANCE_DIR, result + suffix + ".json");
}
try (FileWriter w = new FileWriter(f)) {
GSON.toJson(json, w);
} catch (IOException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment