Major Improvements to DungeonHelper, Minor Bug Fixes and Tweaks #25

Merged
SenseiKiwi merged 29 commits from master into master 2013-06-16 19:30:26 +00:00
2 changed files with 23 additions and 19 deletions
Showing only changes of commit 61297c3a3a - Show all commits

View File

@@ -1,13 +1,11 @@
package StevenDimDoors.mod_pocketDim.commands; package StevenDimDoors.mod_pocketDim.commands;
import java.util.regex.Pattern; import java.io.File;
import net.minecraft.command.CommandBase; import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender; import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.DungeonGenerator;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
public class CommandEndDungeonCreation extends CommandBase public class CommandEndDungeonCreation extends CommandBase
@@ -34,14 +32,14 @@ public class CommandEndDungeonCreation extends CommandBase
if (!dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId)) if (!dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId))
{ {
if(var2.length<2) if (var2.length < 2)
{ {
player.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway"); player.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway");
return; return;
} }
else if(!var2[1].contains("OVERRIDE")) else if (!var2[1].contains("OVERRIDE"))
{ {
player.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway"); player.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway");
return; return;
@@ -63,14 +61,22 @@ public class CommandEndDungeonCreation extends CommandBase
//Check that the dungeon name is valid to prevent directory traversal and other forms of abuse //Check that the dungeon name is valid to prevent directory traversal and other forms of abuse
if (DungeonHelper.NamePattern.matcher(var2[0]).matches()) if (DungeonHelper.NamePattern.matcher(var2[0]).matches())
{ {
DungeonGenerator newDungeon = dungeonHelper.exportDungeon(player.worldObj, x, y, z, properties.CustomSchematicDirectory + "/" + var2[0] + ".schematic"); String exportPath = properties.CustomSchematicDirectory + "/" + var2[0] + ".schematic";
player.sendChatToPlayer("created dungeon schematic in " + properties.CustomSchematicDirectory + "/" + var2[0]+".schematic"); if (dungeonHelper.exportDungeon(player.worldObj, x, y, z, exportPath))
if (dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId) && !player.worldObj.isRemote)
{ {
// mod_pocketDim.dungeonHelper.customDungeonStatus.remove(player.worldObj.provider.dimensionId); player.sendChatToPlayer("Saved dungeon schematic in " + exportPath);
// dimHelper.instance.teleportToPocket(player.worldObj, mod_pocketDim.dungeonHelper.customDungeonStatus.get(player.worldObj.provider.dimensionId), player); dungeonHelper.registerCustomDungeon(new File(exportPath));
if (dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId) && !player.worldObj.isRemote)
{
// mod_pocketDim.dungeonHelper.customDungeonStatus.remove(player.worldObj.provider.dimensionId);
// dimHelper.instance.teleportToPocket(player.worldObj, mod_pocketDim.dungeonHelper.customDungeonStatus.get(player.worldObj.provider.dimensionId), player);
}
}
else
{
player.sendChatToPlayer("Failed to save dungeon schematic!");
} }
} }
else else

View File

@@ -352,7 +352,7 @@ public class DungeonHelper
} }
} }
public DungeonGenerator exportDungeon(World world, int xI, int yI, int zI, String file) public boolean exportDungeon(World world, int xI, int yI, int zI, String exportPath)
{ {
int xMin; int xMin;
int yMin; int yMin;
@@ -366,9 +366,8 @@ public class DungeonHelper
yMin=yMax=yI; yMin=yMax=yI;
zMin=zMax=zI; zMin=zMax=zI;
for(int count=0;count<50;count++) for (int count = 0; count < 50; count++)
{ {
if(world.getBlockId(xMin, yI, zI)!=properties.PermaFabricBlockID) if(world.getBlockId(xMin, yI, zI)!=properties.PermaFabricBlockID)
{ {
xMin--; xMin--;
@@ -492,17 +491,16 @@ public class DungeonHelper
CompoundTag schematicTag = new CompoundTag("Schematic", schematic); CompoundTag schematicTag = new CompoundTag("Schematic", schematic);
try try
{ {
NBTOutputStream stream = new NBTOutputStream(new FileOutputStream(file)); NBTOutputStream stream = new NBTOutputStream(new FileOutputStream(exportPath));
stream.writeTag(schematicTag); stream.writeTag(schematicTag);
stream.close(); stream.close();
return true;
} }
catch(Exception e) catch(Exception e)
{ {
e.printStackTrace(); e.printStackTrace();
return false;
} }
this.registerCustomDungeon(new File(file));
return new DungeonGenerator(0, file, true);
} }
public void generateDungeonlink(LinkData incoming) public void generateDungeonlink(LinkData incoming)