Reviewed and Rewrote Commands #169

Merged
SenseiKiwi merged 17 commits from master into master 2014-07-06 01:59:42 +00:00
17 changed files with 397 additions and 422 deletions

View File

@@ -1,5 +1,9 @@
package StevenDimDoors.mod_pocketDim.commands; package StevenDimDoors.mod_pocketDim.commands;
import java.util.Collection;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.LinkTypes;
@@ -9,12 +13,6 @@ import StevenDimDoors.mod_pocketDim.dungeon.DungeonData;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
import StevenDimDoors.mod_pocketDim.world.PocketBuilder; import StevenDimDoors.mod_pocketDim.world.PocketBuilder;
import java.util.Collection;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
public class CommandCreateDungeonRift extends DDCommandBase public class CommandCreateDungeonRift extends DDCommandBase
{ {
private static CommandCreateDungeonRift instance = null; private static CommandCreateDungeonRift instance = null;
@@ -38,10 +36,6 @@ public class CommandCreateDungeonRift extends DDCommandBase
NewDimData dimension; NewDimData dimension;
DungeonHelper dungeonHelper = DungeonHelper.instance(); DungeonHelper dungeonHelper = DungeonHelper.instance();
if (sender.worldObj.isRemote)
{
return DDCommandResult.SUCCESS;
}
if (command.length == 0) if (command.length == 0)
{ {
return DDCommandResult.TOO_FEW_ARGUMENTS; return DDCommandResult.TOO_FEW_ARGUMENTS;

View File

@@ -1,6 +1,5 @@
package StevenDimDoors.mod_pocketDim.commands; package StevenDimDoors.mod_pocketDim.commands;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
@@ -23,11 +22,6 @@ public class CommandCreatePocket extends DDCommandBase
@Override @Override
protected DDCommandResult 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) if (command.length > 0)
{ {
@@ -42,8 +36,8 @@ public class CommandCreatePocket extends DDCommandBase
DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z); DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z);
//Notify the player //Notify the player
sendChat(sender,("Created a door to a pocket dimension. Please build your dungeon there.")); sendChat(sender, "Created a door to a pocket dimension. Please build your dungeon there.");
}
return DDCommandResult.SUCCESS; return DDCommandResult.SUCCESS;
} }
} }

View File

@@ -39,10 +39,6 @@ public class CommandCreateRandomRift extends DDCommandBase
NewDimData dimension; NewDimData dimension;
DungeonHelper dungeonHelper = DungeonHelper.instance(); DungeonHelper dungeonHelper = DungeonHelper.instance();
if (sender.worldObj.isRemote)
{
return DDCommandResult.SUCCESS;
}
if (command.length > 1) if (command.length > 1)
{ {
return DDCommandResult.TOO_MANY_ARGUMENTS; return DDCommandResult.TOO_MANY_ARGUMENTS;
@@ -118,9 +114,6 @@ public class CommandCreateRandomRift extends DDCommandBase
{ {
return null; return null;
} }
else
{
return matches.get( random.nextInt(matches.size()) ); return matches.get( random.nextInt(matches.size()) );
} }
}
} }

View File

@@ -1,69 +0,0 @@
package StevenDimDoors.mod_pocketDim.commands;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import java.util.ArrayList;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
@SuppressWarnings("deprecation")
public class CommandDeleteAllLinks extends DDCommandBase
{
private static CommandDeleteAllLinks instance = null;
private CommandDeleteAllLinks()
{
super("dd-deletelinks", "???");
}
public static CommandDeleteAllLinks instance()
{
if (instance == null)
instance = new CommandDeleteAllLinks();
return instance;
}
@Override
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{
int linksRemoved=0;
int targetDim;
boolean shouldGo= true;
if(command.length==1)
{
targetDim = parseInt(sender, command[0]);
}
else
{
targetDim=0;
shouldGo=false;
sendChat(sender, ("Error-Invalid argument, delete_all_links <targetDimID>"));
}
if(shouldGo)
{
NewDimData dim = PocketManager.getDimensionData(targetDim);
ArrayList<DimLink> linksInDim = dim.getAllLinks();
for (DimLink link : linksInDim)
{
World targetWorld = PocketManager.loadDimension(targetDim);
targetWorld.setBlock(link.source().getX(), link.source().getY(), link.source().getZ(), 0);
dim.deleteLink(link);
//TODO Probably should check what the block is, but thats annoying so Ill do it later.
linksRemoved++;
}
sendChat(sender,("Removed " + linksRemoved + " links."));
}
return DDCommandResult.SUCCESS; //TEMPORARY HACK
}
}

View File

