Integrated Balgor Pack and Fixed Bugs

* Set up the necessary code in DungeonHelper so that Balgor is
registered along with the other bundled packs.
* Improved the code for registering bundled packs to reduce the number
of paths we need to hardcode and to crash DD if a pack fails to load. A
crash would be inevitable no matter what since bundled packs are
integral to DD.
* Corrected an invalid generation rule for Balgor. It's set to select
random dungeons infinitely for now. I'll add an exit room later and
change the rule to force an exit. Balgor is still unusable until its
schematics get proper doors.
* Fixed PocketBuilder to actually check the results of validating
schematics before we try to build them. This was causing cryptic error
messages when flawed schematics were loaded (e.g. rooms without proper
doors) and could have caused serious problems during dungeon
regeneration. Don't ignore validation!
This commit is contained in:
SenseiKiwi 2014-03-17 19:03:32 -04:00
parent f8982a871d
commit b1b1035b5f
3 changed files with 37 additions and 27 deletions

View file

@ -4,10 +4,10 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
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.DungeonType;
import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor;
import StevenDimDoors.mod_pocketDim.util.ConfigurationProcessingException;
import StevenDimDoors.mod_pocketDim.util.FileFilters;
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 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_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 BUNDLED_PACK_BASE_PATH = "/schematics/";
private static final String STANDARD_CONFIG_FILE_NAME = "rules.txt";
private static final int NETHER_DIMENSION_ID = -1;
@ -158,7 +154,7 @@ public class DungeonHelper
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
File packDirectory = new File(directory);
@ -187,7 +183,7 @@ public class DungeonHelper
if (config == null)
{
System.err.println("Could not load config file: " + configPath);
return;
return null;
}
//Register the pack
@ -208,6 +204,7 @@ public class DungeonHelper
{
registerDungeon(schematicPath, pack, isInternal, verbose);
}
return pack;
}
public List<DungeonData> getRegisteredDungeons()
@ -235,6 +232,7 @@ public class DungeonHelper
{
// 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.
// Gateways should dictate which packs are being used, not the dimensions.
DungeonPack pack;
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);
//Open the list of dungeons packaged with our mod and register their schematics
registerBundledPack(BUNDLED_RUINS_LIST_PATH, RUINS_PACK_PATH, "Ruins", reader);
RuinsPack = getDungeonPack("Ruins");
registerBundledPack(BUNDLED_NETHER_LIST_PATH, NETHER_PACK_PATH, "Nether", reader);
NetherPack = getDungeonPack("Nether");
RuinsPack = registerBundledPack("Ruins", reader);
NetherPack = registerBundledPack("Nether", reader);
registerBundledPack("Balgor", reader);
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);
String packPath = BUNDLED_PACK_BASE_PATH + name.toLowerCase();
String listPath = packPath + ".txt";
InputStream listStream = this.getClass().getResourceAsStream(listPath);
// chance of leak?
if (listStream == null)
{
System.err.println("Unable to open list of bundled dungeon schematics for " + name);
return;
throw new IllegalStateException("Failed to open the list of bundled dungeon schematics for " + name);
}
ArrayList<String> schematics = new ArrayList<String>();
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));
ArrayList<String> schematics = new ArrayList<String>();
String schematicPath = listReader.readLine();
while (schematicPath != null)
{
@ -473,15 +470,19 @@ public class DungeonHelper
schematicPath = listReader.readLine();
}
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);
e.printStackTrace();
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);
}
// 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)

View file

@ -104,8 +104,13 @@ public class PocketBuilder
return false;
}
DungeonSchematic schematic = loadAndValidateDungeon(dimension.dungeon(), properties);
if (schematic == null)
{
return false;
}
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);
return true;
}
@ -167,6 +172,10 @@ public class PocketBuilder
// Try to load up the schematic
DungeonSchematic schematic = null;
schematic = loadAndValidateDungeon(dungeon, properties);
if (schematic == null)
{
return false;
}
// Register a new dimension
NewDimData parent = PocketManager.getDimensionData(link.source().getDimension());

View file

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