Various Updates #144

Merged
SenseiKiwi merged 28 commits from master into master 2014-03-24 18:45:47 +00:00
3 changed files with 37 additions and 27 deletions
Showing only changes of commit b1b1035b5f - Show all commits

View File

@@ -4,10 +4,10 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@@ -32,7 +32,6 @@ import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfig;
import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfigReader; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfigReader;
import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonType; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonType;
import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor; import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor;
import StevenDimDoors.mod_pocketDim.util.ConfigurationProcessingException;
import StevenDimDoors.mod_pocketDim.util.FileFilters; import StevenDimDoors.mod_pocketDim.util.FileFilters;
import StevenDimDoors.mod_pocketDim.util.WeightedContainer; import StevenDimDoors.mod_pocketDim.util.WeightedContainer;
@@ -48,10 +47,7 @@ public class DungeonHelper
private static final String DEFAULT_ERROR_SCHEMATIC_PATH = "/schematics/core/somethingBroke.schematic"; private static final String DEFAULT_ERROR_SCHEMATIC_PATH = "/schematics/core/somethingBroke.schematic";
private static final String DUNGEON_CREATION_GUIDE_SOURCE_PATH = "/mods/DimDoors/text/How_to_add_dungeons.txt"; private static final String DUNGEON_CREATION_GUIDE_SOURCE_PATH = "/mods/DimDoors/text/How_to_add_dungeons.txt";
private static final String RUINS_PACK_PATH = "/schematics/ruins"; private static final String BUNDLED_PACK_BASE_PATH = "/schematics/";
private static final String BUNDLED_RUINS_LIST_PATH = "/schematics/ruins.txt";
private static final String NETHER_PACK_PATH = "/schematics/nether";
private static final String BUNDLED_NETHER_LIST_PATH = "/schematics/nether.txt";
private static final String STANDARD_CONFIG_FILE_NAME = "rules.txt"; private static final String STANDARD_CONFIG_FILE_NAME = "rules.txt";
private static final int NETHER_DIMENSION_ID = -1; private static final int NETHER_DIMENSION_ID = -1;
@@ -158,7 +154,7 @@ public class DungeonHelper
return null; return null;
} }
private void registerDungeonPack(String directory, Iterable<String> schematics, boolean isInternal, boolean verbose, DungeonPackConfigReader reader) private DungeonPack registerDungeonPack(String directory, Iterable<String> schematics, boolean isInternal, boolean verbose, DungeonPackConfigReader reader)
{ {
//First determine the pack's name and validate it //First determine the pack's name and validate it
File packDirectory = new File(directory); File packDirectory = new File(directory);
@@ -187,7 +183,7 @@ public class DungeonHelper
if (config == null) if (config == null)
{ {
System.err.println("Could not load config file: " + configPath); System.err.println("Could not load config file: " + configPath);
return; return null;
} }
//Register the pack //Register the pack
@@ -208,6 +204,7 @@ public class DungeonHelper
{ {
registerDungeon(schematicPath, pack, isInternal, verbose); registerDungeon(schematicPath, pack, isInternal, verbose);
} }
return pack;
} }
public List<DungeonData> getRegisteredDungeons() public List<DungeonData> getRegisteredDungeons()
@@ -235,6 +232,7 @@ public class DungeonHelper
{ {
// TODO: Drop support for dim-based packs and switch to embedding the pack // TODO: Drop support for dim-based packs and switch to embedding the pack
// in the link data itself. That would solve the dungeon pre-generation issue. // in the link data itself. That would solve the dungeon pre-generation issue.
// Gateways should dictate which packs are being used, not the dimensions.
DungeonPack pack; DungeonPack pack;
DungeonData dungeon = dimension.dungeon(); DungeonData dungeon = dimension.dungeon();
@@ -436,32 +434,31 @@ public class DungeonHelper
defaultError = new DungeonData(DEFAULT_ERROR_SCHEMATIC_PATH, true, DungeonType.UNKNOWN_TYPE, true, DEFAULT_DUNGEON_WEIGHT); defaultError = new DungeonData(DEFAULT_ERROR_SCHEMATIC_PATH, true, DungeonType.UNKNOWN_TYPE, true, DEFAULT_DUNGEON_WEIGHT);
//Open the list of dungeons packaged with our mod and register their schematics //Open the list of dungeons packaged with our mod and register their schematics
registerBundledPack(BUNDLED_RUINS_LIST_PATH, RUINS_PACK_PATH, "Ruins", reader); RuinsPack = registerBundledPack("Ruins", reader);
RuinsPack = getDungeonPack("Ruins"); NetherPack = registerBundledPack("Nether", reader);
registerBundledPack("Balgor", reader);
registerBundledPack(BUNDLED_NETHER_LIST_PATH, NETHER_PACK_PATH, "Nether", reader);
NetherPack = getDungeonPack("Nether");
System.out.println("Finished registering bundled dungeon packs"); System.out.println("Finished registering bundled dungeon packs");
} }
private void registerBundledPack(String listPath, String packPath, String name, DungeonPackConfigReader reader) private DungeonPack registerBundledPack(String name, DungeonPackConfigReader reader)
{ {
System.out.println("Registering bundled dungeon pack: " + name); System.out.println("Registering bundled dungeon pack: " + name);
String packPath = BUNDLED_PACK_BASE_PATH + name.toLowerCase();
String listPath = packPath + ".txt";
InputStream listStream = this.getClass().getResourceAsStream(listPath); InputStream listStream = this.getClass().getResourceAsStream(listPath);
// chance of leak?
if (listStream == null) if (listStream == null)
{ {
System.err.println("Unable to open list of bundled dungeon schematics for " + name); throw new IllegalStateException("Failed to open the list of bundled dungeon schematics for " + name);
return;
} }
ArrayList<String> schematics = new ArrayList<String>();
try try
{ {
//Read the list of schematics that come with a bundled pack // Read the list of schematics that come with a bundled pack
BufferedReader listReader = new BufferedReader(new InputStreamReader(listStream)); BufferedReader listReader = new BufferedReader(new InputStreamReader(listStream));
ArrayList<String> schematics = new ArrayList<String>();
String schematicPath = listReader.readLine(); String schematicPath = listReader.readLine();
while (schematicPath != null) while (schematicPath != null)
{ {
@@ -473,15 +470,19 @@ public class DungeonHelper
schematicPath = listReader.readLine(); schematicPath = listReader.readLine();
} }
listReader.close(); listReader.close();
//Register the pack
registerDungeonPack(packPath, schematics, true, false, reader);
} }
catch (Exception e) catch (IOException e)
{ {
System.err.println("An exception occurred while reading the list of bundled dungeon schematics for " + name); throw new RuntimeException("An unexpected error occured while trying to read the list of schematics for the " + name + " bundled dungeon pack. This would inevitably cause Dimensional Doors to crash during runtime.", e);
e.printStackTrace();
} }
// Register the pack
DungeonPack pack = registerDungeonPack(packPath, schematics, true, false, reader);
if (pack == null)
{
throw new RuntimeException("Failed to load the " + name + " bundled dungeon pack. This would inevitably cause Dimensional Doors to crash during runtime.");
}
return pack;
} }
public boolean exportDungeon(World world, int centerX, int centerY, int centerZ, String exportPath) public boolean exportDungeon(World world, int centerX, int centerY, int centerZ, String exportPath)