@@ -2,22 +2,21 @@ package StevenDimDoors.mod_pocketDim.commands;
import java.util.ArrayList; import java.util.ArrayList;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World; import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.util.Point4D;
@SuppressWarnings("deprecation")
public class CommandDeleteRifts extends DDCommandBase public class CommandDeleteRifts extends DDCommandBase
{ {
private static CommandDeleteRifts instance = null; private static CommandDeleteRifts instance = null;
private CommandDeleteRifts() private CommandDeleteRifts()
{ {
super("dd-???", "???"); super("dd-deleterifts", "[dimension number]");
} }
public static CommandDeleteRifts instance() public static CommandDeleteRifts instance()
@@ -31,47 +30,64 @@ public class CommandDeleteRifts extends DDCommandBase
@Override @Override
protected DDCommandResult processCommand(EntityPlayer sender, String[] command) protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{ {
int linksRemoved=0; int linksRemoved = 0;
int targetDim; int targetDimension;
boolean shouldGo= true;
if(command.length==1) if (command.length > 1)
{ {
targetDim = parseInt(sender, command[0]); return DDCommandResult.TOO_MANY_ARGUMENTS;
}
if (command.length == 0)
{
targetDimension = sender.worldObj.provider.dimensionId;
} }
else else
{ {
targetDim=0; try
shouldGo=false; {
sendChat(sender,("Error-Invalid argument, delete_all_links <targetDimID>")); targetDimension = Integer.parseInt(command[0]);
}
catch (NumberFormatException e)
{
return DDCommandResult.INVALID_DIMENSION_ID;
}
} }
if(shouldGo) World world = PocketManager.loadDimension(targetDimension);
if (world == null)
{ {
return DDCommandResult.UNREGISTERED_DIMENSION;
}
NewDimData dim = PocketManager.getDimensionData(targetDim); int x;
ArrayList<DimLink> linksInDim = dim.getAllLinks(); int y;
int z;
for (DimLink link : linksInDim) Point4D location;
NewDimData dimension = PocketManager.getDimensionData(targetDimension);
ArrayList<DimLink> links = dimension.getAllLinks();
for (DimLink link : links)
{ {
World targetWorld = PocketManager.loadDimension(targetDim); location = link.source();
x = location.getX();
if(!mod_pocketDim.blockRift.isBlockImmune(sender.worldObj,link.source().getX(), link.source().getY(), link.source().getZ())|| y = location.getY();
(targetWorld.getBlockId(link.source().getX(), link.source().getY(), link.source().getZ())==mod_pocketDim.blockRift.blockID)) z = location.getZ();
if (world.getBlockId(x, y, z) == mod_pocketDim.blockRift.blockID)
{ {
// Remove the rift and its link
world.setBlockToAir(x, y, z);
dimension.deleteLink(link);
linksRemoved++; linksRemoved++;
targetWorld.setBlock(link.source().getX(), link.source().getY(), link.source().getZ(), 0);
dim.deleteLink(link);
} }
//TODO Probably should check what the block is, but thats annoying so Ill do it later. else if (!mod_pocketDim.blockRift.isBlockImmune(world, x, y, z))
{
// If a block is not immune, then it must not be a DD block.
// The link would regenerate into a rift eventually.
// We only need to remove the link.
dimension.deleteLink(link);
linksRemoved++;
} }
sendChat(sender,("Removed " + linksRemoved + " links."));
} }
return DDCommandResult.SUCCESS; //TEMPORARY HACK sendChat(sender, "Removed " + linksRemoved + " links.");
return DDCommandResult.SUCCESS;
} }
} }

View File

