From 0b9f8fa5d5b89965cc179384bbaa9105de35bc71 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 1 Aug 2013 13:00:27 -0400 Subject: [PATCH] Improved DungeonHelper Completed changes so that our code uses registerDungeon() (formerly registerCustomDungeons() ) to register all dungeons, both bundled with the mod and custom ones. Made some changes to the code to hide implementation details from other classes. Also, I had some problems with old dungeons being mixed into the renamed ones. I had to remove fallingTNThall from the schematics folder and deleted the WIP folder because I think we have completed versions of those schematics already. Some of our dungeons have pre-filled chests and the contents are more generous than our current loot system (e.g. ruinsO has a prefilled chest). I'll have to wipe all the chests later. --- .../mod_pocketDim/SchematicLoader.java | 4 +- .../commands/CommandExportDungeon.java | 2 +- .../mod_pocketDim/helpers/DungeonHelper.java | 92 +++++++++++++++--- ...smallRotundaWithExit_closed_100.schematic} | Bin .../trap_fallingTNThall_closed_100.schematic | Bin 1420 -> 0 bytes .../trap_pistonHallway_closed_100.schematic} | Bin schematics/schematics.txt | 67 +++++++++++++ 7 files changed, 150 insertions(+), 15 deletions(-) rename schematics/{wip/complexHall_smallRotundaWithExit_closed_100_NOT DONE.schematic => ruins/complexHall_smallRotundaWithExit_closed_100.schematic} (100%) delete mode 100644 schematics/ruins/trap_fallingTNThall_closed_100.schematic rename schematics/{wip/trap_pistonHallway_closed_100_NOTDONE.schematic => ruins/trap_pistonHallway_closed_100.schematic} (100%) create mode 100644 schematics/schematics.txt diff --git a/StevenDimDoors/mod_pocketDim/SchematicLoader.java b/StevenDimDoors/mod_pocketDim/SchematicLoader.java index 58d08b2..5fc8603 100644 --- a/StevenDimDoors/mod_pocketDim/SchematicLoader.java +++ b/StevenDimDoors/mod_pocketDim/SchematicLoader.java @@ -71,7 +71,9 @@ public class SchematicLoader //TODO: In the future, remove this dungeon from the generation lists altogether. //That will have to wait until our code is updated to support that more easily. System.err.println("The dungeon will not be loaded."); - dungeon = checkSourceAndLoad(DungeonHelper.instance().defaultBreak.schematicPath); + DungeonGenerator defaultError = DungeonHelper.instance().getDefaultErrorDungeon(); + dimList.get(destDimID).dungeonGenerator = defaultError; + dungeon = checkSourceAndLoad(defaultError.schematicPath); dungeon.applyImportFilters(properties); } diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandExportDungeon.java b/StevenDimDoors/mod_pocketDim/commands/CommandExportDungeon.java index 9ba047c..ff833b3 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandExportDungeon.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandExportDungeon.java @@ -132,7 +132,7 @@ public class CommandExportDungeon extends DDCommandBase if (dungeonHelper.exportDungeon(player.worldObj, x, y, z, exportPath)) { player.sendChatToPlayer("Saved dungeon schematic in " + exportPath); - dungeonHelper.registerCustomDungeon(new File(exportPath)); + dungeonHelper.registerDungeon(exportPath, false, true); return DDCommandResult.SUCCESS; } else diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 5d57357..0a280db 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -1,6 +1,9 @@ package StevenDimDoors.mod_pocketDim.helpers; +import java.io.BufferedReader; import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -27,6 +30,11 @@ public class DungeonHelper private static DDProperties properties = null; public static final Pattern SchematicNamePattern = Pattern.compile("[A-Za-z0-9_\\-]+"); public static final Pattern DungeonNamePattern = Pattern.compile("[A-Za-z0-9\\-]+"); + + private static final String DEFAULT_UP_SCHEMATIC_PATH = "/schematics/core/simpleStairsUp.schematic"; + private static final String DEFAULT_DOWN_SCHEMATIC_PATH = "/schematics/core/simpleStairsDown.schematic"; + private static final String DEFAULT_ERROR_SCHEMATIC_PATH = "/schematics/core/somethingBroke.schematic"; + private static final String BUNDLED_DUNGEONS_LIST_PATH = "/schematics/schematics.txt"; public static final String SCHEMATIC_FILE_EXTENSION = ".schematic"; private static final int DEFAULT_DUNGEON_WEIGHT = 100; @@ -71,9 +79,10 @@ public class DungeonHelper private ArrayList mazes = new ArrayList(); private ArrayList pistonTraps = new ArrayList(); private ArrayList exits = new ArrayList(); - - public DungeonGenerator defaultBreak = new DungeonGenerator(DEFAULT_DUNGEON_WEIGHT, "/schematics/somethingBroke.schematic", true); - public DungeonGenerator defaultUp = new DungeonGenerator(DEFAULT_DUNGEON_WEIGHT, "/schematics/simpleStairsUp.schematic", true); + + private DungeonGenerator defaultUp; + private DungeonGenerator defaultDown; + private DungeonGenerator defaultError; private HashSet dungeonTypeChecker; private HashMap> dungeonTypeMapping; @@ -138,8 +147,8 @@ public class DungeonHelper { copyfile.copyFile("/mods/DimDoors/text/How_to_add_dungeons.txt", file.getAbsolutePath() + "/How_to_add_dungeons.txt"); } + registerBundledDungeons(); importCustomDungeons(properties.CustomSchematicDirectory); - registerBaseDungeons(); } public List getRegisteredDungeons() @@ -152,6 +161,21 @@ public class DungeonHelper return Collections.unmodifiableList(this.untaggedDungeons); } + public DungeonGenerator getDefaultErrorDungeon() + { + return defaultError; + } + + public DungeonGenerator getDefaultUpDungeon() + { + return defaultUp; + } + + public DungeonGenerator getDefaultDownDungeon() + { + return defaultDown; + } + public LinkData createCustomDungeonDoor(World world, int x, int y, int z) { //Create a link above the specified position. Link to a new pocket dimension. @@ -213,10 +237,13 @@ public class DungeonHelper return true; } - public void registerCustomDungeon(File schematicFile) + public void registerDungeon(String schematicPath, boolean isInternal, boolean verbose) { + //We use schematicPath as the real path for internal files (inside our JAR) because it seems + //that File tries to interpret it as a local drive path and mangles it. + File schematicFile = new File(schematicPath); String name = schematicFile.getName(); - String path = schematicFile.getAbsolutePath(); + String path = isInternal ? schematicPath : schematicFile.getAbsolutePath(); try { if (validateSchematicName(name)) @@ -233,23 +260,29 @@ public class DungeonHelper dungeonTypeMapping.get(dungeonType).add(generator); registeredDungeons.add(generator); - System.out.println("Imported " + name); + if (verbose) + { + System.out.println("Registered dungeon: " + name); + } } else { - System.out.println("Could not parse dungeon filename, not adding dungeon to generation lists"); + if (verbose) + { + System.out.println("Could not parse dungeon filename, not adding dungeon to generation lists"); + } untaggedDungeons.add(new DungeonGenerator(DEFAULT_DUNGEON_WEIGHT, path, true)); - System.out.println("Imported " + name); + System.out.println("Registered untagged dungeon: " + name); } } catch(Exception e) { + System.err.println("Failed to register dungeon: " + name); e.printStackTrace(); - System.out.println("Failed to import " + name); } } - public void importCustomDungeons(String path) + private void importCustomDungeons(String path) { File directory = new File(path); File[] schematicNames = directory.listFiles(); @@ -260,15 +293,48 @@ public class DungeonHelper { if (schematicFile.getName().endsWith(SCHEMATIC_FILE_EXTENSION)) { - registerCustomDungeon(schematicFile); + registerDungeon(schematicFile.getPath(), false, true); } } } } - public void registerBaseDungeons() + private void registerBundledDungeons() { + //Register the core schematics + //These are used for debugging and in case of unusual errors while loading dungeons + defaultUp = new DungeonGenerator(DEFAULT_DUNGEON_WEIGHT, DEFAULT_UP_SCHEMATIC_PATH, true); + defaultDown = new DungeonGenerator(DEFAULT_DUNGEON_WEIGHT, DEFAULT_DOWN_SCHEMATIC_PATH, true); + defaultError = new DungeonGenerator(DEFAULT_DUNGEON_WEIGHT, DEFAULT_ERROR_SCHEMATIC_PATH, true); + //Open the list of dungeons packaged with our mod and register their schematics + InputStream listStream = this.getClass().getResourceAsStream(BUNDLED_DUNGEONS_LIST_PATH); + if (listStream == null) + { + System.err.println("Unable to open list of bundled dungeon schematics."); + return; + } + + try + { + BufferedReader listReader = new BufferedReader(new InputStreamReader(listStream)); + String schematicPath = listReader.readLine(); + while (schematicPath != null) + { + schematicPath = schematicPath.trim(); + if (!schematicPath.isEmpty()) + { + registerDungeon(schematicPath, true, false); + } + schematicPath = listReader.readLine(); + } + listReader.close(); + } + catch (Exception e) + { + System.err.println("An exception occurred while reading the list of bundled dungeon schematics."); + e.printStackTrace(); + } } public boolean exportDungeon(World world, int centerX, int centerY, int centerZ, String exportPath) diff --git a/schematics/wip/complexHall_smallRotundaWithExit_closed_100_NOT DONE.schematic b/schematics/ruins/complexHall_smallRotundaWithExit_closed_100.schematic similarity index 100% rename from schematics/wip/complexHall_smallRotundaWithExit_closed_100_NOT DONE.schematic rename to schematics/ruins/complexHall_smallRotundaWithExit_closed_100.schematic diff --git a/schematics/ruins/trap_fallingTNThall_closed_100.schematic b/schematics/ruins/trap_fallingTNThall_closed_100.schematic deleted file mode 100644 index 819575f74c5876fd58ccb9e12ddc730442d27145..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1420 zcmb2|=3sz;w|DpUiMWfjJ!IP4G|x5HC0z@v(CSCzRdS6ZO6wCFS`%h&y$h2o!gpi zZ)aI2bg12(5o#3!!+|i18>NgpY~tVSY6!C6xLy`}=vtxMn!?oUtO|#w@77~Du+5{Q ze;Y_cgJ@0vv44fXzb)Cmduzfa>vQ}Twz4; z#)i;!ZLj(H;_dD01mB%G)cbzE?eB+I=ljR+<9+ya`))nn8&>)MqMTK3Iek$(`D^~f zPO-OIvu3`?Tr|_#FXYJ26u z+(XaXzg*7i#l@&db)93YN|-$(BXHrxoCC9JdwjO6SbM^y`&QRE^Glkg-h(Dnfn6qAs;4m02bzmMl8@{^GB%A71?I zeq8X}?Z>O_i^JRP_uAQ6*;&<87aQISKYZ}L`+2|m)7QTC?@xMtcyT=g!`9E`TsmUi zq3u`w>yGD~?n~Pk@jLBnnaOI+?AisVS7iHW`_vtOxwh6KdDhj^yRQPo1Fug=b+5nY zb<3yr()|;jVfK%Om!W#abY1E83%lIjCcoMmb|z7K-_uKLkL)_O`B3wU&=b2o z|5{f)`2WBDkx*KSFCr z?>o2p+^?VhDbJ`yw)P;`>>Vws?(eTzy_{C}XXo`-zuzsn_v-t@p4%(_)lMq4-xI%m z+Q!AlHyu*bOVr(GGiBHQRof@cdz;t7d*NzK?cMY@hOLg@&TO>PuRSyn}|1NpG`tQwG zm(xm3UWZg0r08De*UhxHI?OdY!F5eH^Iyr;{F-4e zQ*Y%0Q`c;$iDunLSDozwd39;o?4wCn)1Y2Do3t?t=A?l&e%8^XjS=3{WPvV