From bc2745a59619f6dfd58d2728d085b9a60e7fded7 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 25 Jun 2013 13:55:13 -0400 Subject: [PATCH 1/5] Partial Overhaul of Commands Made progress on overhauling and prettifying our commands. There are still more changes to be done for this to be functional. I need to do an intermediate commit because I want to merge in recent changes by Steven. --- StevenDimDoors/mod_pocketDim/DimData.java | 143 ++++++-------- StevenDimDoors/mod_pocketDim/LinkData.java | 16 +- .../commands/CommandCreateDungeonRift.java | 136 ++++++++------ .../commands/CommandDeleteAllLinks.java | 2 +- .../commands/CommandDeleteDimensionData.java | 2 +- .../commands/CommandDeleteRifts.java | 2 +- .../commands/CommandEndDungeonCreation.java | 175 ++++++++++++++---- .../commands/CommandPrintDimensionData.java | 55 +++--- .../commands/CommandPruneDimensions.java | 2 +- .../commands/CommandRegenPocket.java | 2 +- .../commands/CommandStartDungeonCreation.java | 15 +- .../mod_pocketDim/commands/DDCommandBase.java | 32 +++- .../commands/DDCommandResult.java | 54 ++++++ .../mod_pocketDim/helpers/DungeonHelper.java | 15 +- 14 files changed, 425 insertions(+), 226 deletions(-) create mode 100644 StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java diff --git a/StevenDimDoors/mod_pocketDim/DimData.java b/StevenDimDoors/mod_pocketDim/DimData.java index 8783e83c..2da42b18 100644 --- a/StevenDimDoors/mod_pocketDim/DimData.java +++ b/StevenDimDoors/mod_pocketDim/DimData.java @@ -16,37 +16,37 @@ public class DimData implements Serializable public int dimID; public int depth; public int dimOrientation; - + public World world; - + public LinkData exitDimLink; - + public boolean isPocket; public boolean hasBeenFilled=false; public boolean hasDoor=false; public boolean isDimRandomRift=false; public DungeonGenerator dungeonGenerator = null; //public boolean isPrivatePocket = false; - public HashMap>> linksInThisDim=new HashMap(); + public HashMap>> linksInThisDim = new HashMap(); HashMap dimX; HashMap> dimY ; - + static final long serialVersionUID = 454342L; - + public DimData(int dimID, boolean isPocket, int depth, LinkData exitLinkData) { this.dimID=dimID; this.depth=depth; this.isPocket=isPocket; - + this.exitDimLink= exitLinkData; } - + public DimData(int dimID, boolean isPocket, int depth, int exitLinkDimID, int exitX, int exitY, int exitZ) { this(dimID, isPocket, depth, new LinkData(exitLinkDimID, exitX, exitY, exitZ)); } - + public LinkData findNearestRift(World world, int range, int x, int y, int z) { LinkData nearest=null; @@ -55,7 +55,7 @@ public class DimData implements Serializable int j=-range; int k=-range; DDProperties properties = DDProperties.instance(); - + while (i(); this.dimY=new HashMap>(); } - + this.dimX.put(link.locXCoord, link); this.dimY.put(link.locYCoord, dimX); this.linksInThisDim.put(link.locZCoord, dimY); - + //System.out.println("added link to dim "+this.dimID); return link; - + } - + public LinkData addLinkToDim( int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord, int linkOrientation) { LinkData linkData= new LinkData(this.dimID, destinationDimID, locationXCoord, locationYCoord, locationZCoord, destinationXCoord, destinationYCoord,destinationZCoord,this.isPocket,linkOrientation); - + return this.addLinkToDim(linkData); } - + public boolean isLimbo() { return (this.dimID == DDProperties.instance().LimboDimensionID); } - + public void removeLinkAtCoords(LinkData link) { this.removeLinkAtCoords(link.locDimID, link.locXCoord, link.locYCoord, link.locZCoord); } - + public void removeLinkAtCoords(int locationID, int locationXCoord, int locationYCoord, int locationZCoord) { if (this.linksInThisDim.containsKey(locationZCoord)) { this.dimY=this.linksInThisDim.get(locationZCoord); - + if(this.dimY.containsKey(locationYCoord)) { this.dimX=this.dimY.get(locationYCoord); @@ -199,80 +199,59 @@ public class DimData implements Serializable this.dimX=new HashMap(); this.dimY=new HashMap>(); } - - + this.dimX.remove(locationXCoord); this.dimY.put(locationYCoord, dimX); this.linksInThisDim.put(locationZCoord, dimY); - - - - - - - - - } - + public LinkData findLinkAtCoords(int locationXCoord, int locationYCoord, int locationZCoord) { try { - if(this.linksInThisDim.containsKey(locationZCoord)) - { - this.dimY=this.linksInThisDim.get(locationZCoord); - - if(this.dimY.containsKey(locationYCoord)) + if(this.linksInThisDim.containsKey(locationZCoord)) { - this.dimX=this.dimY.get(locationYCoord); - - if(this.dimX.containsKey(locationXCoord)) + this.dimY=this.linksInThisDim.get(locationZCoord); + + if(this.dimY.containsKey(locationYCoord)) { - return this.dimX.get(locationXCoord); + this.dimX=this.dimY.get(locationYCoord); + + if(this.dimX.containsKey(locationXCoord)) + { + return this.dimX.get(locationXCoord); + } + } - } } - } catch(Exception E) { return null; } - - return null; - + return null; } - - - + public ArrayList printAllLinkData() { - ArrayList links = new ArrayList(); - if(this.linksInThisDim==null) + //TODO: We might want to modify this function, but I'm afraid of breaking something right now. + //To begin with, the name is wrong. This doesn't print anything! >_o ~SenseiKiwi + + ArrayList links = new ArrayList(); + if (this.linksInThisDim == null) { return links; } - for(HashMap> first : this.linksInThisDim.values()) + for (HashMap> first : this.linksInThisDim.values()) { - - - for(HashMap second : first.values()) + for (HashMap second : first.values()) { - - - for(LinkData linkData :second.values()) + for (LinkData linkData : second.values()) { links.add(linkData); } } - } - - - + } return links; } - - - } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/LinkData.java b/StevenDimDoors/mod_pocketDim/LinkData.java index a701ace5..eab4ec67 100644 --- a/StevenDimDoors/mod_pocketDim/LinkData.java +++ b/StevenDimDoors/mod_pocketDim/LinkData.java @@ -15,10 +15,7 @@ public class LinkData implements Serializable public int numberofChildren; public boolean isLocPocket; public int linkOrientation; - - - public int destDimID; public int locDimID; @@ -43,8 +40,7 @@ public class LinkData implements Serializable public LinkData(int locationDimID, int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord, boolean isPocket,int orientation) { - - this.exists=true; + this.exists = true; this.locXCoord=locationXCoord; this.locYCoord=locationYCoord; this.locZCoord=locationZCoord; @@ -57,20 +53,16 @@ public class LinkData implements Serializable this.locDimID=locationDimID; this.isLocPocket=isPocket; this.linkOrientation=orientation; - - - } public String printLinkData() { + //TODO: Rewrite this to make it prettier. @_@ I'm afraid of changing it to ToString() on the off + //chance it'll cause explosions and sadness. Damn serialization! ~SenseiKiwi String linkInfo; - linkInfo=String.valueOf(this.locDimID)+"locDimID "+String.valueOf(this.locXCoord)+":locXCoord "+String.valueOf(this.locYCoord)+":locYCoord "+String.valueOf(this.locZCoord)+":locZCoord "; + linkInfo = String.valueOf(this.locDimID) + "locDimID "+String.valueOf(this.locXCoord)+":locXCoord "+String.valueOf(this.locYCoord)+":locYCoord "+String.valueOf(this.locZCoord)+":locZCoord "; linkInfo.concat("\n"+ String.valueOf(this.destDimID)+"DestDimID "+String.valueOf(this.destXCoord)+":destXCoord "+String.valueOf(this.destYCoord)+":destYCoord "+String.valueOf(this.destZCoord)+":destZCoord "); return linkInfo; - - - } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java b/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java index 0f36f834..84f2c06a 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java @@ -1,9 +1,9 @@ package StevenDimDoors.mod_pocketDim.commands; +import java.io.File; import java.util.Collection; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.MathHelper; import StevenDimDoors.mod_pocketDim.DungeonGenerator; import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; @@ -15,7 +15,7 @@ public class CommandCreateDungeonRift extends DDCommandBase private CommandCreateDungeonRift() { - super("dd-rift"); + super("dd-rift", ""); } public static CommandCreateDungeonRift instance() @@ -27,71 +27,101 @@ public class CommandCreateDungeonRift extends DDCommandBase } @Override - public void processCommand(EntityPlayer sender, String[] command) + protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { DungeonHelper dungeonHelper = DungeonHelper.instance(); - if(command==null||sender.worldObj.isRemote) + if (sender.worldObj.isRemote) { - return; + return DDCommandResult.SUCCESS; + } + if (command.length == 0) + { + return DDCommandResult.TOO_FEW_ARGUMENTS; + } + if (command.length > 1) + { + return DDCommandResult.TOO_MANY_ARGUMENTS; } - LinkData link = new LinkData(sender.worldObj.provider.dimensionId, 0, - (int) sender.posX, - (int) sender.posY + 1, - (int) sender.posZ, - (int) sender.posX, - (int) sender.posY + 1, - (int) sender.posZ,true,3); - - if(command.length!=0&&command[0].equals("random")) - { - sender.sendChatToPlayer("Created dungeon rift"); - dimHelper.instance.createLink(link); - link = dimHelper.instance.createPocket(link,true, true); - } - else if (command.length != 0 && command[0].equals("list")) + if (command[0].equals("list")) { Collection dungeonNames = dungeonHelper.getDungeonNames(); for (String name : dungeonNames) { - getCommandSenderAsPlayer(sender).sendChatToPlayer(name); - } - } - else if(command.length!=0) - { - for(DungeonGenerator dungeonGen : dungeonHelper.registeredDungeons) - { - String dungeonName =dungeonGen.schematicPath.toLowerCase(); - - if(dungeonName.contains(command[0].toLowerCase())) - { - link = dimHelper.instance.createPocket(link,true, true); - dimHelper.dimList.get(link.destDimID).dungeonGenerator=dungeonGen; - sender.sendChatToPlayer("Genned dungeon " +dungeonName); - return; - } - } - for(DungeonGenerator dungeonGen : dungeonHelper.customDungeons) - { - String dungeonName =dungeonGen.schematicPath.toLowerCase(); - - if(dungeonName.contains(command[0].toLowerCase())) - { - link = dimHelper.instance.createPocket(link,true, true); - dimHelper.dimList.get(link.destDimID).dungeonGenerator=dungeonGen; - sender.sendChatToPlayer("Genned dungeon " +dungeonName); - return; - } - } - if(command!=null&&!command[0].equals("random")) - { - sender.sendChatToPlayer("could not find dungeon, 'list' for list of dungeons"); + sender.sendChatToPlayer(name); } + sender.sendChatToPlayer(""); } else { - sender.sendChatToPlayer("invalid arguments- 'random' for random dungeon, or 'list' for dungeon names"); + DungeonGenerator result; + int x = (int) sender.posX; + int y = (int) sender.posY; + int z = (int) sender.posZ; + LinkData link = new LinkData(sender.worldObj.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3); + + if (command[0].equals("random")) + { + dimHelper.instance.createLink(link); + link = dimHelper.instance.createPocket(link, true, true); + sender.sendChatToPlayer("Created a rift to a random dungeon (Dimension ID = " + link.destDimID + ")."); + } + else + { + result = findDungeonByPartialName(command[0], dungeonHelper.registeredDungeons); + if (result == null) + { + result = findDungeonByPartialName(command[0], dungeonHelper.customDungeons); + } + //Check if we found any matches + if (result != null) + { + //Create a rift to our selected dungeon and notify the player + link = dimHelper.instance.createPocket(link, true, true); + dimHelper.dimList.get(link.destDimID).dungeonGenerator = result; + sender.sendChatToPlayer("Created a rift to \"" + getSchematicName(result) + "\" dungeon (Dimension ID = " + link.destDimID + ")."); + } + else + { + //No matches! + return new DDCommandResult("Error: The specified dungeon was not found. Use 'list' to see a list of the available dungeons."); + } + } } + return DDCommandResult.SUCCESS; + } + + private DungeonGenerator findDungeonByPartialName(String query, Collection dungeons) + { + //Search for the shortest dungeon name that contains the lowercase query string. + String dungeonName; + String normalQuery = query.toLowerCase(); + DungeonGenerator bestMatch = null; + int matchLength = Integer.MAX_VALUE; + + for (DungeonGenerator dungeon : dungeons) + { + //We need to extract the file's name. Comparing against schematicPath could + //yield false matches if the query string is contained within the path. + + dungeonName = getSchematicName(dungeon).toLowerCase(); + if (dungeonName.length() < matchLength && dungeonName.contains(normalQuery)) + { + matchLength = dungeonName.length(); + bestMatch = dungeon; + } + } + return bestMatch; + } + + private static String getSchematicName(DungeonGenerator dungeon) + { + //TODO: Move this to DungeonHelper and use it for all schematic name parsing. + //In the future, we really should include the schematic's name as part of DungeonGenerator + //to avoid redoing this work constantly. + File schematic = new File(dungeon.schematicPath); + String fileName = schematic.getName(); + return fileName.substring(0, fileName.length() - DungeonHelper.SCHEMATIC_FILE_EXTENSION.length()); } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java index 6f377904..0d27e8e8 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java @@ -26,7 +26,7 @@ public class CommandDeleteAllLinks extends DDCommandBase } @Override - protected void processCommand(EntityPlayer sender, String[] command) + protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { int linksRemoved=0; int targetDim; diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java index f80ad1aa..7ba8f09c 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java @@ -26,7 +26,7 @@ public class CommandDeleteDimensionData extends DDCommandBase } @Override - protected void processCommand(EntityPlayer sender, String[] command) + protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { int linksRemoved=0; int targetDim; diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java index 6bd020d8..7537371a 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java @@ -27,7 +27,7 @@ public class CommandDeleteRifts extends DDCommandBase } @Override - protected void processCommand(EntityPlayer sender, String[] command) + protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { int linksRemoved=0; int targetDim; diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java b/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java index 6f49de7b..a89abf1f 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java @@ -12,7 +12,9 @@ public class CommandEndDungeonCreation extends DDCommandBase private CommandEndDungeonCreation() { - super("dd-export"); + super("dd-export", new String[] { + " <'open' | 'closed'> [weight] ['override']", + " override" } ); } public static CommandEndDungeonCreation instance() @@ -24,57 +26,160 @@ public class CommandEndDungeonCreation extends DDCommandBase } @Override - protected void processCommand(EntityPlayer sender, String[] command) + protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { + /* + * There are two versions of this command. One version takes 3 to 5 arguments consisting + * of the information needed for a proper schematic name and an optional override argument. + * The override argument only allows the user to export any dimension, even if it wasn't + * meant for custom dungeon creation. It does not allow the user to export a dungeon with + * invalid tags. + * + * If the user wishes to name his schematic in a different format, then he will have to use + * the 2-argument version of this command, which accepts a schematic name and a mandatory + * override argument. + */ + DungeonHelper dungeonHelper = DungeonHelper.instance(); - DDProperties properties = DDProperties.instance(); - if (!dungeonHelper.isCustomDungeon(sender.worldObj.provider.dimensionId)) + if (command.length < 2) { - if (command.length < 2) - { - sender.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway"); - return; - - } - - else if (!command[1].contains("OVERRIDE")) - { - sender.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway"); - return; - - } - + return DDCommandResult.TOO_FEW_ARGUMENTS; + } + if (command.length > 5) + { + return DDCommandResult.TOO_MANY_ARGUMENTS; } - int x = (int) sender.posX; - int y = (int) sender.posY; - int z = (int) sender.posZ; - - if (command.length == 0) + //Check if we received the 2-argument version + if (command.length == 2) { - sender.sendChatToPlayer("Must name file"); - } - else if(!sender.worldObj.isRemote) - { - //Check that the dungeon name is valid to prevent directory traversal and other forms of abuse - if (DungeonHelper.NamePattern.matcher(command[0]).matches()) + if (command[1].equalsIgnoreCase("override")) { - String exportPath = properties.CustomSchematicDirectory + "/" + command[0] + ".schematic"; - if (dungeonHelper.exportDungeon(sender.worldObj, x, y, z, exportPath)) + //Check that the schematic name is a legal name + if (DungeonHelper.SchematicNamePattern.matcher(command[0]).matches()) { - sender.sendChatToPlayer("Saved dungeon schematic in " + exportPath); - dungeonHelper.registerCustomDungeon(new File(exportPath)); + //Export the schematic + return exportDungeon(sender, command[0]); } else { - sender.sendChatToPlayer("Failed to save dungeon schematic!"); + //The schematic name contains illegal characters. Inform the user. + return new DDCommandResult("Error: Invalid schematic name. Please use only letters, numbers, dashes, and underscores."); } } else { - sender.sendChatToPlayer("Invalid schematic name. Please use only letters, numbers, and underscores."); + //The command is malformed in some way. Assume that the user meant to use + //the 3-argument version and report an error. + return DDCommandResult.TOO_FEW_ARGUMENTS; } } + + //The user must have used the 3-argument version of this command + //Check if the current dimension is a pocket for building custom dungeons or if the override argument was used. + if (!dungeonHelper.isCustomDungeon(sender.worldObj.provider.dimensionId) || + !command[command.length - 1].equalsIgnoreCase("override")) + { + //This dimension may not be exported without overriding! + return new DDCommandResult("Error: The current dimension was not made for dungeon creation. Use the 'override' argument to export anyway."); + } + + //TODO: Why do we check remoteness here but not before? And why not for the other export case? + //Something feels wrong... ~SenseiKiwi + + if (!sender.worldObj.isRemote) + { + //TODO: This validation should be in DungeonHelper or in another class. We should move it + //once the during the save file format rewrite. ~SenseiKiwi + + if (!dungeonHelper.validateDungeonType(command[0])) + { + return new DDCommandResult("Error: Invalid dungeon type. Please use one of the existing types."); + } + if (!DungeonHelper.DungeonNamePattern.matcher(command[1]).matches()) + { + return new DDCommandResult("Error: Invalid dungeon name. Please use only letters, numbers, and dashes."); + } + if (!command[2].equalsIgnoreCase("open") && !command[2].equalsIgnoreCase("closed")) + { + return new DDCommandResult("Error: Please specify whether the dungeon is 'open' or 'closed'."); + } + + //If there are no more argument, export the dungeon. + if (command.length == 3) + { + return exportDungeon(sender, join(command, "_", 0, 3)); + } + + //Validate the 4th argument, which might be the weight or might be "override". + try + { + int weight = Integer.parseInt(command[3]); + if (weight >= 0 && weight <= DungeonHelper.MAX_DUNGEON_WEIGHT) + { + return exportDungeon(sender, join(command, "_", 0, 4)); + } + } + catch (Exception e) + { + //The 4th argument could be "override", but only if it's the last argument. + //In that case, we assume the default dungeon weight. + if (command.length == 4 && command[3].equalsIgnoreCase("override")) + { + return exportDungeon(sender, join(command, "_", 0, 3)); + } + } + + //If we've reached this point, then we must have an invalid weight. + return new DDCommandResult("Invalid dungeon weight. Please specify a weight between 0 and " + DungeonHelper.MAX_DUNGEON_WEIGHT + ", inclusive."); + } + + return DDCommandResult.SUCCESS; + } + + private static DDCommandResult exportDungeon(EntityPlayer player, String name) + { + DDProperties properties = DDProperties.instance(); + DungeonHelper dungeonHelper = DungeonHelper.instance(); + + int x = (int) player.posX; + int y = (int) player.posY; + int z = (int) player.posZ; + String exportPath = properties.CustomSchematicDirectory + File.separator + name + ".schematic"; + if (dungeonHelper.exportDungeon(player.worldObj, x, y, z, exportPath)) + { + player.sendChatToPlayer("Saved dungeon schematic in " + exportPath); + dungeonHelper.registerCustomDungeon(new File(exportPath)); + return DDCommandResult.SUCCESS; + } + else + { + return new DDCommandResult("Error: Failed to save dungeon schematic!"); + } + } + + private static String join(String[] source, String delimiter, int start, int end) + { + //TODO: This function should be moved to a helper, but we have several single-function helpers as is. + //I find that to be worse than keeping this private. ~SenseiKiwi + + int index; + int length = 0; + StringBuilder buffer; + for (index = start; index < end; index++) + { + length += source[index].length(); + } + length += (end - start - 1) * delimiter.length(); + + buffer = new StringBuilder(length); + buffer.append(source[start]); + for (index = start + 1; index < end; index++) + { + buffer.append(delimiter); + buffer.append(source[index]); + } + return buffer.toString(); } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java b/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java index ca235d2b..7a8c5c0c 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java @@ -1,7 +1,6 @@ package StevenDimDoors.mod_pocketDim.commands; import java.util.ArrayList; -import java.util.Collection; import net.minecraft.entity.player.EntityPlayer; import StevenDimDoors.mod_pocketDim.DimData; @@ -14,7 +13,7 @@ public class CommandPrintDimensionData extends DDCommandBase private CommandPrintDimensionData() { - super("dd-dimensiondata"); + super("dd-dimensiondata", "[dimension number]"); } public static CommandPrintDimensionData instance() @@ -26,45 +25,45 @@ public class CommandPrintDimensionData extends DDCommandBase } @Override - protected void processCommand(EntityPlayer sender, String[] command) + protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { int targetDim; - boolean shouldGo= true; + DimData dimData; - if(command.length==0) + if (command.length == 0) { - targetDim= sender.worldObj.provider.dimensionId; + targetDim = sender.worldObj.provider.dimensionId; } - else if(command.length==1) + else if (command.length == 1) { - targetDim = parseInt(sender, command[0]); - if(!dimHelper.dimList.containsKey(targetDim)) + try { - sender.sendChatToPlayer("Error- dim "+targetDim+" not registered"); - shouldGo=false; + targetDim = Integer.parseInt(command[0]); + } + catch (Exception ex) + { + return DDCommandResult.INVALID_DIMENSION_ID; } } else { - targetDim=0; - shouldGo=false; - sender.sendChatToPlayer("Error-Invalid argument, print_dim_data or blank for current dim"); + return DDCommandResult.TOO_MANY_ARGUMENTS; + } + + dimData = dimHelper.dimList.get(targetDim); + if (dimData == null) + { + return DDCommandResult.UNREGISTERED_DIMENSION; } - if(shouldGo) - { - if(dimHelper.dimList.containsKey(targetDim)) - { - DimData dimData = dimHelper.dimList.get(targetDim); - Collection links = new ArrayList(); - links.addAll( dimData.printAllLinkData()); + ArrayList links = dimData.printAllLinkData(); - for (LinkData link : links) - { - sender.sendChatToPlayer(link.printLinkData()); - } - sender.sendChatToPlayer("DimID= "+dimData.dimID+"Dim depth = "+dimData.depth); - } - } + sender.sendChatToPlayer("Dimension ID = " + dimData.dimID); + sender.sendChatToPlayer("Dimension Depth = " + dimData.depth); + for (LinkData 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 index 32e1dce0..d58f0b4d 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java @@ -26,7 +26,7 @@ public class CommandPruneDimensions extends DDCommandBase } @Override - protected void processCommand(EntityPlayer sender, String[] command) + protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { int numRemoved=0; ArrayList dimsWithLinks = new ArrayList(); diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandRegenPocket.java b/StevenDimDoors/mod_pocketDim/commands/CommandRegenPocket.java index fa63a667..b4d1feb4 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandRegenPocket.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandRegenPocket.java @@ -26,7 +26,7 @@ public class CommandRegenPocket extends DDCommandBase } @Override - protected void processCommand(EntityPlayer sender, String[] command) + protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { DungeonHelper dungeonHelper = DungeonHelper.instance(); DDProperties properties = DDProperties.instance(); diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandStartDungeonCreation.java b/StevenDimDoors/mod_pocketDim/commands/CommandStartDungeonCreation.java index 4a645fd5..39fbccfa 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandStartDungeonCreation.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandStartDungeonCreation.java @@ -10,7 +10,7 @@ public class CommandStartDungeonCreation extends DDCommandBase private CommandStartDungeonCreation() { - super("dd-create"); + super("dd-create", ""); } public static CommandStartDungeonCreation instance() @@ -22,10 +22,18 @@ public class CommandStartDungeonCreation extends DDCommandBase } @Override - protected void processCommand(EntityPlayer sender, String[] command) + protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { + //TODO: Some commands have isRemote checks, some do not. Why? Can commands even run locally anyway? + //What does it mean when you run a command locally? ~SenseiKiwi + if (!sender.worldObj.isRemote) { + if (command.length > 0) + { + return DDCommandResult.TOO_MANY_ARGUMENTS; + } + //Place a door leading to a pocket dimension where the player is standing. //The pocket dimension will be serve as a room for the player to build a dungeon. int x = (int) sender.posX; @@ -34,7 +42,8 @@ public class CommandStartDungeonCreation extends DDCommandBase LinkData link = DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z); //Notify the player - sender.sendChatToPlayer("Created a door to a pocket dimension (ID = " + link.destDimID + "). Please build your dungeon there."); + sender.sendChatToPlayer("Created a door to a pocket dimension (Dimension ID = " + link.destDimID + "). Please build your dungeon there."); } + return DDCommandResult.SUCCESS; } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/commands/DDCommandBase.java b/StevenDimDoors/mod_pocketDim/commands/DDCommandBase.java index 2197f5db..9a7c5343 100644 --- a/StevenDimDoors/mod_pocketDim/commands/DDCommandBase.java +++ b/StevenDimDoors/mod_pocketDim/commands/DDCommandBase.java @@ -12,16 +12,25 @@ import cpw.mods.fml.common.event.FMLServerStartingEvent; public abstract class DDCommandBase extends CommandBase { private String name; + private String[] formats; - public DDCommandBase(String name) + public DDCommandBase(String name, String format) { this.name = name; + this.formats = new String[] { format }; } + public DDCommandBase(String name, String[] formats) + { + this.name = name; + this.formats = formats; + } + /* - * When overridden in a derived class, processes the command sent by the server. + * When overridden in a derived class, processes the command sent by the server + * and returns a status code and message for the result of the operation. */ - protected abstract void processCommand(EntityPlayer sender, String[] command); + protected abstract DDCommandResult processCommand(EntityPlayer sender, String[] command); public final String getCommandName() { @@ -43,6 +52,21 @@ public abstract class DDCommandBase extends CommandBase public final void processCommand(ICommandSender sender, String[] command) { //Forward the command - processCommand(getCommandSenderAsPlayer(sender), command); + EntityPlayer player = getCommandSenderAsPlayer(sender); + DDCommandResult result = processCommand(player, command); + + //If the command failed, send the player a status message. + if (result.failed()) + { + if (result.shouldPrintUsage()) + { + //Send the argument formats for this command + for (String format : formats) + { + player.sendChatToPlayer("Usage: " + name + " " + format); + } + } + player.sendChatToPlayer(result.getMessage()); + } } } diff --git a/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java b/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java new file mode 100644 index 00000000..c40a99e0 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java @@ -0,0 +1,54 @@ +package StevenDimDoors.mod_pocketDim.commands; + +public class DDCommandResult { + + + public static final DDCommandResult SUCCESS = new DDCommandResult(0, "", false); + public static final DDCommandResult TOO_FEW_ARGUMENTS = new DDCommandResult(1, "Error: Too few arguments passed to the command", true); + public static final DDCommandResult TOO_MANY_ARGUMENTS = new DDCommandResult(2, "Error: Too many arguments passed to the command", true); + public static final DDCommandResult INVALID_DIMENSION_ID = new DDCommandResult(3, "Error: Invalid dimension ID", true); + public static final DDCommandResult UNREGISTERED_DIMENSION = new DDCommandResult(4, "Error: Dimension is not registered", false); + + public static final int CUSTOM_ERROR_CODE = -1; + + private int code; + private String message; + private boolean printUsage; + + private DDCommandResult(int code, String message, boolean printUsage) + { + this.code = code; + this.message = message; + this.printUsage = printUsage; + } + + public DDCommandResult(String message) + { + this(CUSTOM_ERROR_CODE, message, false); + } + + public DDCommandResult(String message, boolean printUsage) + { + this(CUSTOM_ERROR_CODE, message, printUsage); + } + + public boolean failed() + { + return (code != 0); + } + + public int getCode() + { + return code; + } + + public String getMessage() + { + return message; + } + + public boolean shouldPrintUsage() + { + return printUsage; + } +} diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index a996a3b7..fd2f2ea0 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -31,11 +31,12 @@ public class DungeonHelper { private static DungeonHelper instance = null; private static DDProperties properties = null; - public static final Pattern NamePattern = Pattern.compile("[A-Za-z0-9_\\-]+"); + 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 SCHEMATIC_FILE_EXTENSION = ".schematic"; + public static final String SCHEMATIC_FILE_EXTENSION = ".schematic"; private static final int DEFAULT_DUNGEON_WEIGHT = 100; - private static final int MAX_DUNGEON_WEIGHT = 10000; //Used to prevent overflows and math breaking down + public static final int MAX_DUNGEON_WEIGHT = 10000; //Used to prevent overflows and math breaking down private static final String HUB_DUNGEON_TYPE = "Hub"; private static final String TRAP_DUNGEON_TYPE = "Trap"; @@ -166,6 +167,12 @@ public class DungeonHelper return customDungeonStatus.containsKey(dimensionID); } + public boolean validateDungeonType(String type) + { + //Check if the dungeon type is valid + return dungeonTypeChecker.contains(type.toLowerCase()); + } + public boolean validateSchematicName(String name) { String[] dungeonData; @@ -184,7 +191,7 @@ public class DungeonHelper return false; //Check if the name is valid - if (!NamePattern.matcher(dungeonData[1]).matches()) + if (!SchematicNamePattern.matcher(dungeonData[1]).matches()) return false; //Check if the open/closed flag is present From d15f372c598846fabe4c3e090d0a119fc845d4a3 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 25 Jun 2013 14:28:11 -0400 Subject: [PATCH 2/5] Improved and Renamed CommandRegenPocket Renamed CommandRegenPocket to CommandResetDungeons. Changed command name accordingly. Added a message for the user listing the number of dungeons that were reset. Modified DimHelper slightly to add support for this. Added error condition if user specifies arguments for the command. --- .../commands/CommandRegenPocket.java | 43 ---------------- .../commands/CommandResetDungeons.java | 51 +++++++++++++++++++ .../mod_pocketDim/helpers/dimHelper.java | 33 ++++++------ .../mod_pocketDim/mod_pocketDim.java | 2 +- 4 files changed, 68 insertions(+), 61 deletions(-) delete mode 100644 StevenDimDoors/mod_pocketDim/commands/CommandRegenPocket.java create mode 100644 StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandRegenPocket.java b/StevenDimDoors/mod_pocketDim/commands/CommandRegenPocket.java deleted file mode 100644 index b4d1feb4..00000000 --- a/StevenDimDoors/mod_pocketDim/commands/CommandRegenPocket.java +++ /dev/null @@ -1,43 +0,0 @@ -package StevenDimDoors.mod_pocketDim.commands; - -import java.io.File; - -import net.minecraft.entity.player.EntityPlayer; -import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; - -public class CommandRegenPocket extends DDCommandBase -{ - private static CommandRegenPocket instance = null; - - private CommandRegenPocket() - { - super("dd-regenDungeons"); - } - - public static CommandRegenPocket instance() - { - if (instance == null) - instance = new CommandRegenPocket(); - - return instance; - } - - @Override - protected DDCommandResult processCommand(EntityPlayer sender, String[] command) - { - DungeonHelper dungeonHelper = DungeonHelper.instance(); - DDProperties properties = DDProperties.instance(); - - for(DimData data : dimHelper.dimList.values()) - { - if(data.isDimRandomRift) - { - dimHelper.instance.regenPocket(data); - } - } - - } -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java b/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java new file mode 100644 index 00000000..11c875a6 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java @@ -0,0 +1,51 @@ +package StevenDimDoors.mod_pocketDim.commands; + +import net.minecraft.entity.player.EntityPlayer; +import StevenDimDoors.mod_pocketDim.DimData; +import StevenDimDoors.mod_pocketDim.helpers.dimHelper; + +public class CommandResetDungeons extends DDCommandBase +{ + private static CommandResetDungeons instance = null; + + private CommandResetDungeons() + { + super("dd-resetdungeons", ""); + } + + public static CommandResetDungeons instance() + { + if (instance == null) + instance = new CommandResetDungeons(); + + return instance; + } + + @Override + protected DDCommandResult processCommand(EntityPlayer sender, String[] command) + { + if (command.length > 0) + { + return DDCommandResult.TOO_FEW_ARGUMENTS; + } + + int dungeonCount = 0; + int resetCount = 0; + + for (DimData data : dimHelper.dimList.values()) + { + if (data.isDimRandomRift) + { + dungeonCount++; + if (dimHelper.instance.resetPocket(data)) + { + resetCount++; + } + } + } + + //Notify the user of the results + sender.sendChatToPlayer("Reset complete. " + resetCount + " out of " + dungeonCount + " dungeons were reset."); + return DDCommandResult.SUCCESS; + } +} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java b/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java index 45de6346..bf30fa19 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java @@ -38,6 +38,7 @@ import StevenDimDoors.mod_pocketDim.DimData; import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.ObjectSaveInputStream; import StevenDimDoors.mod_pocketDim.PacketHandler; +import StevenDimDoors.mod_pocketDim.Point3D; import StevenDimDoors.mod_pocketDim.TileEntityRift; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.world.LimboProvider; @@ -64,7 +65,7 @@ public class dimHelper extends DimensionManager * ArrayList containing any blocks in limbo that have been placed by the player. Cycled through in the common tick manager * @Return */ - public static ArrayList blocksToDecay= new ArrayList(); + public static ArrayList blocksToDecay = new ArrayList(); /** * instance of the dimHelper @@ -812,33 +813,31 @@ public class dimHelper extends DimensionManager } } - public void regenPocket(DimData dimData) + public boolean resetPocket(DimData dimData) { - if(this.getWorld(dimData.dimID)!=null ||!dimData.isPocket) + //TODO: Should we add a check to see if the dimension is currently loaded? How could we check that? ~SenseiKiwi + if (getWorld(dimData.dimID) != null || !dimData.isPocket) { - return; + return false; } - File save = new File( this.getCurrentSaveRootDirectory()+"/DimensionalDoors/pocketDimID" + dimData.dimID); + File save = new File(getCurrentSaveRootDirectory() + "/DimensionalDoors/pocketDimID" + dimData.dimID); DeleteFolder.deleteFolder(save); - dimData.hasBeenFilled=false; - dimData.hasDoor=false; + dimData.hasBeenFilled = false; + dimData.hasDoor = false; for(LinkData link : dimData.printAllLinkData()) { - link.hasGennedDoor=false; - LinkData linkOut =this.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID); - if(linkOut!=null) + link.hasGennedDoor = false; + LinkData linkOut = this.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID); + if (linkOut != null) { - linkOut.hasGennedDoor=false; - + linkOut.hasGennedDoor = false; } } - - - - + return true; } + /** - * method called when the client disconects/server stops to unregister dims. + * method called when the client disconnects/server stops to unregister dims. * @Return */ public void unregsisterDims() diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index bd9ab9e9..b2499f47 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -29,7 +29,7 @@ import StevenDimDoors.mod_pocketDim.commands.CommandDeleteRifts; import StevenDimDoors.mod_pocketDim.commands.CommandEndDungeonCreation; import StevenDimDoors.mod_pocketDim.commands.CommandPrintDimensionData; import StevenDimDoors.mod_pocketDim.commands.CommandPruneDimensions; -import StevenDimDoors.mod_pocketDim.commands.CommandRegenPocket; +import StevenDimDoors.mod_pocketDim.commands.CommandResetDungeons; import StevenDimDoors.mod_pocketDim.commands.CommandStartDungeonCreation; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; From ad0e2cbe61b03b7ffc500cac2541920f1760ce2c Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 25 Jun 2013 20:54:58 -0400 Subject: [PATCH 3/5] Improved CommandPruneDimensions Improved CommandPruneDimensions. Cleaned up the code and improved performance by using a HashSet instead of an ArrayList to list dimension reachability. Added an optional argument that sets whether we should delete the folders of pruned dimensions. --- .../commands/CommandPruneDimensions.java | 56 +++++++++++-------- .../commands/DDCommandResult.java | 1 + .../mod_pocketDim/helpers/dimHelper.java | 19 ++++++- 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java b/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java index d58f0b4d..b130dbf7 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java @@ -2,6 +2,8 @@ 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.DimData; @@ -14,7 +16,7 @@ public class CommandPruneDimensions extends DDCommandBase private CommandPruneDimensions() { - super("dd-prune"); + super("dd-prune", "['delete']"); } public static CommandPruneDimensions instance() @@ -28,36 +30,44 @@ public class CommandPruneDimensions extends DDCommandBase @Override protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { - int numRemoved=0; - ArrayList dimsWithLinks = new ArrayList(); + 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(dimHelper.dimList.values()); - for(DimData data: allDims) + + for (DimData data : allDims) { - for(LinkData link:data.printAllLinkData()) + for (LinkData link : data.printAllLinkData()) { - if(!dimsWithLinks.contains(link.destDimID)) + linkedDimensions.add(link.destDimID); + } + } + for (LinkData link : dimHelper.instance.interDimLinkList.values()) + { + linkedDimensions.add(link.destDimID); + } + for (DimData data : allDims) + { + if (!linkedDimensions.contains(data.dimID)) + { + if (dimHelper.instance.pruneDimension(data, deleteFolders)) { - dimsWithLinks.add(link.destDimID); + removedCount++; } } } - for(LinkData link : dimHelper.instance.interDimLinkList.values()) - { - if(!dimsWithLinks.contains(link.destDimID)) - { - dimsWithLinks.add(link.destDimID); - } - } - for(DimData data : allDims) - { - if(!dimsWithLinks.contains(data.dimID)) - { - dimHelper.dimList.remove(data.dimID); - numRemoved++; - } - } dimHelper.instance.save(); - sender.sendChatToPlayer("Removed " + numRemoved + " unreachable pocket dims."); + sender.sendChatToPlayer("Removed " + removedCount + " unreachable pocket dims."); + return DDCommandResult.SUCCESS; } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java b/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java index c40a99e0..9ec0cf73 100644 --- a/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java +++ b/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java @@ -8,6 +8,7 @@ public class DDCommandResult { public static final DDCommandResult TOO_MANY_ARGUMENTS = new DDCommandResult(2, "Error: Too many arguments passed to the command", true); public static final DDCommandResult INVALID_DIMENSION_ID = new DDCommandResult(3, "Error: Invalid dimension ID", true); public static final DDCommandResult UNREGISTERED_DIMENSION = new DDCommandResult(4, "Error: Dimension is not registered", false); + public static final DDCommandResult INVALID_ARGUMENTS = new DDCommandResult(5, "Error: Invalid arguments passed to the command.", true); public static final int CUSTOM_ERROR_CODE = -1; diff --git a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java b/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java index bf30fa19..e5e357af 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java @@ -816,7 +816,7 @@ public class dimHelper extends DimensionManager public boolean resetPocket(DimData dimData) { //TODO: Should we add a check to see if the dimension is currently loaded? How could we check that? ~SenseiKiwi - if (getWorld(dimData.dimID) != null || !dimData.isPocket) + if (!dimData.isPocket || getWorld(dimData.dimID) != null) { return false; } @@ -836,6 +836,23 @@ public class dimHelper extends DimensionManager return true; } + public boolean pruneDimension(DimData dimData, boolean deleteFolder) + { + //TODO: Should we add a check to see if the dimension is currently loaded? How could we check that? ~SenseiKiwi + //TODO: All the logic for checking that this is an isolated pocket should be moved in here. + if (!dimData.isPocket || getWorld(dimData.dimID) != null) + { + return false; + } + dimList.remove(dimData.dimID); + if (deleteFolder) + { + File save = new File(getCurrentSaveRootDirectory() + "/DimensionalDoors/pocketDimID" + dimData.dimID); + DeleteFolder.deleteFolder(save); + } + return true; + } + /** * method called when the client disconnects/server stops to unregister dims. * @Return From 6e3c93fa17e3a6ede800a54ec7a564ce37ad4f21 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 25 Jun 2013 23:24:21 -0400 Subject: [PATCH 4/5] Temporary Fix to Commands Temporarily patched up CommandDeleteAllLinks, CommandDeleteDimensionData, and CommandDeleteRifts so they'll compile. I'll be fixing some things for Steven and I'll come back to those classes to finish overhauling them. --- .../mod_pocketDim/commands/CommandDeleteAllLinks.java | 3 ++- .../mod_pocketDim/commands/CommandDeleteDimensionData.java | 3 ++- StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java index 0d27e8e8..191424e5 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java @@ -14,7 +14,7 @@ public class CommandDeleteAllLinks extends DDCommandBase private CommandDeleteAllLinks() { - super("dd-deletelinks"); + super("dd-deletelinks", "FIXME"); } public static CommandDeleteAllLinks instance() @@ -80,5 +80,6 @@ public class CommandDeleteAllLinks extends DDCommandBase sender.sendChatToPlayer("Removed " + linksRemoved + " links."); } } + return DDCommandResult.SUCCESS; //TEMPORARY HACK } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java index 7ba8f09c..388e3dbf 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java @@ -14,7 +14,7 @@ public class CommandDeleteDimensionData extends DDCommandBase private CommandDeleteDimensionData() { - super("dd-deletedimension"); + super("dd-deletedimension", "FIXME"); } public static CommandDeleteDimensionData instance() @@ -90,5 +90,6 @@ public class CommandDeleteDimensionData extends DDCommandBase 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 7537371a..d109d82c 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java @@ -15,7 +15,7 @@ public class CommandDeleteRifts extends DDCommandBase private CommandDeleteRifts() { - super("dd-???"); + super("dd-???", "FIXME"); } public static CommandDeleteRifts instance() @@ -84,5 +84,6 @@ public class CommandDeleteRifts extends DDCommandBase sender.sendChatToPlayer("Removed "+linksRemoved+" rifts."); } } + return DDCommandResult.SUCCESS; //TEMPORARY HACK } } \ No newline at end of file From 471114415bd153e2d95548bb5143f094d4f67904 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 26 Jun 2013 00:45:20 -0400 Subject: [PATCH 5/5] Fixed Rotation in SchematicLoader Fixed reference to CommandRegenPocket - should be CommandResetDungeons. Autofixed indentation in SchematicLoader. I wanted to commit that change before doing any more code changes but I forgot. Then I fixed the code that calculates the coordinate offsets so our dungeons rotate right. It was pretty simple - all I had to do was move the xCooe and zCooe calculations into the loops so they're recalculated to account for rotation. I rearranged the loops for optimal performance. --- .../mod_pocketDim/SchematicLoader.java | 206 +++++++++--------- .../mod_pocketDim/mod_pocketDim.java | 2 +- 2 files changed, 102 insertions(+), 106 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/SchematicLoader.java b/StevenDimDoors/mod_pocketDim/SchematicLoader.java index 2c4f8de5..3ebe87d9 100644 --- a/StevenDimDoors/mod_pocketDim/SchematicLoader.java +++ b/StevenDimDoors/mod_pocketDim/SchematicLoader.java @@ -37,15 +37,15 @@ public class SchematicLoader private Random rand = new Random(); public HashMap>> rotationMap = new HashMap>>(); public int transMeta; - - - - + + + + private DDProperties properties = DDProperties.instance(); - + public SchematicLoader() { } public int transformMetadata(int metadata, int orientation, int blockID) @@ -733,17 +733,17 @@ public class SchematicLoader public void generateSchematic(int incX, int incY, int incZ, int orientation, int destDimID, int originDimID, String schematicPath) { - + short width=0; short height=0; short length=0; //list of combined blockIds short[] blocks = new short[0]; - + //block metaData byte[] blockData = new byte[0]; - + //first 4 bytes of the block ID byte[] blockId = new byte[0]; @@ -756,19 +756,19 @@ public class SchematicLoader NBTTagList entities; NBTTagList tileEntities=null; - + //the wooden door leading into the pocket Point3D incomingLink= new Point3D(0,0,0); - + //the iron dim doors leading to more pockets ArrayList sideLinks = new ArrayList(); - + //the wooden dim doors leading to the surface ArrayList exitLinks = new ArrayList(); - + //the locations to spawn monoliths ArrayList monolithSpawns = new ArrayList(); - + //load the schematic from disk try { @@ -793,7 +793,7 @@ public class SchematicLoader width = nbtdata.getShort("Width"); height = nbtdata.getShort("Height"); length = nbtdata.getShort("Length"); - + //load block info blockId = nbtdata.getByteArray("Blocks"); blockData = nbtdata.getByteArray("Data"); @@ -814,7 +814,7 @@ public class SchematicLoader entities = nbtdata.getTagList("Entities"); tileentities = nbtdata.getTagList("TileEntities"); - **/ + **/ input.close(); //combine the split block IDs into a single short[] @@ -871,16 +871,16 @@ public class SchematicLoader { for ( z = 0; z < length; ++z) { - + int index = y * width * length + z * width + x; int blockToReplace=blocks[index]; int blockMetaData=blockData[index]; - + //NBTTagList tileEntity = tileEntities; //int size = tileEntity.tagCount(); - + if(blockToReplace==Block.doorIron.blockID&&blocks[ (y-1) * width * length + z * width + x]==Block.doorIron.blockID) { sideLinks.add(new Point3D(x,y,z)); @@ -900,56 +900,52 @@ public class SchematicLoader else if(blockToReplace==Block.endPortalFrame.blockID) { monolithSpawns.add(new Point3D(x,y,z)); - + } - + } } } - - //determines necessary rotation, reflection, and translation to build the .schematic by finding the difference between the - //.schematic incomingLink location which is relative to the .schematic only, and comparing it with the world incoming link coordinates - //must also factor in the orientation of the incoming door. - if(orientation==0) //TODO currently broken, only orientation 3 works atm - { - xCooe=-incomingLink.getX()+incX; - yCooe=-incomingLink.getY()+incY; - zCooe=-incomingLink.getZ()+incZ; - } - if(orientation==1)//TODO currently broken, only orientation 3 works atm - { - xCooe=-incomingLink.getX()+incX; - yCooe=-incomingLink.getY()+incY; - zCooe=-incomingLink.getZ()+incZ; - } - if(orientation==2)//TODO currently broken, only orientation 3 works atm - { - xCooe=-incomingLink.getX()+incX; - yCooe=-incomingLink.getY()+incY; - zCooe=-incomingLink.getZ()+incZ; - } - if(orientation==3)//TODO this only works because it is the default orientation of the pocket dim - { - xCooe=-incomingLink.getX()+incX; - yCooe=-incomingLink.getY()+incY; - zCooe=-incomingLink.getZ()+incZ; - } + //Compute the Y-axis translation that places our structure correctly + yCooe = incY - incomingLink.getY(); - //loop to actually place the blocks - for ( x = 0; x < width; ++x) + //Loop to actually place the blocks + for ( x = 0; x < width; x++) { - for ( y = 0; y < height; ++y) + for ( z = 0; z < length; z++) { - for ( z = 0; z < length; ++z) + //Compute the X-axis and Z-axis translations that will shift + //and rotate our structure properly. + switch (orientation) { - + case 0: + xCooe = -incomingLink.getX() + incX; + zCooe = -incomingLink.getZ() + incZ; + break; + case 1: + xCooe = -incomingLink.getX() + incX; + zCooe = -incomingLink.getZ() + incZ; + break; + case 2: + xCooe = -incomingLink.getX() + incX; + zCooe = -incomingLink.getZ() + incZ; + break; + case 3: + xCooe = -incomingLink.getX() + incX; + zCooe = -incomingLink.getZ() + incZ; + break; + } + + for ( y = 0; y < height; y++) + { + int index = y * width * length + z * width + x; int blockToReplace=blocks[index]; int blockMetaData=blockData[index]; NBTTagList tileEntity = tileEntities; - + //replace tagging blocks with air, and mob blocks with FoR if(blockToReplace==Block.endPortalFrame.blockID) { @@ -959,7 +955,7 @@ public class SchematicLoader { blockToReplace=mod_pocketDim.blockDimWall.blockID; } - + //place blocks and metaData if(blockToReplace>0) { @@ -990,23 +986,23 @@ public class SchematicLoader { tile.readFromNBT(tag); } - **/ - - //fill chests - if(world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe) instanceof TileEntityChest) - { - TileEntityChest chest = (TileEntityChest) world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe); - ChestGenHooks info = DDLoot.DungeonChestInfo; - WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), (TileEntityChest)world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe), info.getCount(rand)); - } - - //fill dispensers - if(world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe) instanceof TileEntityDispenser) - { - TileEntityDispenser dispenser = (TileEntityDispenser) world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe); - dispenser.addItem(new ItemStack(Item.arrow, 64)); + **/ - } + //fill chests + if(world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe) instanceof TileEntityChest) + { + TileEntityChest chest = (TileEntityChest) world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe); + ChestGenHooks info = DDLoot.DungeonChestInfo; + WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), (TileEntityChest)world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe), info.getCount(rand)); + } + + //fill dispensers + if(world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe) instanceof TileEntityDispenser) + { + TileEntityDispenser dispenser = (TileEntityDispenser) world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe); + dispenser.addItem(new ItemStack(Item.arrow, 64)); + + } } } } @@ -1016,39 +1012,39 @@ public class SchematicLoader //generate the LinkData defined by the door placement, Iron Dim doors first for(Point3D point : sideLinks) { - - int depth = dimHelper.instance.getDimDepth(originDimID); - int xNoise = 0; - int zNoise =0; - switch(world.getBlockMetadata(point.getX()+xCooe, point.getY()+yCooe-1, point.getZ()+zCooe)) - { - case 0: - xNoise = (int)rand.nextInt(depth+1*200)+depth*50; - zNoise = (int)rand.nextInt(depth+1*20)-(10)*depth; - break; - case 1: - xNoise = (int)rand.nextInt(depth+1*20)-(10)*depth; - zNoise = (int) rand.nextInt(depth+1*200)+depth*50; + int depth = dimHelper.instance.getDimDepth(originDimID); + int xNoise = 0; + int zNoise =0; + switch(world.getBlockMetadata(point.getX()+xCooe, point.getY()+yCooe-1, point.getZ()+zCooe)) + { + case 0: + xNoise = (int)rand.nextInt(depth+1*200)+depth*50; + zNoise = (int)rand.nextInt(depth+1*20)-(10)*depth; - break; - case 2: - xNoise = - (rand.nextInt(depth+1*200)+depth*50); - zNoise = (int)rand.nextInt(depth+1*20)-(10)*depth; + break; + case 1: + xNoise = (int)rand.nextInt(depth+1*20)-(10)*depth; + zNoise = (int) rand.nextInt(depth+1*200)+depth*50; - break; - case 3: - xNoise = (int)rand.nextInt(depth+1*20)-(10)*depth; - zNoise = -(rand.nextInt(depth+1*200)+depth*50); + break; + case 2: + xNoise = - (rand.nextInt(depth+1*200)+depth*50); + zNoise = (int)rand.nextInt(depth+1*20)-(10)*depth; - break; - } + break; + case 3: + xNoise = (int)rand.nextInt(depth+1*20)-(10)*depth; + zNoise = -(rand.nextInt(depth+1*200)+depth*50); - LinkData sideLink = new LinkData(destDimID,0,point.getX()+xCooe, point.getY()+yCooe, point.getZ()+zCooe,xNoise+point.getX()+xCooe, point.getY()+yCooe+1, zNoise+point.getZ()+zCooe,true,world.getBlockMetadata(point.getX()+xCooe, point.getY()+yCooe-1, point.getZ()+zCooe)); - dimHelper.instance.createPocket(sideLink, true, true); + break; + } + + LinkData sideLink = new LinkData(destDimID,0,point.getX()+xCooe, point.getY()+yCooe, point.getZ()+zCooe,xNoise+point.getX()+xCooe, point.getY()+yCooe+1, zNoise+point.getZ()+zCooe,true,world.getBlockMetadata(point.getX()+xCooe, point.getY()+yCooe-1, point.getZ()+zCooe)); + dimHelper.instance.createPocket(sideLink, true, true); } - + //generate linkData for wooden dim doors leading to the overworld for(Point3D point : exitLinks) { @@ -1064,7 +1060,7 @@ public class SchematicLoader else if((rand.nextBoolean()&&randomLink!=null)) { sideLink.destDimID=randomLink.locDimID; - // System.out.println("randomLink"); + // System.out.println("randomLink"); } sideLink.destYCoord=yCoordHelper.getFirstUncovered(sideLink.destDimID, point.getX()+xCooe,10,point.getZ()+zCooe); @@ -1075,7 +1071,7 @@ public class SchematicLoader } sideLink.linkOrientation=world.getBlockMetadata(point.getX()+xCooe, point.getY()+yCooe-1, point.getZ()+zCooe); - + dimHelper.instance.createLink(sideLink); dimHelper.instance.createLink(sideLink.destDimID , sideLink.locDimID, sideLink.destXCoord, sideLink.destYCoord, sideLink.destZCoord, sideLink.locXCoord, sideLink.locYCoord, sideLink.locZCoord, dimHelper.instance.flipDoorMetadata(sideLink.linkOrientation)); @@ -1093,7 +1089,7 @@ public class SchematicLoader E.printStackTrace(); } } - + //spawn monoliths for(Point3D point : monolithSpawns) { @@ -1102,7 +1098,7 @@ public class SchematicLoader world.spawnEntityInWorld(mob); } } - + public void generateDungeonPocket(LinkData link) { String filePath=DungeonHelper.instance().defaultBreak.schematicPath; @@ -1124,15 +1120,15 @@ public class SchematicLoader { return; } - + int cX; int cZ; int cY; - + Chunk chunk; cX = x >> 4; - cZ = z >> 4; - cY=y >>4; + cZ = z >> 4; + cY=y >>4; int chunkX=(x % 16)< 0 ? ((x) % 16)+16 : ((x) % 16); int chunkZ=((z) % 16)< 0 ? ((z) % 16)+16 : ((z) % 16); diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index dc2d3261..10af10e6 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -391,7 +391,7 @@ public class mod_pocketDim @ServerStarting public void serverStarting(FMLServerStartingEvent event) { - CommandRegenPocket.instance().register(event); + CommandResetDungeons.instance().register(event); CommandCreateDungeonRift.instance().register(event); CommandDeleteAllLinks.instance().register(event); CommandDeleteDimensionData.instance().register(event);