Created DungeonSchematic, a class that extends Schematic and adds DD-specific functionality such as methods for filtering the schematic's block before importing and exporting. Testing confirms that DungeonSchematic works well so far, although it still lacks critical features. Made some minor changes to Schematic and copied SchematicLoader.setBlockDirectly(). I realized during testing that setting blocks without using that function could cause problems. First, it's possible that the blocks would not be placed if chunks weren't created. Second, there are issues with blocks updating if we use World to set them, even if block updates are disabled. That causes some torches to break and other weird problems. Added classes to support block filtering operations applied to Schematic. These are used to implement ID standardization and removing mod blocks when importing.
150 lines
4.6 KiB
Java
150 lines
4.6 KiB
Java
package StevenDimDoors.mod_pocketDim.commands;
|
|
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.util.Collection;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import StevenDimDoors.mod_pocketDim.DDProperties;
|
|
import StevenDimDoors.mod_pocketDim.DungeonGenerator;
|
|
import StevenDimDoors.mod_pocketDim.LinkData;
|
|
import StevenDimDoors.mod_pocketDim.dungeon.DungeonSchematic;
|
|
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
|
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
|
import StevenDimDoors.mod_pocketDim.schematic.InvalidSchematicException;
|
|
|
|
public class CommandCreateDungeonRift extends DDCommandBase
|
|
{
|
|
private static CommandCreateDungeonRift instance = null;
|
|
|
|
private CommandCreateDungeonRift()
|
|
{
|
|
super("dd-rift", "<dungeon name | 'list' | 'random'>");
|
|
}
|
|
|
|
public static CommandCreateDungeonRift instance()
|
|
{
|
|
if (instance == null)
|
|
instance = new CommandCreateDungeonRift();
|
|
|
|
return instance;
|
|
}
|
|
|
|
@Override
|
|
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
|
|
{
|
|
DungeonHelper dungeonHelper = DungeonHelper.instance();
|
|
|
|
if (sender.worldObj.isRemote)
|
|
{
|
|
return DDCommandResult.SUCCESS;
|
|
}
|
|
if (command.length == 0)
|
|
{
|
|
return DDCommandResult.TOO_FEW_ARGUMENTS;
|
|
}
|
|
if (command.length > 1)
|
|
{
|
|
return DDCommandResult.TOO_MANY_ARGUMENTS;
|
|
}
|
|
|
|
if (command[0].equals("list"))
|
|
{
|
|
Collection<String> dungeonNames = dungeonHelper.getDungeonNames();
|
|
for (String name : dungeonNames)
|
|
{
|
|
sender.sendChatToPlayer(name);
|
|
}
|
|
sender.sendChatToPlayer("");
|
|
}
|
|
else
|
|
{
|
|
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 + ").");
|
|
|
|
/*try {
|
|
DungeonSchematic dungeon;
|
|
if ((new File(result.schematicPath)).exists())
|
|
{
|
|
dungeon = DungeonSchematic.readFromFile(result.schematicPath);
|
|
}
|
|
else
|
|
{
|
|
dungeon = DungeonSchematic.readFromResource(result.schematicPath);
|
|
}
|
|
dungeon.ApplyImportFilters(DDProperties.instance());
|
|
dungeon.copyToWorld(sender.worldObj, x, y, z);
|
|
} catch (InvalidSchematicException e) {
|
|
e.printStackTrace();
|
|
} catch (FileNotFoundException e) {
|
|
e.printStackTrace();
|
|
}*/
|
|
|
|
}
|
|
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<DungeonGenerator> 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());
|
|
}
|
|
} |