Support for includes added to JSON recipes.
parent
fd0e608700
commit
f8be087f98
|
@ -9,6 +9,7 @@ import org.apache.logging.log4j.Level;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class BBConfigFolderLoader
|
||||
{
|
||||
|
@ -46,6 +47,9 @@ public class BBConfigFolderLoader
|
|||
|
||||
config.loadJsonConfig(e, main, auto, custom);
|
||||
|
||||
List<String> includes = config.getIncludedJson(subfolder);
|
||||
config.loadIncludedConfig(e, includes);
|
||||
|
||||
config.savePostLoad(subfolder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AdvancedCraftingConfig implements IJsonConfig
|
||||
{
|
||||
|
@ -15,6 +17,8 @@ public class AdvancedCraftingConfig implements IJsonConfig
|
|||
|
||||
private JsonAdvancedCraftingHandler mainRecipes = new JsonAdvancedCraftingHandler();
|
||||
|
||||
private List<JsonAdvancedCraftingHandler> includes = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public String getSubFolder()
|
||||
{
|
||||
|
@ -56,6 +60,35 @@ public class AdvancedCraftingConfig implements IJsonConfig
|
|||
return "{}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getIncludedJson(File subfolder)
|
||||
{
|
||||
List<String> res = new ArrayList<>();
|
||||
for (String fileName : mainRecipes.getIncludes())
|
||||
{
|
||||
File incf = new File(subfolder, fileName);
|
||||
if (!incf.exists())
|
||||
{
|
||||
LogUtil.log(Level.ERROR, "Included file not found: config/betterbeginnings/advancedcrafting/" +
|
||||
fileName + " - Skipping.");
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
res.add(new String(Files.readAllBytes(incf.toPath())));
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
LogUtil.log(Level.ERROR, "IOException occurred opening config/betterbeginnings/advancedcrafting/" + fileName);
|
||||
LogUtil.log("");
|
||||
LogUtil.log(Level.ERROR, ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyMain()
|
||||
{
|
||||
|
@ -73,6 +106,21 @@ public class AdvancedCraftingConfig implements IJsonConfig
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadIncludedConfig(FMLInitializationEvent e, List<String> includedJsons)
|
||||
{
|
||||
for (String json : includedJsons)
|
||||
{
|
||||
JsonAdvancedCraftingHandler handler = BBJsonLoader.deserializeObject(json, JsonAdvancedCraftingHandler.class);
|
||||
includes.add(handler);
|
||||
|
||||
for (JsonAdvancedRecipe r : handler.getRecipes())
|
||||
{
|
||||
r.register();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePostLoad(File subfolder)
|
||||
{
|
||||
|
|
|
@ -8,12 +8,15 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BrickOvenConfig implements IJsonConfig
|
||||
{
|
||||
public static final BrickOvenConfig INSTANCE = new BrickOvenConfig();
|
||||
|
||||
private JsonBrickOvenRecipeHandler mainRecipes = new JsonBrickOvenRecipeHandler();
|
||||
private List<JsonBrickOvenRecipeHandler> includes = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public String getSubFolder()
|
||||
|
@ -56,6 +59,35 @@ public class BrickOvenConfig implements IJsonConfig
|
|||
return "{}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getIncludedJson(File subfolder)
|
||||
{
|
||||
List<String> res = new ArrayList<>();
|
||||
for (String fileName : mainRecipes.getIncludes())
|
||||
{
|
||||
File incf = new File(subfolder, fileName);
|
||||
if (!incf.exists())
|
||||
{
|
||||
LogUtil.log(Level.ERROR, "Included file not found: config/betterbeginnings/brickoven/" +
|
||||
fileName + " - Skipping.");
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
res.add(new String(Files.readAllBytes(incf.toPath())));
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
LogUtil.log(Level.ERROR, "IOException occurred opening config/betterbeginnings/brickoven/" + fileName);
|
||||
LogUtil.log("");
|
||||
LogUtil.log(Level.ERROR, ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyMain()
|
||||
{
|
||||
|
@ -78,6 +110,26 @@ public class BrickOvenConfig implements IJsonConfig
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadIncludedConfig(FMLInitializationEvent e, List<String> includedJsons)
|
||||
{
|
||||
for (String json : includedJsons)
|
||||
{
|
||||
JsonBrickOvenRecipeHandler handler = BBJsonLoader.deserializeObject(json, JsonBrickOvenRecipeHandler.class);
|
||||
includes.add(handler);
|
||||
|
||||
for (JsonBrickOvenShapedRecipe r : handler.getShaped())
|
||||
{
|
||||
r.register();
|
||||
}
|
||||
|
||||
for (JsonBrickOvenShapelessRecipe r : handler.getShapeless())
|
||||
{
|
||||
r.register();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePostLoad(File subfolder)
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.einsteinsci.betterbeginnings.config.json;
|
|||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public interface IJsonConfig
|
||||
{
|
||||
|
@ -12,9 +13,12 @@ public interface IJsonConfig
|
|||
String getAutoJson(File subfolder); // later
|
||||
String getCustomJson(File subfolder);
|
||||
|
||||
List<String> getIncludedJson(File subfolder);
|
||||
|
||||
boolean isOnlyMain();
|
||||
|
||||
void loadJsonConfig(FMLInitializationEvent e, String mainJson, String autoJson, String customJson);
|
||||
void loadIncludedConfig(FMLInitializationEvent e, List<String> includedJsons);
|
||||
|
||||
void savePostLoad(File subfolder);
|
||||
}
|
||||
|
|
|
@ -12,9 +12,12 @@ public class JsonAdvancedCraftingHandler
|
|||
{
|
||||
private List<JsonAdvancedRecipe> recipes;
|
||||
|
||||
private List<String> includes;
|
||||
|
||||
public JsonAdvancedCraftingHandler()
|
||||
{
|
||||
recipes = new ArrayList<>();
|
||||
includes = new ArrayList<>();
|
||||
|
||||
// TESTING ONLY
|
||||
recipes.add(new JsonAdvancedRecipe(new ItemStack(Items.string, 38),
|
||||
|
@ -26,4 +29,9 @@ public class JsonAdvancedCraftingHandler
|
|||
{
|
||||
return recipes;
|
||||
}
|
||||
|
||||
public List<String> getIncludes()
|
||||
{
|
||||
return includes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,13 @@ public class JsonBrickOvenRecipeHandler
|
|||
private List<JsonBrickOvenShapedRecipe> shaped;
|
||||
private List<JsonBrickOvenShapelessRecipe> shapeless;
|
||||
|
||||
private List<String> includes;
|
||||
|
||||
public JsonBrickOvenRecipeHandler()
|
||||
{
|
||||
shaped = new ArrayList<>();
|
||||
shapeless = new ArrayList<>();
|
||||
includes = new ArrayList<>();
|
||||
|
||||
// TESTING ONLY
|
||||
shaped.add(new JsonBrickOvenShapedRecipe(new ItemStack(Items.beef), "x ", "ox", 'x',
|
||||
|
@ -33,4 +36,9 @@ public class JsonBrickOvenRecipeHandler
|
|||
{
|
||||
return shapeless;
|
||||
}
|
||||
|
||||
public List<String> getIncludes()
|
||||
{
|
||||
return includes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,12 @@ import java.util.List;
|
|||
public class JsonKilnRecipeHandler
|
||||
{
|
||||
private List<JsonKilnRecipe> recipes;
|
||||
private List<String> includes;
|
||||
|
||||
public JsonKilnRecipeHandler()
|
||||
{
|
||||
recipes = new ArrayList<>();
|
||||
includes = new ArrayList<>();
|
||||
|
||||
// TESTING ONLY
|
||||
recipes.add(new JsonKilnRecipe(new ItemStack(Blocks.bedrock), new ItemStack(Items.blaze_rod), 0.5f));
|
||||
|
@ -23,4 +25,9 @@ public class JsonKilnRecipeHandler
|
|||
{
|
||||
return recipes;
|
||||
}
|
||||
|
||||
public List<String> getIncludes()
|
||||
{
|
||||
return includes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,12 @@ public class JsonSmelterRecipeHandler
|
|||
{
|
||||
private List<JsonSmelterRecipe> recipes;
|
||||
|
||||
private List<String> includes;
|
||||
|
||||
public JsonSmelterRecipeHandler()
|
||||
{
|
||||
recipes = new ArrayList<>();
|
||||
includes = new ArrayList<>();
|
||||
|
||||
// TESTING ONLY //
|
||||
recipes.add(new JsonSmelterRecipe(new ItemStack(Blocks.bedrock), new ItemStack(Items.golden_hoe), 0.5f, 1, 0));
|
||||
|
@ -23,4 +26,9 @@ public class JsonSmelterRecipeHandler
|
|||
{
|
||||
return recipes;
|
||||
}
|
||||
|
||||
public List<String> getIncludes()
|
||||
{
|
||||
return includes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class KilnConfig implements IJsonConfig
|
||||
{
|
||||
|
@ -15,6 +17,8 @@ public class KilnConfig implements IJsonConfig
|
|||
|
||||
private JsonKilnRecipeHandler mainRecipes = new JsonKilnRecipeHandler();
|
||||
|
||||
private List<JsonKilnRecipeHandler> includes = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public String getSubFolder()
|
||||
{
|
||||
|
@ -56,6 +60,35 @@ public class KilnConfig implements IJsonConfig
|
|||
return "{}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getIncludedJson(File subfolder)
|
||||
{
|
||||
List<String> res = new ArrayList<>();
|
||||
for (String fileName : mainRecipes.getIncludes())
|
||||
{
|
||||
File incf = new File(subfolder, fileName);
|
||||
if (!incf.exists())
|
||||
{
|
||||
LogUtil.log(Level.ERROR, "Included file not found: config/betterbeginnings/kiln/" +
|
||||
fileName + " - Skipping.");
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
res.add(new String(Files.readAllBytes(incf.toPath())));
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
LogUtil.log(Level.ERROR, "IOException occurred opening config/betterbeginnings/kiln/" + fileName);
|
||||
LogUtil.log("");
|
||||
LogUtil.log(Level.ERROR, ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyMain()
|
||||
{
|
||||
|
@ -73,6 +106,21 @@ public class KilnConfig implements IJsonConfig
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadIncludedConfig(FMLInitializationEvent e, List<String> includedJsons)
|
||||
{
|
||||
for (String json : includedJsons)
|
||||
{
|
||||
JsonKilnRecipeHandler handler = BBJsonLoader.deserializeObject(json, JsonKilnRecipeHandler.class);
|
||||
includes.add(handler);
|
||||
|
||||
for (JsonKilnRecipe r : handler.getRecipes())
|
||||
{
|
||||
r.register();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePostLoad(File subfolder)
|
||||
{
|
||||
|
|
|
@ -8,12 +8,15 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SmelterConfig implements IJsonConfig
|
||||
{
|
||||
public static final SmelterConfig INSTANCE = new SmelterConfig();
|
||||
|
||||
private JsonSmelterRecipeHandler mainRecipes = new JsonSmelterRecipeHandler();
|
||||
private List<JsonSmelterRecipeHandler> includes = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public String getSubFolder()
|
||||
|
@ -56,6 +59,35 @@ public class SmelterConfig implements IJsonConfig
|
|||
return "{}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getIncludedJson(File subfolder)
|
||||
{
|
||||
List<String> res = new ArrayList<>();
|
||||
for (String fileName : mainRecipes.getIncludes())
|
||||
{
|
||||
File incf = new File(subfolder, fileName);
|
||||
if (!incf.exists())
|
||||
{
|
||||
LogUtil.log(Level.ERROR, "Included file not found: config/betterbeginnings/smelter/" +
|
||||
fileName + " - Skipping.");
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
res.add(new String(Files.readAllBytes(incf.toPath())));
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
LogUtil.log(Level.ERROR, "IOException occurred opening config/betterbeginnings/smelter/" + fileName);
|
||||
LogUtil.log("");
|
||||
LogUtil.log(Level.ERROR, ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyMain()
|
||||
{
|
||||
|
@ -73,6 +105,21 @@ public class SmelterConfig implements IJsonConfig
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadIncludedConfig(FMLInitializationEvent e, List<String> includedJsons)
|
||||
{
|
||||
for (String json : includedJsons)
|
||||
{
|
||||
JsonSmelterRecipeHandler handler = BBJsonLoader.deserializeObject(json, JsonSmelterRecipeHandler.class);
|
||||
includes.add(handler);
|
||||
|
||||
for (JsonSmelterRecipe r : handler.getRecipes())
|
||||
{
|
||||
r.register();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePostLoad(File subfolder)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue