2013-02-18 03:46:16 +01:00
|
|
|
package StevenDimDoors.mod_pocketDim;
|
2013-06-02 03:43:56 +02:00
|
|
|
import java.io.File;
|
2013-07-30 19:58:14 +02:00
|
|
|
import java.io.FileNotFoundException;
|
2013-07-31 14:05:58 +02:00
|
|
|
import java.util.HashMap;
|
2013-02-18 03:46:16 +01:00
|
|
|
|
|
|
|
import net.minecraft.world.World;
|
2013-07-30 19:58:14 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.dungeon.DungeonSchematic;
|
2013-06-13 21:44:11 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
2013-06-10 23:03:52 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
2013-07-30 19:58:14 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.schematic.InvalidSchematicException;
|
2013-06-14 01:01:54 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
public class SchematicLoader
|
2013-07-31 14:05:58 +02:00
|
|
|
{
|
2013-07-30 19:58:14 +02:00
|
|
|
private SchematicLoader() { }
|
2013-06-27 05:54:06 +02:00
|
|
|
|
2013-07-31 14:05:58 +02:00
|
|
|
public static boolean generateDungeonPocket(LinkData link, DDProperties properties)
|
2013-06-14 01:01:54 +02:00
|
|
|
{
|
2013-07-30 19:58:14 +02:00
|
|
|
//TODO: Phase this function out in the next update. ~SenseiKiwi
|
2013-07-09 06:50:06 +02:00
|
|
|
|
2013-07-31 14:05:58 +02:00
|
|
|
if (link == null || properties == null)
|
2013-06-26 04:10:15 +02:00
|
|
|
{
|
2013-07-31 14:05:58 +02:00
|
|
|
return false;
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
2013-07-30 19:58:14 +02:00
|
|
|
try
|
2013-06-14 01:01:54 +02:00
|
|
|
{
|
2013-07-31 14:05:58 +02:00
|
|
|
String schematicPath;
|
2013-07-30 19:58:14 +02:00
|
|
|
int originDimID = link.locDimID;
|
|
|
|
int destDimID = link.destDimID;
|
2013-07-31 14:05:58 +02:00
|
|
|
HashMap<Integer, DimData> dimList = dimHelper.dimList;
|
|
|
|
|
|
|
|
if (dimList.containsKey(destDimID))
|
2013-02-18 03:46:16 +01:00
|
|
|
{
|
2013-07-31 14:05:58 +02:00
|
|
|
if (dimList.get(destDimID).dungeonGenerator == null)
|
|
|
|
{
|
|
|
|
DungeonHelper.instance().generateDungeonLink(link);
|
|
|
|
}
|
|
|
|
schematicPath = dimList.get(destDimID).dungeonGenerator.schematicPath;
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
2013-07-30 19:58:14 +02:00
|
|
|
else
|
2013-02-18 03:46:16 +01:00
|
|
|
{
|
2013-07-31 14:05:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2013-06-30 06:24:44 +02:00
|
|
|
}
|
2013-06-27 05:54:06 +02:00
|
|
|
|
2013-07-31 14:05:58 +02:00
|
|
|
dungeon.applyImportFilters(properties);
|
|
|
|
dimList.get(destDimID).hasBeenFilled = true;
|
2013-07-30 19:58:14 +02:00
|
|
|
if (dimHelper.getWorld(destDimID) == null)
|
2013-07-15 22:58:44 +02:00
|
|
|
{
|
2013-07-30 19:58:14 +02:00
|
|
|
dimHelper.initDimension(destDimID);
|
2013-07-15 22:58:44 +02:00
|
|
|
}
|
2013-07-30 19:58:14 +02:00
|
|
|
World world = dimHelper.getWorld(destDimID);
|
|
|
|
|
|
|
|
dungeon.copyToWorld(world, new Point3D(link.destXCoord, link.destYCoord, link.destZCoord), link.linkOrientation, originDimID, destDimID);
|
2013-07-31 14:05:58 +02:00
|
|
|
return true;
|
2013-07-15 22:58:44 +02:00
|
|
|
}
|
2013-07-31 14:05:58 +02:00
|
|
|
catch (Exception e)
|
2013-06-27 05:54:06 +02:00
|
|
|
{
|
2013-07-30 19:58:14 +02:00
|
|
|
e.printStackTrace();
|
2013-07-31 14:05:58 +02:00
|
|
|
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);
|
2013-06-27 05:54:06 +02:00
|
|
|
}
|
2013-07-31 14:05:58 +02:00
|
|
|
else
|
2013-06-27 05:54:06 +02:00
|
|
|
{
|
2013-07-31 14:05:58 +02:00
|
|
|
dungeon = DungeonSchematic.readFromResource(schematicPath);
|
2013-06-27 05:54:06 +02:00
|
|
|
}
|
2013-07-31 14:05:58 +02:00
|
|
|
return dungeon;
|
2013-06-14 01:01:54 +02:00
|
|
|
}
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|