@@ -2,7 +2,6 @@ package StevenDimDoors.mod_pocketDim.commands;
import java.io.File; import java.io.File;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import StevenDimDoors.mod_pocketDim.config.DDProperties; import StevenDimDoors.mod_pocketDim.config.DDProperties;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
@@ -60,25 +59,15 @@ public class CommandExportDungeon extends DDCommandBase
//Export the schematic //Export the schematic
return exportDungeon(sender, command[0]); return exportDungeon(sender, command[0]);
} }
else
{
//The schematic name contains illegal characters. Inform the user. //The schematic name contains illegal characters. Inform the user.
return new DDCommandResult("Error: Invalid schematic name. Please use only letters, numbers, dashes, and underscores."); return new DDCommandResult("Error: Invalid schematic name. Please use only letters, numbers, dashes, and underscores.");
} }
}
else
{
//The command is malformed in some way. Assume that the user meant to use //The command is malformed in some way. Assume that the user meant to use
//the 3-argument version and report an error. //the 3-argument version and report an error.
return DDCommandResult.TOO_FEW_ARGUMENTS; return DDCommandResult.TOO_FEW_ARGUMENTS;
} }
}
//The user must have used the 3-argument version of this command //The user must have used the 3-argument version of this command
//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 //TODO: This validation should be in DungeonHelper or in another class. We should move it
//during the save file format rewrite. ~SenseiKiwi //during the save file format rewrite. ~SenseiKiwi
@@ -100,8 +89,7 @@ public class CommandExportDungeon extends DDCommandBase
{ {
return exportDungeon(sender, join(command, "_", 0, 3)); return exportDungeon(sender, join(command, "_", 0, 3));
} }
else
{
//Validate the weight argument //Validate the weight argument
try try
{ {
@@ -112,16 +100,12 @@ public class CommandExportDungeon extends DDCommandBase
} }
} }
catch (Exception e) { } catch (Exception e) { }
}
//If we've reached this point, then we must have an invalid weight. //If we've reached this point, then we must have an invalid weight.
return new DDCommandResult("Invalid dungeon weight. Please specify a weight between " return new DDCommandResult("Invalid dungeon weight. Please specify a weight between "
+ DungeonHelper.MIN_DUNGEON_WEIGHT + " and " + DungeonHelper.MAX_DUNGEON_WEIGHT + ", inclusive."); + DungeonHelper.MIN_DUNGEON_WEIGHT + " and " + DungeonHelper.MAX_DUNGEON_WEIGHT + ", inclusive.");
} }
return DDCommandResult.SUCCESS;
}
private static DDCommandResult exportDungeon(EntityPlayer player, String name) private static DDCommandResult exportDungeon(EntityPlayer player, String name)
{ {
DDProperties properties = DDProperties.instance(); DDProperties properties = DDProperties.instance();
@@ -137,11 +121,8 @@ public class CommandExportDungeon extends DDCommandBase
dungeonHelper.registerDungeon(exportPath, dungeonHelper.getDungeonPack("ruins"), false, true); dungeonHelper.registerDungeon(exportPath, dungeonHelper.getDungeonPack("ruins"), false, true);
return DDCommandResult.SUCCESS; return DDCommandResult.SUCCESS;
} }
else
{
return new DDCommandResult("Error: Failed to save dungeon schematic!"); return new DDCommandResult("Error: Failed to save dungeon schematic!");
} }
}
private static String join(String[] source, String delimiter, int start, int end) private static String join(String[] source, String delimiter, int start, int end)
{ {

View File

@@ -31,10 +31,6 @@ public class CommandListDungeons extends DDCommandBase
int pageCount; int pageCount;
ArrayList<String> dungeonNames; ArrayList<String> dungeonNames;
if (sender.worldObj.isRemote)
{
return DDCommandResult.SUCCESS;
}
if (command.length > 1) if (command.length > 1)
{ {
return DDCommandResult.TOO_MANY_ARGUMENTS; return DDCommandResult.TOO_MANY_ARGUMENTS;

View File

@@ -1,16 +1,14 @@
package StevenDimDoors.mod_pocketDim.commands; package StevenDimDoors.mod_pocketDim.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.DimensionManager;
import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.LinkTypes;
import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.core.PocketManager;
@SuppressWarnings("deprecation")
public class CommandResetDungeons extends DDCommandBase public class CommandResetDungeons extends DDCommandBase
{ {
private static CommandResetDungeons instance = null; private static CommandResetDungeons instance = null;
@@ -31,61 +29,75 @@ public class CommandResetDungeons extends DDCommandBase
@Override @Override
protected DDCommandResult processCommand(EntityPlayer sender, String[] command) protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{ {
if(sender.worldObj.isRemote)
{
return DDCommandResult.SUCCESS;
}
if (command.length > 0) if (command.length > 0)
{ {
return DDCommandResult.TOO_FEW_ARGUMENTS; return DDCommandResult.TOO_MANY_ARGUMENTS;
} }
int dungeonCount = 0; int id;
int resetCount = 0; int resetCount = 0;
ArrayList<Integer> dimsToDelete = new ArrayList<Integer>(); int dungeonCount = 0;
ArrayList<Integer> dimsToFix = new ArrayList<Integer>(); HashSet<Integer> deletedDimensions = new HashSet<Integer>();
ArrayList<NewDimData> loadedDungeons = new ArrayList<NewDimData>();
for (NewDimData data : PocketManager.getDimensions()) // Copy the list of dimensions to iterate over the copy. Otherwise,
// we would trigger an exception by modifying the original list.
ArrayList<NewDimData> dimensions = new ArrayList<NewDimData>();
for (NewDimData dimension : PocketManager.getDimensions())
{ {
dimensions.add(dimension);
}
if(DimensionManager.getWorld(data.id())==null&&data.isDungeon()) // Iterate over the list of dimensions. Check which ones are dungeons.
// If a dungeon is found, try to delete it. If it can't be deleted,
// then it must be loaded and needs to be updated to prevent bugs.
for (NewDimData dimension : dimensions)
{
if (dimension.isDungeon())
{
dungeonCount++;
id = dimension.id();
if (PocketManager.deletePocket(dimension, true))
{ {
resetCount++; resetCount++;
dungeonCount++; deletedDimensions.add(id);
dimsToDelete.add(data.id());
} }
else if(data.isDungeon()) else
{ {
dimsToFix.add(data.id()); loadedDungeons.add(dimension);
dungeonCount++;
for(DimLink link : data.links())
{
if(link.linkType()==LinkTypes.REVERSE)
{
data.createLink(link.source(), LinkTypes.DUNGEON_EXIT, link.orientation());
} }
if(link.linkType()==LinkTypes.DUNGEON) }
}
// Modify the loaded dungeons to prevent bugs
for (NewDimData dungeon : loadedDungeons)
{ {
data.createLink(link.source(), LinkTypes.DUNGEON, link.orientation()); // Find top-most loaded dungeons and update their parents.
// They will automatically update their children.
// Dungeons with non-dungeon parents don't need to be fixed.
if (dungeon.parent() == null)
{
dungeon.setParentToRoot();
}
// Links to any deleted dungeons must be replaced
for (DimLink link : dungeon.links())
{
if (link.hasDestination() && deletedDimensions.contains(link.destination().getDimension()))
{
if (link.linkType() == LinkTypes.DUNGEON)
{
dungeon.createLink(link.source(), LinkTypes.DUNGEON, link.orientation());
}
else if (link.linkType() == LinkTypes.REVERSE)
{
dungeon.createLink(link.source(), LinkTypes.DUNGEON_EXIT, link.orientation());
} }
} }
} }
} }
for(Integer dimID:dimsToDelete) // Notify the user of the results
{
PocketManager.deletePocket(PocketManager.getDimensionData(dimID), true);
}
/**
* temporary workaround
*/
for(Integer dimID: dimsToFix)
{
PocketManager.getDimensionData(dimID).setParentToRoot();
}
//TODO- for some reason the parent field of loaded dimenions get reset to null if I call .setParentToRoot() before I delete the pockets.
//TODO implement blackList
//Notify the user of the results
sendChat(sender,("Reset complete. " + resetCount + " out of " + dungeonCount + " dungeons were reset.")); sendChat(sender,("Reset complete. " + resetCount + " out of " + dungeonCount + " dungeons were reset."));
return DDCommandResult.SUCCESS; return DDCommandResult.SUCCESS;
} }

View File

@@ -1,23 +1,23 @@
package StevenDimDoors.mod_pocketDim.commands; package StevenDimDoors.mod_pocketDim.commands;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import StevenDimDoors.mod_pocketDim.core.DDTeleporter;
import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.util.Point4D;
import java.util.Arrays;
import java.util.List;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.DimensionManager;
public class CommandTeleportPlayer extends DDCommandBase public class CommandTeleportPlayer extends DDCommandBase
{ {
private static CommandTeleportPlayer instance = null; private static CommandTeleportPlayer instance = null;
private CommandTeleportPlayer() private CommandTeleportPlayer()
{ {
super("dd-tp", new String[] {"<Player Name> <Dimension ID> <X Coord> <Y Coord> <Z Coord>","<Player Name> <Dimension ID>"} ); super("dd-tp", new String[] {
"<player name> <dimension number>",
"<player name> <x> <y> <z>",
"<player name> <dimension number> <x> <y> <z>"} );
} }
public static CommandTeleportPlayer instance() public static CommandTeleportPlayer instance()
@@ -28,110 +28,120 @@ public class CommandTeleportPlayer extends DDCommandBase
return instance; return instance;
} }
/**
* TODO- Change to accept variety of input, like just coords, just dim ID, or two player names.
*/
@Override @Override
protected DDCommandResult processCommand(EntityPlayer sender, String[] command) protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{ {
EntityPlayer targetPlayer = sender; int x;
int dimDestinationID = sender.worldObj.provider.dimensionId; int y;
int z;
World world;
int dimensionID;
Point4D destination;
NewDimData dimension;
boolean checkOrientation;
EntityPlayer targetPlayer;
if(command.length == 5) if (command.length < 2)
{ {
for(int i= 1; i <5;i++) return DDCommandResult.TOO_FEW_ARGUMENTS;
}
if (command.length > 5)
{ {
if(!isInteger(command[i])) return DDCommandResult.TOO_MANY_ARGUMENTS;
}
if (command.length == 3)
{
return DDCommandResult.INVALID_ARGUMENTS;
}
// Check that all arguments after the username are integers
for (int k = 1; k < command.length; k++)
{
if (!isInteger(command[k]))
{ {
return DDCommandResult.INVALID_ARGUMENTS; return DDCommandResult.INVALID_ARGUMENTS;
} }
} }
if(sender.worldObj.getPlayerEntityByName(command[0])!=null) //Gets the targeted player // Check if the target player is logged in
targetPlayer = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(command[0]);
if (targetPlayer == null)
{ {
targetPlayer = sender.worldObj.getPlayerEntityByName(command[0]); return DDCommandResult.PLAYER_OFFLINE;
}
// If a dimension ID was provided, try to load it
if (command.length != 4)
{
dimensionID = Integer.parseInt(command[1]);
world = PocketManager.loadDimension(dimensionID);
if (world == null)
{
return DDCommandResult.UNREGISTERED_DIMENSION;
}
} }
else else
{ {
return DDCommandResult.INVALID_ARGUMENTS; dimensionID = targetPlayer.worldObj.provider.dimensionId;
} // SenseiKiwi: Will not be used, but I prefer not to leave 'world' as null
dimDestinationID=Integer.parseInt(command[1]);//gets the target dim ID from the command string world = targetPlayer.worldObj;
if(!DimensionManager.isDimensionRegistered(dimDestinationID))
{
return DDCommandResult.INVALID_DIMENSION_ID;
} }
PocketManager.loadDimension(dimDestinationID); // If we teleport to a pocket dimension, set checkOrientation to true
Point4D destination = new Point4D(Integer.parseInt(command[2]),Integer.parseInt(command[3]),Integer.parseInt(command[4]),dimDestinationID); // so the player is placed correctly relative to the entrance door.
DDTeleporter.teleportEntity(targetPlayer, destination, false); checkOrientation = false;
}
else if(command.length == 2 && isInteger(command[1])) // Parse or calculate the destination as necessary
// The Y coordinate must be increased by 1 because of the way that
// DDTeleporter considers destination points. It assumes that the
// point provided is the upper block of a door.
if (command.length == 2)
{ {
if(sender.worldObj.getPlayerEntityByName(command[0])!=null) //Gets the targeted player // Check if the destination is a pocket dimension
dimension = PocketManager.getDimensionData(dimensionID);
if (dimension.isPocketDimension())
{ {
targetPlayer = sender.worldObj.getPlayerEntityByName(command[0]); // The destination is a pocket dimension.
// Teleport the player to its original entrance (the origin).
destination = dimension.origin();
checkOrientation = true;
} }
else else
{ {
return DDCommandResult.INVALID_ARGUMENTS; // The destination is not a pocket dimension, which means we
// don't automatically know a safe location where we can send
// the player. Send the player to (0, Y, 0), where Y is chosen
// by searching. Add 2 to place the player ABOVE the top block.
y = world.getTopSolidOrLiquidBlock(0, 0) + 2;
destination = new Point4D(0, y, 0, dimensionID);
} }
dimDestinationID=Integer.parseInt(command[1]);//gets the target dim ID from the command string }
else if (command.length == 4)
if(!DimensionManager.isDimensionRegistered(dimDestinationID))
{ {
return DDCommandResult.INVALID_DIMENSION_ID; x = Integer.parseInt(command[1]);
} y = Integer.parseInt(command[2]) + 1; // Correct the Y value
z = Integer.parseInt(command[3]);
destination = new Point4D(x, y, z, dimensionID);
Point4D destination = PocketManager.getDimensionData(dimDestinationID).origin();
if(!PocketManager.getDimensionData(dimDestinationID).isPocketDimension())
{
destination = new Point4D(destination.getX(),PocketManager.loadDimension(dimDestinationID).getTopSolidOrLiquidBlock(
destination.getX(), destination.getZ()),
destination.getZ(),destination.getDimension());
}
DDTeleporter.teleportEntity(targetPlayer, destination, false);
}
else if(command.length == 1 && isInteger(command[0]))
{
targetPlayer = sender;
dimDestinationID=Integer.parseInt(command[0]);//gets the target dim ID from the command string
if(!DimensionManager.isDimensionRegistered(dimDestinationID))
{
return DDCommandResult.INVALID_DIMENSION_ID;
}
Point4D destination = PocketManager.getDimensionData(dimDestinationID).origin();
if(!PocketManager.getDimensionData(dimDestinationID).isPocketDimension())
{
destination = new Point4D(destination.getX(),PocketManager.loadDimension(dimDestinationID).getTopSolidOrLiquidBlock(
destination.getX(), destination.getZ()),
destination.getZ(),destination.getDimension());
}
DDTeleporter.teleportEntity(targetPlayer, destination, false);
} }
else else
{ {
return DDCommandResult.INVALID_ARGUMENTS; x = Integer.parseInt(command[2]);
y = Integer.parseInt(command[3]) + 1; // Correct the Y value
z = Integer.parseInt(command[4]);
destination = new Point4D(x, y, z, dimensionID);
} }
// Teleport!
DDTeleporter.teleportEntity(targetPlayer, destination, checkOrientation);
return DDCommandResult.SUCCESS; return DDCommandResult.SUCCESS;
} }
public boolean isInteger( String input ) private static boolean isInteger(String input)
{ {
try try
{ {
Integer.parseInt( input ); Integer.parseInt(input);
return true; return true;
} }
catch(Exception e ) catch(Exception e)
{ {
return false; return false;
} }
} }
} }

View File

@@ -5,7 +5,6 @@ import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender; import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatMessageComponent; import net.minecraft.util.ChatMessageComponent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
/* /*
* An abstract base class for our Dimensional Doors commands. This cleans up the code a little and provides * An abstract base class for our Dimensional Doors commands. This cleans up the code a little and provides
@@ -96,13 +95,15 @@ public abstract class DDCommandBase extends CommandBase
* that Dryware and Technic Jenkins don't have those functions defined. How in the world? * that Dryware and Technic Jenkins don't have those functions defined. How in the world?
* I have no idea. But it's breaking our builds. -_- ~SenseiKiwi * I have no idea. But it's breaking our builds. -_- ~SenseiKiwi
*/ */
public int compareTo(ICommand par1ICommand) @Override
public int compareTo(ICommand command)
{ {
return this.getCommandName().compareTo(par1ICommand.getCommandName()); return this.getCommandName().compareTo(command.getCommandName());
} }
public int compareTo(Object par1Obj) @Override
public int compareTo(Object other)
{ {
return this.compareTo((ICommand)par1Obj); return this.compareTo((ICommand) other);
} }
} }

View File

@@ -8,7 +8,8 @@ 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 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 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 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 DDCommandResult INVALID_ARGUMENTS = new DDCommandResult(5, "Error: Invalid arguments passed to the command", true);
public static final DDCommandResult PLAYER_OFFLINE = new DDCommandResult(6, "Error: Player is not online", false);
public static final int CUSTOM_ERROR_CODE = -1; public static final int CUSTOM_ERROR_CODE = -1;

View File

@@ -25,7 +25,6 @@ import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor; import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor;
import StevenDimDoors.mod_pocketDim.config.DDProperties; import StevenDimDoors.mod_pocketDim.config.DDProperties;
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor;
import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator;
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor;
import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.util.Point4D;
@@ -483,9 +482,33 @@ public class DDTeleporter
{ {
if (link.hasDestination()) if (link.hasDestination())
{ {
if(PocketManager.isBlackListed(link.destination().getDimension())) if (PocketManager.isBlackListed(link.destination().getDimension()))
{ {
link=PocketManager.getDimensionData(link.source().getDimension()).createLink(link.link.point,LinkTypes.SAFE_EXIT,link.link.orientation); // This link leads to a dimension that has been blacklisted.
// That means that it was a pocket and it was deleted.
// Depending on the link type, we must overwrite it or cancel
// the teleport operation. We don't need to assign 'link' with
// a different value. NewDimData will overwrite it in-place.
NewDimData start = PocketManager.getDimensionData(link.source().getDimension());
if (link.linkType() == LinkTypes.DUNGEON)
{
// Ovewrite the link into a dungeon link with no destination
start.createLink(link.source(), LinkTypes.DUNGEON, link.orientation());
}
else
{
if (start.isPocketDimension())
{
// Ovewrite the link into a safe exit link, because
// this could be the only way out from a pocket.
start.createLink(link.source(), LinkTypes.SAFE_EXIT, link.orientation());
}
else
{
// Cancel the teleport attempt
return false;
}
}
} }
else else
{ {
@@ -499,7 +522,7 @@ public class DDTeleporter
case LinkTypes.DUNGEON: case LinkTypes.DUNGEON:
return PocketBuilder.generateNewDungeonPocket(link, properties); return PocketBuilder.generateNewDungeonPocket(link, properties);
case LinkTypes.POCKET: case LinkTypes.POCKET:
return PocketBuilder.generateNewPocket(link, properties,door); return PocketBuilder.generateNewPocket(link, properties, door);
case LinkTypes.SAFE_EXIT: case LinkTypes.SAFE_EXIT:
return generateSafeExit(link, properties); return generateSafeExit(link, properties);
case LinkTypes.DUNGEON_EXIT: case LinkTypes.DUNGEON_EXIT:
@@ -544,11 +567,8 @@ public class DDTeleporter
{ {
return matches.get( random.nextInt(matches.size()) ); return matches.get( random.nextInt(matches.size()) );
} }
else
{
return null; return null;
} }
}
private static boolean generateUnsafeExit(DimLink link) private static boolean generateUnsafeExit(DimLink link)
{ {
@@ -749,7 +769,7 @@ public class DDTeleporter
// Set up the warp door at the destination // Set up the warp door at the destination
orientation = BlockRotator.transformMetadata(orientation, 2, properties.WarpDoorID); orientation = BlockRotator.transformMetadata(orientation, 2, properties.WarpDoorID);
ItemDimensionalDoor.placeDoorBlock(world, x, y + 1, z, orientation, mod_pocketDim.warpDoor); ItemDoor.placeDoorBlock(world, x, y + 1, z, orientation, mod_pocketDim.warpDoor);
// Complete the link to the destination // Complete the link to the destination
// This comes last so the destination isn't set unless everything else works first // This comes last so the destination isn't set unless everything else works first

View File

@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Stack;
import java.util.TreeMap; import java.util.TreeMap;
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData; import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
@@ -516,11 +517,42 @@ public abstract class NewDimData
*/ */
public void setParentToRoot() public void setParentToRoot()
{ {
// Update this dimension's information
if (parent != null)
{
parent.children.remove(this);
}
this.depth = 1; this.depth = 1;
this.parent = this.root; this.parent = this.root;
this.root.children.add(this); this.root.children.add(this);
this.root.modified = true; this.root.modified = true;
this.modified = true; this.modified = true;
if (this.isDungeon)
{
this.packDepth = calculatePackDepth(this.parent, this.dungeon);
}
// Update the depths for child dimensions using a depth-first traversal
Stack<NewDimData> ordering = new Stack<NewDimData>();
ordering.addAll(this.children);
while (!ordering.isEmpty())
{
NewDimData current = ordering.pop();
current.resetDepth();
ordering.addAll(current.children);
}
}
private void resetDepth()
{
// We assume that this is only applied to dimensions with parents
this.depth = this.parent.depth + 1;
if (this.isDungeon)
{
this.packDepth = calculatePackDepth(this.parent, this.dungeon);
}
this.modified = true;
} }
public static int calculatePackDepth(NewDimData parent, DungeonData current) public static int calculatePackDepth(NewDimData parent, DungeonData current)
@@ -549,11 +581,8 @@ public abstract class NewDimData
{ {
return parent.packDepth + 1; return parent.packDepth + 1;
} }
else
{
return 1; return 1;
} }
}
public void initializePocket(int originX, int originY, int originZ, int orientation, DimLink incoming) public void initializePocket(int originX, int originY, int originZ, int orientation, DimLink incoming)
{ {
@@ -589,11 +618,8 @@ public abstract class NewDimData
{ {
return linkList.get(random.nextInt(linkList.size())); return linkList.get(random.nextInt(linkList.size()));
} }
else
{
return linkList.get(0); return linkList.get(0);
} }
}
public boolean isModified() public boolean isModified()
{ {
@@ -605,6 +631,7 @@ public abstract class NewDimData
this.modified = false; this.modified = false;
} }
@Override
public String toString() public String toString()
{ {
return "DimID= " + this.id; return "DimID= " + this.id;

View File

@@ -315,44 +315,48 @@ public class PocketManager
{ {
if (deleteFolder) if (deleteFolder)
{ {
deleteDimensionFiles(target); deleteDimensionFiles(dimension);
} }
// Note: We INTENTIONALLY don't unregister the dimensions that we
// delete with Forge. Instead, we keep them registered to stop Forge
// from reallocating those IDs to other mods such as Mystcraft. This
// is to prevent bugs. Blacklisted dimensions are still properly
// unregistered when the server shuts down.
dimensionIDBlackList.add(dimension.id); dimensionIDBlackList.add(dimension.id);
deleteDimensionData(dimension.id); deleteDimensionData(dimension);
return true; return true;
} }
return false; return false;
} }
private static boolean deleteDimensionFiles(NewDimData target) private static void deleteDimensionFiles(InnerDimData dimension)
{
InnerDimData dimension = (InnerDimData) target;
if (dimension.isPocketDimension() && DimensionManager.getWorld(dimension.id()) == null)
{ {
// We assume that the caller checks if the dimension is loaded, for the
// sake of efficiency. Don't call this on a loaded dimension or bad
// things will happen!
String saveRootPath = DimensionManager.getCurrentSaveRootDirectory().getAbsolutePath(); String saveRootPath = DimensionManager.getCurrentSaveRootDirectory().getAbsolutePath();
File saveDirectory = new File(saveRootPath + "/DimensionalDoors/pocketDimID" + dimension.id()); File saveDirectory = new File(saveRootPath + "/DimensionalDoors/pocketDimID" + dimension.id());
DeleteFolder.deleteFolder(saveDirectory); DeleteFolder.deleteFolder(saveDirectory);
File dataFile = new File(saveRootPath + "/DimensionalDoors/data/dim_" + dimension.id() + ".txt"); File dataFile = new File(saveRootPath + "/DimensionalDoors/data/dim_" + dimension.id() + ".txt");
dataFile.delete(); dataFile.delete();
return true;
}
return false;
} }
private static boolean deleteDimensionData(int dimensionID) private static void deleteDimensionData(InnerDimData dimension)
{ {
if (dimensionData.containsKey(dimensionID) && DimensionManager.getWorld(dimensionID) == null) // We assume that the caller checks if the dimension is loaded, for the
// sake of efficiency. Don't call this on a loaded dimension or bad
// things will happen!
if (dimensionData.remove(dimension.id()) != null)
{ {
NewDimData target = PocketManager.getDimensionData(dimensionID);
InnerDimData dimension = (InnerDimData) target;
dimensionData.remove(dimensionID);
// Raise the dim deleted event // Raise the dim deleted event
getDimwatcher().onDeleted(new ClientDimData(dimension)); getDimwatcher().onDeleted(new ClientDimData(dimension));
dimension.clear(); dimension.clear();
return true;
} }
return false; else
{
// This should never happen. A simple sanity check.
throw new IllegalArgumentException("The specified dimension is not listed with PocketManager.");
}
} }
private static void registerPockets(DDProperties properties) private static void registerPockets(DDProperties properties)
@@ -479,6 +483,11 @@ public class PocketManager
public static WorldServer loadDimension(int id) public static WorldServer loadDimension(int id)
{ {
if (!DimensionManager.isDimensionRegistered(id))
{
return null;
}
WorldServer world = DimensionManager.getWorld(id); WorldServer world = DimensionManager.getWorld(id);
if (world == null) if (world == null)
{ {
@@ -647,11 +656,8 @@ public class PocketManager
{ {
return dimension.getLink(x, y, z); return dimension.getLink(x, y, z);
} }
else
{
return null; return null;
} }
}
public static boolean isBlackListed(int dimensionID) public static boolean isBlackListed(int dimensionID)
{ {
@@ -716,9 +722,6 @@ public class PocketManager
load(); load();
Compactor.readDimensions(input, new DimRegistrationCallback()); Compactor.readDimensions(input, new DimRegistrationCallback());
// Register pocket dimensions
DDProperties properties = DDProperties.instance();
isLoaded = true; isLoaded = true;
isLoading = false; isLoading = false;
isConnected = true; isConnected = true;

View File

@@ -2,31 +2,33 @@ package StevenDimDoors.mod_pocketDim.helpers;
import java.io.File; import java.io.File;
public class DeleteFolder public class DeleteFolder
{ {
public static boolean deleteFolder(File file) public static boolean deleteFolder(File directory)
{ {
try try
{ {
File[] files = file.listFiles(); File[] contents = directory.listFiles();
if (contents != null)
if(files==null)
{ {
file.delete(); for (File entry : contents)
return true;
}
for(File inFile : files)
{ {
DeleteFolder.deleteFolder(inFile); if (entry.isDirectory())
{
deleteFolder(entry);
} }
else
{
entry.delete();
}
}
}
return directory.delete();
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
return true;
} }
} }

View File

@@ -30,7 +30,6 @@ import StevenDimDoors.mod_pocketDim.blocks.WarpDoor;
import StevenDimDoors.mod_pocketDim.commands.CommandCreateDungeonRift; import StevenDimDoors.mod_pocketDim.commands.CommandCreateDungeonRift;
import StevenDimDoors.mod_pocketDim.commands.CommandCreatePocket; import StevenDimDoors.mod_pocketDim.commands.CommandCreatePocket;
import StevenDimDoors.mod_pocketDim.commands.CommandCreateRandomRift; import StevenDimDoors.mod_pocketDim.commands.CommandCreateRandomRift;
import StevenDimDoors.mod_pocketDim.commands.CommandDeleteAllLinks;
import StevenDimDoors.mod_pocketDim.commands.CommandDeleteRifts; import StevenDimDoors.mod_pocketDim.commands.CommandDeleteRifts;
import StevenDimDoors.mod_pocketDim.commands.CommandExportDungeon; import StevenDimDoors.mod_pocketDim.commands.CommandExportDungeon;
import StevenDimDoors.mod_pocketDim.commands.CommandListDungeons; import StevenDimDoors.mod_pocketDim.commands.CommandListDungeons;
@@ -350,16 +349,11 @@ public class mod_pocketDim
event.registerServerCommand( CommandCreateDungeonRift.instance() ); event.registerServerCommand( CommandCreateDungeonRift.instance() );
event.registerServerCommand( CommandListDungeons.instance() ); event.registerServerCommand( CommandListDungeons.instance() );
event.registerServerCommand( CommandCreateRandomRift.instance() ); event.registerServerCommand( CommandCreateRandomRift.instance() );
event.registerServerCommand( CommandDeleteAllLinks.instance() );
//CommandDeleteDimensionData.instance().register(event);
event.registerServerCommand( CommandDeleteRifts.instance() ); event.registerServerCommand( CommandDeleteRifts.instance() );
event.registerServerCommand( CommandExportDungeon.instance() ); event.registerServerCommand( CommandExportDungeon.instance() );
//CommandPrintDimensionData.instance().register(event);
//CommandPruneDimensions.instance().register(event);
event.registerServerCommand( CommandCreatePocket.instance() ); event.registerServerCommand( CommandCreatePocket.instance() );
event.registerServerCommand( CommandTeleportPlayer.instance() ); event.registerServerCommand( CommandTeleportPlayer.instance() );
try try
{ {
ChunkLoaderHelper.loadChunkForcedWorlds(event); ChunkLoaderHelper.loadChunkForcedWorlds(event);

View File

@@ -21,9 +21,9 @@ import StevenDimDoors.mod_pocketDim.world.PocketProvider;
public class MobMonolith extends EntityFlying implements IMob public class MobMonolith extends EntityFlying implements IMob
{ {
private static final short MAX_AGGRO = 200; private static final short MAX_AGGRO = 250;
private static final short MAX_AGGRO_CAP = 80; private static final short MAX_AGGRO_CAP = 100;
private static final short MIN_AGGRO_CAP = 20; private static final short MIN_AGGRO_CAP = 25;
private static final int MAX_TEXTURE_STATE = 18; private static final int MAX_TEXTURE_STATE = 18;
private static final int MAX_SOUND_COOLDOWN = 200; private static final int MAX_SOUND_COOLDOWN = 200;
private static final int MAX_AGGRO_RANGE = 35; private static final int MAX_AGGRO_RANGE = 35;