Progress to Next Update #57

Merged
SenseiKiwi merged 3 commits from ProgressOnUpdate into master 2013-07-31 19:34:39 +00:00
2 changed files with 60 additions and 25 deletions
Showing only changes of commit 356bfe4bd0 - Show all commits

View File

@@ -1,6 +1,7 @@
package StevenDimDoors.mod_pocketDim;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.dungeon.DungeonSchematic;
@@ -9,41 +10,52 @@ import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
import StevenDimDoors.mod_pocketDim.schematic.InvalidSchematicException;
public class SchematicLoader
{
{
private SchematicLoader() { }
public static void generateDungeonPocket(LinkData link, DDProperties properties)
public static boolean generateDungeonPocket(LinkData link, DDProperties properties)
{
//TODO: Phase this function out in the next update. ~SenseiKiwi
String filePath=DungeonHelper.instance().defaultBreak.schematicPath;
if(dimHelper.dimList.containsKey(link.destDimID))
if (link == null || properties == null)
{
if(dimHelper.dimList.get(link.destDimID).dungeonGenerator == null)
{
DungeonHelper.instance().generateDungeonLink(link);
}
filePath = dimHelper.dimList.get(link.destDimID).dungeonGenerator.schematicPath;
return false;
}
//this.generateSchematic(link.destXCoord, link.destYCoord, link.destZCoord, link.linkOrientation, link.destDimID, link.locDimID, filePath);
try
{
String schematicPath;
int originDimID = link.locDimID;
int destDimID = link.destDimID;
DungeonSchematic dungeon;
if ((new File(filePath)).exists())
HashMap<Integer, DimData> dimList = dimHelper.dimList;
if (dimList.containsKey(destDimID))
{
dungeon = DungeonSchematic.readFromFile(filePath);
if (dimList.get(destDimID).dungeonGenerator == null)
{
DungeonHelper.instance().generateDungeonLink(link);
}
schematicPath = dimList.get(destDimID).dungeonGenerator.schematicPath;
}
else
{
dungeon = DungeonSchematic.readFromResource(filePath);
return false;
}
dungeon.applyImportFilters(properties);
dimHelper.dimList.get(destDimID).hasBeenFilled = true;
DungeonSchematic dungeon = checkSourceAndLoad(schematicPath);
//Validate the dungeon's dimensions
if (!hasValidDimensions(dungeon))
{
//TODO: In the future, remove this dungeon from the generation lists altogether.
//That will have to wait until our code is updated to support that more easily.
System.err.println("The following schematic file has dimensions that exceed the maximum permitted dimensions for dungeons: " + schematicPath);
System.err.println("The dungeon will not be loaded.");
dungeon = checkSourceAndLoad(DungeonHelper.instance().defaultBreak.schematicPath);
}
dungeon.applyImportFilters(properties);
dimList.get(destDimID).hasBeenFilled = true;
if (dimHelper.getWorld(destDimID) == null)
{
dimHelper.initDimension(destDimID);
@@ -51,14 +63,34 @@ public class SchematicLoader
World world = dimHelper.getWorld(destDimID);
dungeon.copyToWorld(world, new Point3D(link.destXCoord, link.destYCoord, link.destZCoord), link.linkOrientation, originDimID, destDimID);
return true;
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (InvalidSchematicException e)
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
private static boolean hasValidDimensions(DungeonSchematic dungeon)
{
return (dungeon.getWidth() <= DungeonHelper.MAX_DUNGEON_WIDTH &&
dungeon.getHeight() <= DungeonHelper.MAX_DUNGEON_HEIGHT &&
dungeon.getLength() <= DungeonHelper.MAX_DUNGEON_LENGTH);
}
private static DungeonSchematic checkSourceAndLoad(String schematicPath) throws FileNotFoundException, InvalidSchematicException
{
//TODO: Change this code once we introduce an isInternal flag in dungeon data
DungeonSchematic dungeon;
if ((new File(schematicPath)).exists())
{
dungeon = DungeonSchematic.readFromFile(schematicPath);
}
else
{
dungeon = DungeonSchematic.readFromResource(schematicPath);
}
return dungeon;
}
}

View File

@@ -31,6 +31,9 @@ public class DungeonHelper
private static final int DEFAULT_DUNGEON_WEIGHT = 100;
public static final int MAX_DUNGEON_WEIGHT = 10000; //Used to prevent overflows and math breaking down
private static final int MAX_EXPORT_RADIUS = 50;
public static final short MAX_DUNGEON_WIDTH = 2 * MAX_EXPORT_RADIUS + 1;
public static final short MAX_DUNGEON_HEIGHT = 2 * MAX_EXPORT_RADIUS + 1;
public static final short MAX_DUNGEON_LENGTH = 2 * MAX_EXPORT_RADIUS + 1;
public static final int FABRIC_OF_REALITY_EXPORT_ID = 1973;
public static final int PERMAFABRIC_EXPORT_ID = 220;
@@ -340,9 +343,9 @@ public class DungeonHelper
//Write schematic data to a file
try
{
short size = (short) 2 * MAX_EXPORT_RADIUS + 1;
DungeonSchematic dungeon = DungeonSchematic.copyFromWorld(world,
centerX - MAX_EXPORT_RADIUS, centerY - MAX_EXPORT_RADIUS, centerZ - MAX_EXPORT_RADIUS, size, size, size, true);
centerX - MAX_EXPORT_RADIUS, centerY - MAX_EXPORT_RADIUS, centerZ - MAX_EXPORT_RADIUS,
MAX_DUNGEON_WIDTH, MAX_DUNGEON_HEIGHT, MAX_DUNGEON_LENGTH, true);
dungeon.applyExportFilters(properties);
dungeon.writeToFile(exportPath);
return true;