diff --git a/StevenDimDoors/mod_pocketDim/Point3D.java b/StevenDimDoors/mod_pocketDim/Point3D.java index 7a3d357d..f44d0fe5 100644 --- a/StevenDimDoors/mod_pocketDim/Point3D.java +++ b/StevenDimDoors/mod_pocketDim/Point3D.java @@ -2,6 +2,8 @@ package StevenDimDoors.mod_pocketDim; import java.io.Serializable; +import StevenDimDoors.mod_pocketDim.util.Point4D; + public class Point3D implements Serializable { private static final long serialVersionUID = -9044026830605287190L; @@ -16,6 +18,13 @@ public class Point3D implements Serializable { this.y = y; this.z = z; } + + public Point3D(Point4D point) + { + this.x = point.getX(); + this.y = point.getY(); + this.z = point.getZ(); + } public int getX() { diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java b/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java index c15b4588..8eff0aa6 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java @@ -4,7 +4,10 @@ import java.util.Collection; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.MathHelper; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.core.LinkTypes; +import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; @@ -29,6 +32,7 @@ public class CommandCreateDungeonRift extends DDCommandBase @Override protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { + NewDimData dimension; DungeonHelper dungeonHelper = DungeonHelper.instance(); if (sender.worldObj.isRemote) @@ -60,13 +64,16 @@ public class CommandCreateDungeonRift extends DDCommandBase int x = MathHelper.floor_double(sender.posX); int y = MathHelper.floor_double(sender.posY); int z = MathHelper.floor_double (sender.posZ); - + int orientation = MathHelper.floor_double((double) ((sender.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; + if (command[0].equals("random")) { - link = new NewLinkData(sender.worldObj.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3); - PocketManager.createLink(link); - link = PocketManager.createPocket(link, true, true); - sender.sendChatToPlayer("Created a rift to a random dungeon (Dimension ID = " + link.destDimID + ")."); + + dimension = PocketManager.getDimensionData(sender.worldObj); + link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON); + sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID,0,3); + + sender.sendChatToPlayer("Created a rift to a random dungeon."); } else { @@ -79,10 +86,11 @@ public class CommandCreateDungeonRift extends DDCommandBase if (result != null) { //Create a rift to our selected dungeon and notify the player - link = new NewLinkData(sender.worldObj.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3); - link = PocketManager.instance.createPocket(link, true, true); - PocketManager.instance.getDimData(link.destDimID).dungeonGenerator = result; - sender.sendChatToPlayer("Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination.getDimensionID() + ")."); + dimension = PocketManager.getDimensionData(sender.worldObj); + link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON); + PocketManager.getDimensionData(link.destination().getDimension()).initializeDungeon(x, y + 1, z, orientation,link, result); + sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID,0,3); + sender.sendChatToPlayer("Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination().getDimension() + ")."); } else { diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java index 55b307ba..4b2cf423 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java @@ -4,8 +4,9 @@ import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; +import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; -import StevenDimDoors.mod_pocketDim.core.ILinkData; import StevenDimDoors.mod_pocketDim.core.PocketManager; public class CommandDeleteAllLinks extends DDCommandBase @@ -32,53 +33,34 @@ public class CommandDeleteAllLinks extends DDCommandBase int targetDim; boolean shouldGo= true; - if(command.length==0) - { - targetDim= sender.worldObj.provider.dimensionId; - } - else if(command.length==1) + if(command.length==1) { targetDim = parseInt(sender, command[0]); - if (!PocketManager.dimList.containsKey(targetDim)) - { - sender.sendChatToPlayer("Error- dim "+targetDim+" not registered"); - shouldGo=false; - } } else { targetDim=0; shouldGo=false; - sender.sendChatToPlayer("Error-Invalid argument, delete_all_links or blank for current dim"); + sender.sendChatToPlayer("Error-Invalid argument, delete_all_links "); } if(shouldGo) { - if(PocketManager.dimList.containsKey(targetDim)) - { - NewDimData dim = PocketManager.instance.getDimData(targetDim); - ArrayList linksInDim = dim.getLinksInDim(); + + NewDimData dim = PocketManager.getDimensionData(targetDim); + ArrayList linksInDim = dim.getAllLinks(); - for (ILinkData link : linksInDim) + for (DimLink link : linksInDim) { - World targetWorld = PocketManager.getWorld(targetDim); + World targetWorld = PocketManager.loadDimension(targetDim); + targetWorld.setBlock(link.source().getX(), link.source().getY(), link.source().getZ(), 0); + dim.deleteLink(link); + //TODO Probably should check what the block is, but thats annoying so Ill do it later. - if(targetWorld==null) - { - PocketManager.initDimension(targetDim); - } - else if(targetWorld.provider==null) - { - PocketManager.initDimension(targetDim); - } - targetWorld = PocketManager.getWorld(targetDim); - dim.removeLinkAtCoords(link); - targetWorld.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, 0); linksRemoved++; } - //dim.linksInThisDim.clear(); sender.sendChatToPlayer("Removed " + linksRemoved + " links."); - } + } return DDCommandResult.SUCCESS; //TEMPORARY HACK } diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java deleted file mode 100644 index 7d654358..00000000 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java +++ /dev/null @@ -1,95 +0,0 @@ -package StevenDimDoors.mod_pocketDim.commands; - -import java.util.ArrayList; -import java.util.Collection; - -import net.minecraft.entity.player.EntityPlayer; -import StevenDimDoors.mod_pocketDim.core.NewDimData; -import StevenDimDoors.mod_pocketDim.core.ILinkData; -import StevenDimDoors.mod_pocketDim.core.PocketManager; - -public class CommandDeleteDimensionData extends DDCommandBase -{ - private static CommandDeleteDimensionData instance = null; - - private CommandDeleteDimensionData() - { - super("dd-deletedimension", "???"); - } - - public static CommandDeleteDimensionData instance() - { - if (instance == null) - instance = new CommandDeleteDimensionData(); - - return instance; - } - - @Override - protected DDCommandResult processCommand(EntityPlayer sender, String[] command) - { - int linksRemoved=0; - int targetDim; - boolean shouldGo= true; - - if (command.length==0) - { - targetDim= sender.worldObj.provider.dimensionId; - } - else if (command.length==1) - { - targetDim = parseInt(sender, command[0]); - if(!PocketManager.dimList.containsKey(targetDim)) - { - sender.sendChatToPlayer("Error- dim "+targetDim+" not registered"); - shouldGo=false; - } - } - else - { - targetDim=0; - shouldGo=false; - sender.sendChatToPlayer("Error-Invalid argument, delete_dim_data or blank for current dim"); - } - - if(shouldGo) - { - if(PocketManager.dimList.containsKey(targetDim)) - { - try - { - for(NewDimData newDimData :PocketManager.dimList.values()) - { - Collection links= new ArrayList(); - links.addAll( newDimData.getLinksInDim()); - - for(ILinkData link : links) - { - if(link.destDimID==targetDim) - { - PocketManager.instance.getDimData(link.locDimID).removeLinkAtCoords(link); - linksRemoved++; - } - if(newDimData.dimID==targetDim) - { - linksRemoved++; - } - } - } - } - catch(Exception e) - { - e.printStackTrace(); - } - - PocketManager.dimList.remove(targetDim); - sender.sendChatToPlayer("Removed dimension " + targetDim + " from DimDoors and deleted " + linksRemoved + " links"); - } - else - { - sender.sendChatToPlayer("Error- dimension "+targetDim+" not registered with dimDoors"); - } - } - return DDCommandResult.SUCCESS; //TEMPORARY HACK - } -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java index 529cf20f..61668d70 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java @@ -5,8 +5,8 @@ import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; -import StevenDimDoors.mod_pocketDim.core.ILinkData; import StevenDimDoors.mod_pocketDim.core.PocketManager; public class CommandDeleteRifts extends DDCommandBase @@ -33,56 +33,36 @@ public class CommandDeleteRifts extends DDCommandBase int targetDim; boolean shouldGo= true; - if(command.length==0) - { - targetDim= sender.worldObj.provider.dimensionId; - } - else if(command.length==1) + if(command.length==1) { targetDim = parseInt(sender, command[0]); - if(!PocketManager.dimList.containsKey(targetDim)) - { - sender.sendChatToPlayer("Error- dim "+targetDim+" not registered"); - shouldGo=false; - } } else { targetDim=0; shouldGo=false; - sender.sendChatToPlayer("Error-Invalid argument, delete_links or blank for current dim"); + sender.sendChatToPlayer("Error-Invalid argument, delete_all_links "); } if(shouldGo) { - if(PocketManager.dimList.containsKey(targetDim)) - { - NewDimData dim = PocketManager.instance.getDimData(targetDim); - ArrayList linksInDim = dim.getLinksInDim(); + + NewDimData dim = PocketManager.getDimensionData(targetDim); + ArrayList linksInDim = dim.getAllLinks(); - for(ILinkData link : linksInDim) + for (DimLink link : linksInDim) { - World targetWorld = PocketManager.getWorld(targetDim); - - if(targetWorld==null) + World targetWorld = PocketManager.loadDimension(targetDim); + + if(sender.worldObj.getBlockId(link.source().getX(), link.source().getY(), link.source().getZ())==mod_pocketDim.blockRift.blockID) { - PocketManager.initDimension(targetDim); - } - else if(targetWorld.provider==null) - { - PocketManager.initDimension(targetDim); - } - targetWorld = PocketManager.getWorld(targetDim); - - if (targetWorld.getBlockId(link.locXCoord, link.locYCoord, link.locZCoord) == mod_pocketDim.blockRift.blockID) - { - dim.removeLinkAtCoords(link); - targetWorld.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, 0); + targetWorld.setBlock(link.source().getX(), link.source().getY(), link.source().getZ(), 0); linksRemoved++; + dim.deleteLink(link); } } - sender.sendChatToPlayer("Removed "+linksRemoved+" rifts."); - } + sender.sendChatToPlayer("Removed " + linksRemoved + " rifts."); + } return DDCommandResult.SUCCESS; //TEMPORARY HACK } diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java b/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java deleted file mode 100644 index e4a99c61..00000000 --- a/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java +++ /dev/null @@ -1,69 +0,0 @@ -package StevenDimDoors.mod_pocketDim.commands; - -import java.util.ArrayList; - -import net.minecraft.entity.player.EntityPlayer; -import StevenDimDoors.mod_pocketDim.core.NewDimData; -import StevenDimDoors.mod_pocketDim.core.ILinkData; -import StevenDimDoors.mod_pocketDim.core.PocketManager; - -public class CommandPrintDimensionData extends DDCommandBase -{ - private static CommandPrintDimensionData instance = null; - - private CommandPrintDimensionData() - { - super("dd-dimensiondata", "[dimension number]"); - } - - public static CommandPrintDimensionData instance() - { - if (instance == null) - instance = new CommandPrintDimensionData(); - - return instance; - } - - @Override - protected DDCommandResult processCommand(EntityPlayer sender, String[] command) - { - int targetDim; - NewDimData newDimData; - - if (command.length == 0) - { - targetDim = sender.worldObj.provider.dimensionId; - } - else if (command.length == 1) - { - try - { - targetDim = Integer.parseInt(command[0]); - } - catch (Exception ex) - { - return DDCommandResult.INVALID_DIMENSION_ID; - } - } - else - { - return DDCommandResult.TOO_MANY_ARGUMENTS; - } - - newDimData = PocketManager.instance.getDimData(targetDim); - if (newDimData == null) - { - return DDCommandResult.UNREGISTERED_DIMENSION; - } - - ArrayList links = newDimData.getLinksInDim(); - - sender.sendChatToPlayer("Dimension ID = " + newDimData.dimID); - sender.sendChatToPlayer("Dimension Depth = " + newDimData.depth); - for (ILinkData link : links) - { - sender.sendChatToPlayer(link.printLinkData()); - } - return DDCommandResult.SUCCESS; - } -} diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java b/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java deleted file mode 100644 index faee05f7..00000000 --- a/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java +++ /dev/null @@ -1,73 +0,0 @@ -package StevenDimDoors.mod_pocketDim.commands; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import net.minecraft.entity.player.EntityPlayer; -import StevenDimDoors.mod_pocketDim.core.NewDimData; -import StevenDimDoors.mod_pocketDim.core.ILinkData; -import StevenDimDoors.mod_pocketDim.core.PocketManager; - -public class CommandPruneDimensions extends DDCommandBase -{ - private static CommandPruneDimensions instance = null; - - private CommandPruneDimensions() - { - super("dd-prune", "['delete']"); - } - - public static CommandPruneDimensions instance() - { - if (instance == null) - instance = new CommandPruneDimensions(); - - return instance; - } - - @Override - protected DDCommandResult processCommand(EntityPlayer sender, String[] command) - { - if (command.length > 1) - { - return DDCommandResult.TOO_MANY_ARGUMENTS; - } - if (command.length == 1 && !command[0].equalsIgnoreCase("delete")) - { - return DDCommandResult.INVALID_ARGUMENTS; - } - - int removedCount = 0; - boolean deleteFolders = (command.length == 1); - Set linkedDimensions = new HashSet(); - Collection allDims = new ArrayList(); - allDims.addAll(PocketManager.dimList.values()); - - for (NewDimData data : allDims) - { - for (ILinkData link : data.getLinksInDim()) - { - linkedDimensions.add(link.destDimID); - } - } - for (ILinkData link : dimHelper.PocketManager.interDimLinkList.values()) - { - linkedDimensions.add(link.destDimID); - } - for (NewDimData data : allDims) - { - if (!linkedDimensions.contains(data.dimID)) - { - if (PocketManager.instance.pruneDimension(data, deleteFolders)) - { - removedCount++; - } - } - } - PocketManager.instance.save(); - sender.sendChatToPlayer("Removed " + removedCount + " unreachable pocket dims."); - return DDCommandResult.SUCCESS; - } -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java b/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java index 73e808e9..6c2f0caf 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java @@ -10,7 +10,7 @@ public class CommandResetDungeons extends DDCommandBase private CommandResetDungeons() { - super("dd-resetdungeons", ""); + super("dd-rebuilddungeons", ""); } public static CommandResetDungeons instance() @@ -32,12 +32,12 @@ public class CommandResetDungeons extends DDCommandBase int dungeonCount = 0; int resetCount = 0; - for (NewDimData data : PocketManager.dimList.values()) + for (NewDimData data : PocketManager.getDimensions()) { - if (data.isDimRandomRift) + if (data.isDungeon()) { dungeonCount++; - if (PocketManager.instance.resetPocket(data)) + if (PocketManager.resetDungeon(data)) { resetCount++; } @@ -45,7 +45,7 @@ public class CommandResetDungeons extends DDCommandBase } //Notify the user of the results - sender.sendChatToPlayer("Reset complete. " + resetCount + " out of " + dungeonCount + " dungeons were reset."); + sender.sendChatToPlayer("Reset complete. " + resetCount + " out of " + dungeonCount + " dungeons were rebuilt."); return DDCommandResult.SUCCESS; } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java b/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java index 1892b226..c91286ca 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java @@ -6,13 +6,16 @@ import java.util.List; import cpw.mods.fml.common.FMLCommonHandler; import StevenDimDoors.mod_pocketDim.BlankTeleporter; +import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; +import StevenDimDoors.mod_pocketDim.util.Point4D; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.world.World; import net.minecraft.world.WorldServer; +import net.minecraftforge.common.DimensionManager; public class CommandTeleportPlayer extends DDCommandBase @@ -39,7 +42,7 @@ public class CommandTeleportPlayer extends DDCommandBase @Override protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { - List dimensionIDs = Arrays.asList(PocketManager.getStaticDimensionIDs()); //Gets list of all registered dimensions, regardless if loaded or not + List dimensionIDs = Arrays.asList(DimensionManager.getStaticDimensionIDs()); //Gets list of all registered dimensions, regardless if loaded or not EntityPlayer targetPlayer = sender; int dimDestinationID = sender.worldObj.provider.dimensionId; @@ -66,13 +69,10 @@ public class CommandTeleportPlayer extends DDCommandBase { return DDCommandResult.INVALID_DIMENSION_ID; } - if(PocketManager.getWorld(dimDestinationID)==null) - { - PocketManager.initDimension(dimDestinationID); - } - - FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().transferPlayerToDimension((EntityPlayerMP) targetPlayer, dimDestinationID, new BlankTeleporter(PocketManager.getWorld(dimDestinationID))); - targetPlayer.setPositionAndUpdate(Integer.parseInt(command[2]),Integer.parseInt(command[3]),Integer.parseInt(command[4])); + + PocketManager.loadDimension(dimDestinationID); + Point4D destination = new Point4D(Integer.parseInt(command[2]),Integer.parseInt(command[3]),Integer.parseInt(command[4]),dimDestinationID); + DDTeleporter.teleportEntity(targetPlayer, destination, false); } else { diff --git a/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java b/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index 7ae67d46..a2ed39da 100644 --- a/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java +++ b/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -470,13 +470,26 @@ public class DDTeleporter private static boolean initializeDestination(DimLink link, DDProperties properties, Block door) { - // FIXME: Change this later to support rooms that have been wiped and must be regenerated. - // FIXME: Add code for restoring the destination-side door. - // We might need to implement regeneration for REVERSE links as well. - if (link.hasDestination()) { + //Need to check if the destination is a dungeon, not only the link because non-dungeon links could still link to a dungeon at this point. + if(PocketManager.getDimensionData(link.destination().getDimension()).isDungeon) + { + NewDimData dimData = PocketManager.getDimensionData(link.destination().getDimension()); + if(!dimData.isFilled()) + { + if(!PocketBuilder.regenerateDungeonPocket(dimData, link, properties)) + { + //If we fail to regenerate, send the player to the parent dimension. + return generateSafeExit(link, properties); + } + } + + } + return true; + + } // Check the destination type and respond accordingly diff --git a/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 05ab685c..e53058f8 100644 --- a/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -242,14 +242,14 @@ public abstract class NewDimData } public DimLink createLink(int x, int y, int z, int linkType) { - return createLink(new Point4D(x, y, z, id), linkType,-1); + return createLink(new Point4D(x, y, z, id), linkType,0); } public DimLink createLink(int x, int y, int z, int linkType,int orientation) { return createLink(new Point4D(x, y, z, id), linkType,orientation); } - private DimLink createLink(Point4D source, int linkType,int orientation) + public DimLink createLink(Point4D source, int linkType,int orientation) { //Return an existing link if there is one to avoid creating multiple links starting at the same point. InnerDimLink link = linkMapping.get(source); diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 3c992fcb..39061c24 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -186,7 +186,7 @@ public class PocketManager isLoading = false; } - public boolean resetDungeon(NewDimData target) + public static boolean resetDungeon(NewDimData target) { // We can't reset the dimension if it's currently loaded or if it's not a dungeon. // We cast to InnerDimData so that if anyone tries to be a smartass and create their @@ -452,6 +452,11 @@ public class PocketManager return getLink(x, y, z, world.provider.dimensionId); } + public static DimLink getLink(Point4D point) + { + return getLink(point.getX(), point.getY(), point.getZ(), point.getDimension()); + } + public static DimLink getLink(int x, int y, int z, int dimensionID) { NewDimData dimension = dimensionData.get(dimensionID); diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index c8802e65..bb9d173e 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -24,6 +24,13 @@ import StevenDimDoors.mod_pocketDim.blocks.TransTrapdoor; import StevenDimDoors.mod_pocketDim.blocks.TransientDoor; import StevenDimDoors.mod_pocketDim.blocks.UnstableDoor; import StevenDimDoors.mod_pocketDim.blocks.WarpDoor; +import StevenDimDoors.mod_pocketDim.commands.CommandCreateDungeonRift; +import StevenDimDoors.mod_pocketDim.commands.CommandCreatePocket; +import StevenDimDoors.mod_pocketDim.commands.CommandDeleteAllLinks; +import StevenDimDoors.mod_pocketDim.commands.CommandDeleteRifts; +import StevenDimDoors.mod_pocketDim.commands.CommandExportDungeon; +import StevenDimDoors.mod_pocketDim.commands.CommandResetDungeons; +import StevenDimDoors.mod_pocketDim.commands.CommandTeleportPlayer; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.helpers.ChunkLoaderHelper; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; @@ -405,17 +412,17 @@ public class mod_pocketDim { //TODO- load dims with forced chunks on server startup here - /* + CommandResetDungeons.instance().register(event); CommandCreateDungeonRift.instance().register(event); CommandDeleteAllLinks.instance().register(event); - CommandDeleteDimensionData.instance().register(event); + //CommandDeleteDimensionData.instance().register(event); CommandDeleteRifts.instance().register(event); CommandExportDungeon.instance().register(event); - CommandPrintDimensionData.instance().register(event); - CommandPruneDimensions.instance().register(event); + //CommandPrintDimensionData.instance().register(event); + //CommandPruneDimensions.instance().register(event); CommandCreatePocket.instance().register(event); CommandTeleportPlayer.instance().register(event); - */ + } } diff --git a/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java b/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java index 2a4056f1..88b326a1 100644 --- a/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java +++ b/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java @@ -42,6 +42,82 @@ public class PocketBuilder private PocketBuilder() { } + /** + * Method that takes an arbitrary link into a dungeon pocket and tries to regenerate it. First uses the origin to find that link, + * then uses that link to find the link that originally created the dungeon. If it cant find any of these, it + * instead makes the link that lead to this point into an exit door style link, sending the player to the overworld. + * @param dimension The dungeon to be regenerated + * @param linkIn The link leading somewhere into the dungeon. + * @param properties + * @return + */ + public static boolean regenerateDungeonPocket(NewDimData dimension, DimLink linkIn, DDProperties properties) + { + if (linkIn == null) + { + throw new IllegalArgumentException("link cannot be null."); + } + if (properties == null) + { + throw new IllegalArgumentException("properties cannot be null."); + } + //The link that is at the origin of the dungeon + DimLink originLink = dimension.getLink(dimension.origin()); + Point4D oldLinkPos = linkIn.source(); + if(originLink==null) + { + int orientation = linkIn.orientation(); + originLink=dimension.createLink(oldLinkPos, LinkTypes.SAFE_EXIT, (orientation+2)%4); + return false; + } + //The link that originally created the dungeon on the way in + DimLink incomingLink = PocketManager.getLink(originLink.destination()); + if(incomingLink==null||incomingLink.linkType()!=LinkTypes.DUNGEON||!(originLink.linkType()==LinkTypes.REVERSE)) + { + int orientation = linkIn.orientation(); + dimension.deleteLink(originLink); + dimension.createLink(oldLinkPos, LinkTypes.SAFE_EXIT, (orientation+2)%4); + return false; + } + NewDimData parent = PocketManager.getDimensionData(incomingLink.source().getDimension()); + + if (!dimension.isDungeon()) + { + throw new IllegalArgumentException("destination must be dungeon"); + } + if (dimension.isFilled()) + { + throw new IllegalArgumentException("destination must be empty"); + } + if (!dimension.isInitialized()) + { + throw new IllegalArgumentException("destination must already exist"); + } + + try + { + //Load a world + World world = PocketManager.loadDimension(dimension.id()); + + if (world == null || world.provider == null) + { + System.err.println("Could not initialize dimension for a dungeon!"); + return false; + } + + Point3D destination = new Point3D(incomingLink.destination()); + loadAndValidateDungeon(dimension.dungeon(),properties).copyToWorld(world, destination, originLink.orientation(), incomingLink, random); + dimension.setFilled(true); + return true; + } + catch (Exception e) + { + e.printStackTrace(); + return false; + } + + + } public static boolean generateNewDungeonPocket(DimLink link, DDProperties properties) { if (link == null) @@ -52,10 +128,12 @@ public class PocketBuilder { throw new IllegalArgumentException("properties cannot be null."); } + if (link.hasDestination()) { throw new IllegalArgumentException("link cannot have a destination assigned already."); } + try {