diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java index d5ba8dde..b1512e3a 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java @@ -63,15 +63,24 @@ public class CommandCreateDungeonRift extends DDCommandBase { result = findDungeonByPartialName(command[0], dungeonHelper.getUntaggedDungeons()); } - //Check if we found any matches + + // Check if we found any matches if (result != null) { - //Create a rift to our selected dungeon and notify the player dimension = PocketManager.getDimensionData(sender.worldObj); link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation); - PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result); - sender.worldObj.setBlock(x, y + 1, z, mod_pocketDim.blockRift.blockID, 0, 3); - sendChat(sender, "Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination().getDimension() + ")."); + if (PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result)) + { + // Create a rift to our selected dungeon and notify the player + sender.worldObj.setBlock(x, y + 1, z, mod_pocketDim.blockRift.blockID, 0, 3); + sendChat(sender, "Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination().getDimension() + ")."); + } + else + { + // Dungeon generation failed somehow. Notify the user and remove the useless link. + dimension.deleteLink(link); + sendChat(sender, "Dungeon generation failed unexpectedly!"); + } } else { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java index 013921b2..97cc1a59 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java @@ -69,15 +69,24 @@ public class CommandCreateRandomRift extends DDCommandBase { result = getRandomDungeonByPartialName(command[0], dungeonHelper.getUntaggedDungeons()); } - //Check if we found any matches + + // Check if we found any matches if (result != null) { - //Create a rift to our selected dungeon and notify the player dimension = PocketManager.getDimensionData(sender.worldObj); link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation); - PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result); - sender.worldObj.setBlock(x, y + 1, z, mod_pocketDim.blockRift.blockID, 0, 3); - sendChat(sender, "Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination().getDimension() + ")."); + if (PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result)) + { + // Create a rift to our selected dungeon and notify the player + sender.worldObj.setBlock(x, y + 1, z, mod_pocketDim.blockRift.blockID, 0, 3); + sendChat(sender, "Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination().getDimension() + ")."); + } + else + { + // Dungeon generation failed somehow. Notify the user and remove the useless link. + dimension.deleteLink(link); + sendChat(sender, "Dungeon generation failed unexpectedly!"); + } } else { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java index 877837f2..860bf4ce 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java @@ -145,7 +145,7 @@ public class PocketBuilder return true; } - public static boolean generateSelectedDungeonPocket(DimLink link, DDProperties properties, DungeonData data) + public static boolean generateSelectedDungeonPocket(DimLink link, DDProperties properties, DungeonData dungeon) { if (link == null) { @@ -155,13 +155,20 @@ public class PocketBuilder { throw new IllegalArgumentException("properties cannot be null."); } - if (link.hasDestination()) { throw new IllegalArgumentException("link cannot have a destination assigned already."); } + if (dungeon == null) + { + throw new IllegalArgumentException("dungeon cannot be null."); + } - //Register a new dimension + // Try to load up the schematic + DungeonSchematic schematic = null; + schematic = loadAndValidateDungeon(dungeon, properties); + + // Register a new dimension NewDimData parent = PocketManager.getDimensionData(link.source().getDimension()); NewDimData dimension = PocketManager.registerPocket(parent, true); @@ -174,17 +181,6 @@ public class PocketBuilder return false; } - DungeonData dungeon = null; - DungeonSchematic schematic = null; - - dungeon = data; - if (data == null) - { - System.err.println("Could not select a dungeon for generation!"); - return false; - } - schematic = loadAndValidateDungeon(dungeon, properties); - return PocketBuilder.buildDungeonPocket(dungeon, dimension, link, schematic, world, properties); } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/BaseGateway.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/BaseGateway.java index 92572b70..b19e8dfa 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/BaseGateway.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/BaseGateway.java @@ -73,7 +73,15 @@ public abstract class BaseGateway this.generateRandomBits(world, x, y, z); DimLink link = PocketManager.getDimensionData(world).createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation); - PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, this.getStartingDungeon(PocketManager.getDimensionData(world),world.rand)); + DungeonData dungeon = this.getStartingDungeon(PocketManager.getDimensionData(world), world.rand); + if (dungeon != null) + { + PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, dungeon); + } + else + { + System.err.println("Warning: Dimensional Doors was unable to assign a dungeon to a Rift Gateway."); + } return true; } @@ -107,7 +115,7 @@ public abstract class BaseGateway */ public DungeonData getStartingDungeon(NewDimData dimension, Random random) { - return getStartingPack().getNextDungeon(dimension,random); + return getStartingPack().getNextDungeon(dimension, random); } /**