View File

@@ -104,8 +104,13 @@ public class PocketBuilder
return false; return false;
} }
DungeonSchematic schematic = loadAndValidateDungeon(dimension.dungeon(), properties);
if (schematic == null)
{
return false;
}
Point3D destination = new Point3D(incomingLink.destination()); Point3D destination = new Point3D(incomingLink.destination());
loadAndValidateDungeon(dimension.dungeon(), properties).copyToWorld(world, destination, originLink.orientation(), incomingLink, random, properties, false); schematic.copyToWorld(world, destination, originLink.orientation(), incomingLink, random, properties, false);
dimension.setFilled(true); dimension.setFilled(true);
return true; return true;
} }
@@ -167,6 +172,10 @@ public class PocketBuilder
// Try to load up the schematic // Try to load up the schematic
DungeonSchematic schematic = null; DungeonSchematic schematic = null;
schematic = loadAndValidateDungeon(dungeon, properties); schematic = loadAndValidateDungeon(dungeon, properties);
if (schematic == null)
{
return false;
}
// Register a new dimension // Register a new dimension
NewDimData parent = PocketManager.getDimensionData(link.source().getDimension()); NewDimData parent = PocketManager.getDimensionData(link.source().getDimension());

View File

@@ -12,7 +12,7 @@ AllowPackChangeIn = true
Rules: Rules:
? ? ? -> ? ? ? -> ?
? ? -> Maze#20 ComplexHall#40 Trap#40 ? ? -> Maze#20 ComplexHall#40 Trap#40