Added configuration for blueprint input / output folders.
Changed default blueprint output folder. Added capability of defining several blueprint input folders for the library. Close #1717.
This commit is contained in:
parent
3e4378f565
commit
5131374073
2 changed files with 125 additions and 35 deletions
|
@ -20,6 +20,7 @@ import net.minecraft.entity.item.EntityPainting;
|
|||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
|
@ -34,6 +35,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
import buildcraft.api.blueprints.BlueprintDeployer;
|
||||
import buildcraft.api.blueprints.SchematicBlock;
|
||||
|
@ -42,6 +44,7 @@ import buildcraft.api.blueprints.SchematicFactory;
|
|||
import buildcraft.api.blueprints.SchematicMask;
|
||||
import buildcraft.api.blueprints.SchematicRegistry;
|
||||
import buildcraft.api.core.BCLog;
|
||||
import buildcraft.api.core.JavaTools;
|
||||
import buildcraft.api.filler.FillerManager;
|
||||
import buildcraft.api.filler.IFillerPattern;
|
||||
import buildcraft.api.gates.ActionManager;
|
||||
|
@ -147,14 +150,59 @@ public class BuildCraftBuilders extends BuildCraftMod {
|
|||
public void loadConfiguration(FMLPreInitializationEvent evt) {
|
||||
File bptMainDir = new File(new File(evt.getModConfigurationDirectory(), "buildcraft"), "blueprints");
|
||||
|
||||
String blueprintServerDir = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL,
|
||||
"blueprints.serverDir",
|
||||
"\"$MINECRAFT" + File.separator + "config" + File.separator + "buildcraft" + File.separator
|
||||
+ "blueprints" + File.separator + "server\"").getString();
|
||||
|
||||
String blueprintLibraryOutput = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL,
|
||||
"blueprints.libraryOutput", "\"$MINECRAFT" + File.separator + "blueprints\"").getString();
|
||||
|
||||
String [] blueprintLibraryInput = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL,
|
||||
"blueprints.libraryInput", new String []
|
||||
{
|
||||
// expected location
|
||||
"\"$MINECRAFT" + File.separator + "blueprints\"",
|
||||
// legacy beta BuildCraft
|
||||
"\"$MINECRAFT" + File.separator + "config" + File.separator + "buildcraft" + File.separator
|
||||
+ "blueprints" + File.separator + "client\"",
|
||||
// default Windows download location
|
||||
"\"$HOME" + File.separator + "Downloads\""
|
||||
}
|
||||
).getStringList().clone();
|
||||
|
||||
blueprintServerDir = JavaTools.stripSurroundingQuotes(replacePathVariables(blueprintServerDir));
|
||||
blueprintLibraryOutput = JavaTools.stripSurroundingQuotes(replacePathVariables(blueprintLibraryOutput));
|
||||
|
||||
for (int i = 0; i < blueprintLibraryInput.length; ++i) {
|
||||
blueprintLibraryInput[i] = JavaTools.stripSurroundingQuotes(replacePathVariables(blueprintLibraryInput[i]));
|
||||
}
|
||||
|
||||
if (BuildCraftCore.mainConfiguration.hasChanged()) {
|
||||
BuildCraftCore.mainConfiguration.save();
|
||||
}
|
||||
|
||||
File serverDir = new File (bptMainDir, "server");
|
||||
File clientDir = new File (bptMainDir, "client");
|
||||
|
||||
serverDB = new BlueprintDatabase();
|
||||
clientDB = new BlueprintDatabase();
|
||||
|
||||
serverDB.init(serverDir);
|
||||
clientDB.init(clientDir);
|
||||
serverDB.init(new String[] {blueprintServerDir}, blueprintServerDir);
|
||||
clientDB.init(blueprintLibraryInput, blueprintLibraryOutput);
|
||||
}
|
||||
|
||||
private String replacePathVariables(String path) {
|
||||
String result = path.replaceAll("\\$HOME", System.getProperty("user.home").replaceAll("\\\\", "\\\\\\\\"));
|
||||
|
||||
if (Launch.minecraftHome == null) {
|
||||
result = result.replaceAll("\\$MINECRAFT", new File(".").getAbsolutePath().replaceAll("\\\\", "\\\\\\\\"));
|
||||
} else {
|
||||
result = result.replaceAll("\\$MINECRAFT",
|
||||
Launch.minecraftHome.getAbsolutePath().replaceAll("\\\\", "\\\\\\\\"));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
|
|
@ -35,7 +35,8 @@ public class BlueprintDatabase {
|
|||
private static final int PAGE_SIZE = 12;
|
||||
|
||||
private final int bufferSize = 8192;
|
||||
private File blueprintFolder;
|
||||
private File outputDir;
|
||||
private File[] inputDirs;
|
||||
|
||||
private Set<BlueprintId> blueprintIds = new TreeSet<BlueprintId>();
|
||||
private BlueprintId [] pages = new BlueprintId [0];
|
||||
|
@ -45,14 +46,20 @@ public class BlueprintDatabase {
|
|||
*
|
||||
* @param configDir config directory to read the blueprints from.
|
||||
*/
|
||||
public void init(File configDir) {
|
||||
blueprintFolder = configDir;
|
||||
public void init(String[] inputPaths, String outputPath) {
|
||||
outputDir = new File(outputPath);
|
||||
|
||||
if (!blueprintFolder.exists()) {
|
||||
blueprintFolder.mkdirs();
|
||||
if (!outputDir.exists()) {
|
||||
outputDir.mkdirs();
|
||||
}
|
||||
|
||||
loadIndex();
|
||||
inputDirs = new File[inputPaths.length];
|
||||
|
||||
for (int i = 0; i < inputDirs.length; ++i) {
|
||||
inputDirs[i] = new File(inputPaths[i]);
|
||||
}
|
||||
|
||||
loadIndex(inputDirs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,17 +81,20 @@ public class BlueprintDatabase {
|
|||
|
||||
public void deleteBlueprint (BlueprintId id) {
|
||||
File blueprintFile = getBlueprintFile(id);
|
||||
blueprintFile.delete();
|
||||
blueprintIds.remove(id);
|
||||
pages = new BlueprintId [blueprintIds.size()];
|
||||
pages = blueprintIds.toArray(pages);
|
||||
|
||||
if (blueprintFile != null) {
|
||||
blueprintFile.delete();
|
||||
blueprintIds.remove(id);
|
||||
pages = new BlueprintId[blueprintIds.size()];
|
||||
pages = blueprintIds.toArray(pages);
|
||||
}
|
||||
}
|
||||
|
||||
private BlueprintId save(BlueprintBase blueprint) {
|
||||
blueprint.id.generateUniqueId(blueprint.getData());
|
||||
|
||||
BlueprintId id = blueprint.id;
|
||||
File blueprintFile = getBlueprintFile (id);
|
||||
File blueprintFile = getBlueprintFile(id, outputDir);
|
||||
|
||||
if (!blueprintFile.exists()) {
|
||||
OutputStream gzOs = null;
|
||||
|
@ -107,14 +117,44 @@ public class BlueprintDatabase {
|
|||
}
|
||||
|
||||
private File getBlueprintFile(BlueprintId id) {
|
||||
String name = "";
|
||||
|
||||
if (id.kind == Kind.Blueprint) {
|
||||
return new File(blueprintFolder, String.format(Locale.ENGLISH, "%s" + BPT_EXTENSION, id.toString()));
|
||||
name = String.format(Locale.ENGLISH, "%s" + BPT_EXTENSION, id.toString());
|
||||
} else {
|
||||
return new File(blueprintFolder, String.format(Locale.ENGLISH, "%s" + TPL_EXTENSION, id.toString()));
|
||||
name = String.format(Locale.ENGLISH, "%s" + TPL_EXTENSION, id.toString());
|
||||
}
|
||||
|
||||
for (File dir : inputDirs) {
|
||||
File f = new File(dir, name);
|
||||
|
||||
if (f.exists()) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private File getBlueprintFile(BlueprintId id, File folder) {
|
||||
String name = "";
|
||||
|
||||
if (id.kind == Kind.Blueprint) {
|
||||
name = String.format(Locale.ENGLISH, "%s" + BPT_EXTENSION, id.toString());
|
||||
} else {
|
||||
name = String.format(Locale.ENGLISH, "%s" + TPL_EXTENSION, id.toString());
|
||||
}
|
||||
|
||||
return new File(folder, name);
|
||||
}
|
||||
|
||||
private void loadIndex(File[] dirs) {
|
||||
for (File dir : dirs) {
|
||||
loadIndex(dir);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadIndex() {
|
||||
private void loadIndex(File directory) {
|
||||
FilenameFilter filter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
|
@ -122,31 +162,33 @@ public class BlueprintDatabase {
|
|||
}
|
||||
};
|
||||
|
||||
for (File blueprintFile : blueprintFolder.listFiles(filter)) {
|
||||
String fileName = blueprintFile.getName();
|
||||
if (directory.exists()) {
|
||||
for (File blueprintFile : directory.listFiles(filter)) {
|
||||
String fileName = blueprintFile.getName();
|
||||
|
||||
int cutIndex = fileName.lastIndexOf(BuildCraftBuilders.BPT_SEP_CHARACTER);
|
||||
int cutIndex = fileName.lastIndexOf(BuildCraftBuilders.BPT_SEP_CHARACTER);
|
||||
|
||||
String prefix = fileName.substring(0, cutIndex);
|
||||
String suffix = fileName.substring(cutIndex + 1);
|
||||
String prefix = fileName.substring(0, cutIndex);
|
||||
String suffix = fileName.substring(cutIndex + 1);
|
||||
|
||||
BlueprintId id = new BlueprintId();
|
||||
id.name = prefix;
|
||||
BlueprintId id = new BlueprintId();
|
||||
id.name = prefix;
|
||||
|
||||
if (suffix.contains(BPT_EXTENSION)) {
|
||||
id.uniqueId = BlueprintId.toBytes (suffix.replaceAll(BPT_EXTENSION, ""));
|
||||
id.kind = Kind.Blueprint;
|
||||
} else {
|
||||
id.uniqueId = BlueprintId.toBytes (suffix.replaceAll(TPL_EXTENSION, ""));
|
||||
id.kind = Kind.Template;
|
||||
if (suffix.contains(BPT_EXTENSION)) {
|
||||
id.uniqueId = BlueprintId.toBytes(suffix.replaceAll(BPT_EXTENSION, ""));
|
||||
id.kind = Kind.Blueprint;
|
||||
} else {
|
||||
id.uniqueId = BlueprintId.toBytes(suffix.replaceAll(TPL_EXTENSION, ""));
|
||||
id.kind = Kind.Template;
|
||||
}
|
||||
|
||||
if (!blueprintIds.contains(id)) {
|
||||
blueprintIds.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (!blueprintIds.contains(id)) {
|
||||
blueprintIds.add(id);
|
||||
}
|
||||
pages = blueprintIds.toArray(pages);
|
||||
}
|
||||
|
||||
pages = blueprintIds.toArray(pages);
|
||||
}
|
||||
|
||||
public boolean exists (BlueprintId id) {
|
||||
|
@ -168,7 +210,7 @@ public class BlueprintDatabase {
|
|||
}
|
||||
|
||||
public static BlueprintBase load (File blueprintFile) {
|
||||
if (blueprintFile.exists()) {
|
||||
if (blueprintFile != null && blueprintFile.exists()) {
|
||||
try {
|
||||
FileInputStream f = new FileInputStream(blueprintFile);
|
||||
byte [] data = new byte [(int) blueprintFile.length()];
|
||||
|
|
Loading…
Add table
Reference in a new issue