Merge pull request #169 from SenseiKiwi/master

Reviewed and Rewrote Commands
This commit is contained in:
StevenRS11 2014-07-05 20:59:42 -05:00
commit b40141f99d
17 changed files with 397 additions and 422 deletions

View file

@ -1,5 +1,9 @@
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.core.DimLink;
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.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
{
private static CommandCreateDungeonRift instance = null;
@ -38,10 +36,6 @@ public class CommandCreateDungeonRift extends DDCommandBase
NewDimData dimension;
DungeonHelper dungeonHelper = DungeonHelper.instance();
if (sender.worldObj.isRemote)
{
return DDCommandResult.SUCCESS;
}
if (command.length == 0)
{
return DDCommandResult.TOO_FEW_ARGUMENTS;

View file

@ -1,6 +1,5 @@
package StevenDimDoors.mod_pocketDim.commands;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
@ -24,26 +23,21 @@ public class CommandCreatePocket extends DDCommandBase
@Override
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)
{
return DDCommandResult.TOO_MANY_ARGUMENTS;
}
//Place a door leading to a pocket dimension where the player is standing.
//The pocket dimension will serve as a room for the player to build a dungeon.
int x = (int) sender.posX;
int y = (int) sender.posY;
int z = (int) sender.posZ;
DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z);
//Notify the player
sendChat(sender,("Created a door to a pocket dimension. Please build your dungeon there."));
return DDCommandResult.TOO_MANY_ARGUMENTS;
}
//Place a door leading to a pocket dimension where the player is standing.
//The pocket dimension will serve as a room for the player to build a dungeon.
int x = (int) sender.posX;
int y = (int) sender.posY;
int z = (int) sender.posZ;
DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z);
//Notify the player
sendChat(sender, "Created a door to a pocket dimension. Please build your dungeon there.");
return DDCommandResult.SUCCESS;
}
}

View file

@ -38,11 +38,7 @@ public class CommandCreateRandomRift extends DDCommandBase
{
NewDimData dimension;
DungeonHelper dungeonHelper = DungeonHelper.instance();
if (sender.worldObj.isRemote)
{
return DDCommandResult.SUCCESS;
}
if (command.length > 1)
{
return DDCommandResult.TOO_MANY_ARGUMENTS;
@ -118,9 +114,6 @@ public class CommandCreateRandomRift extends DDCommandBase
{
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 net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.util.Point4D;
@SuppressWarnings("deprecation")
public class CommandDeleteRifts extends DDCommandBase
{
private static CommandDeleteRifts instance = null;
private CommandDeleteRifts()
{
super("dd-???", "???");
super("dd-deleterifts", "[dimension number]");
}
public static CommandDeleteRifts instance()
@ -31,47 +30,64 @@ public class CommandDeleteRifts extends DDCommandBase
@Override
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{
int linksRemoved=0;
int targetDim;
boolean shouldGo= true;
int linksRemoved = 0;
int targetDimension;
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
{
targetDim=0;
shouldGo=false;
sendChat(sender,("Error-Invalid argument, delete_all_links <targetDimID>"));
try
{
targetDimension = Integer.parseInt(command[0]);
}
catch (NumberFormatException e)
{
return DDCommandResult.INVALID_DIMENSION_ID;
}
}
if(shouldGo)
World world = PocketManager.loadDimension(targetDimension);
if (world == null)
{
NewDimData dim = PocketManager.getDimensionData(targetDim);
ArrayList<DimLink> linksInDim = dim.getAllLinks();
for (DimLink link : linksInDim)
{
World targetWorld = PocketManager.loadDimension(targetDim);
if(!mod_pocketDim.blockRift.isBlockImmune(sender.worldObj,link.source().getX(), link.source().getY(), link.source().getZ())||
(targetWorld.getBlockId(link.source().getX(), link.source().getY(), link.source().getZ())==mod_pocketDim.blockRift.blockID))
{
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.
}
sendChat(sender,("Removed " + linksRemoved + " links."));
return DDCommandResult.UNREGISTERED_DIMENSION;
}
return DDCommandResult.SUCCESS; //TEMPORARY HACK
int x;
int y;
int z;
Point4D location;
NewDimData dimension = PocketManager.getDimensionData(targetDimension);
ArrayList<DimLink> links = dimension.getAllLinks();
for (DimLink link : links)
{
location = link.source();
x = location.getX();
y = location.getY();
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++;
}
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;
}
}

View file

@ -2,7 +2,6 @@ package StevenDimDoors.mod_pocketDim.commands;
import java.io.File;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import StevenDimDoors.mod_pocketDim.config.DDProperties;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
@ -60,66 +59,51 @@ public class CommandExportDungeon extends DDCommandBase
//Export the schematic
return exportDungeon(sender, command[0]);
}
else
{
//The schematic name contains illegal characters. Inform the user.
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 3-argument version and report an error.
return DDCommandResult.TOO_FEW_ARGUMENTS;
//The schematic name contains illegal characters. Inform the user.
return new DDCommandResult("Error: Invalid schematic name. Please use only letters, numbers, dashes, and underscores.");
}
//The command is malformed in some way. Assume that the user meant to use
//the 3-argument version and report an error.
return DDCommandResult.TOO_FEW_ARGUMENTS;
}
//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
//during the save file format rewrite. ~SenseiKiwi
if (!dungeonHelper.validateDungeonType(command[0], dungeonHelper.getDungeonPack("ruins")))
{
//TODO: This validation should be in DungeonHelper or in another class. We should move it
//during the save file format rewrite. ~SenseiKiwi
if (!dungeonHelper.validateDungeonType(command[0], dungeonHelper.getDungeonPack("ruins")))
{
return new DDCommandResult("Error: Invalid dungeon type. Please use one of the existing types.");
}
if (!DungeonHelper.DUNGEON_NAME_PATTERN.matcher(command[1]).matches())
{
return new DDCommandResult("Error: Invalid dungeon name. Please use only letters, numbers, and dashes.");
}
if (!command[2].equalsIgnoreCase("open") && !command[2].equalsIgnoreCase("closed"))
{
return new DDCommandResult("Error: Please specify whether the dungeon is 'open' or 'closed'.");
}
//If there are no more arguments, export the dungeon.
if (command.length == 3)
{
return exportDungeon(sender, join(command, "_", 0, 3));
}
else
{
//Validate the weight argument
try
{
int weight = Integer.parseInt(command[3]);
if (weight >= DungeonHelper.MIN_DUNGEON_WEIGHT && weight <= DungeonHelper.MAX_DUNGEON_WEIGHT)
{
return exportDungeon(sender, join(command, "_", 0, 4));
}
}
catch (Exception e) { }
}
//If we've reached this point, then we must have an invalid weight.
return new DDCommandResult("Invalid dungeon weight. Please specify a weight between "
+ DungeonHelper.MIN_DUNGEON_WEIGHT + " and " + DungeonHelper.MAX_DUNGEON_WEIGHT + ", inclusive.");
return new DDCommandResult("Error: Invalid dungeon type. Please use one of the existing types.");
}
if (!DungeonHelper.DUNGEON_NAME_PATTERN.matcher(command[1]).matches())
{
return new DDCommandResult("Error: Invalid dungeon name. Please use only letters, numbers, and dashes.");
}
if (!command[2].equalsIgnoreCase("open") && !command[2].equalsIgnoreCase("closed"))
{
return new DDCommandResult("Error: Please specify whether the dungeon is 'open' or 'closed'.");
}
return DDCommandResult.SUCCESS;
//If there are no more arguments, export the dungeon.
if (command.length == 3)
{
return exportDungeon(sender, join(command, "_", 0, 3));
}
//Validate the weight argument
try
{
int weight = Integer.parseInt(command[3]);
if (weight >= DungeonHelper.MIN_DUNGEON_WEIGHT && weight <= DungeonHelper.MAX_DUNGEON_WEIGHT)
{
return exportDungeon(sender, join(command, "_", 0, 4));
}
}
catch (Exception e) { }
//If we've reached this point, then we must have an invalid weight.
return new DDCommandResult("Invalid dungeon weight. Please specify a weight between "
+ DungeonHelper.MIN_DUNGEON_WEIGHT + " and " + DungeonHelper.MAX_DUNGEON_WEIGHT + ", inclusive.");
}
private static DDCommandResult exportDungeon(EntityPlayer player, String name)
@ -137,10 +121,7 @@ public class CommandExportDungeon extends DDCommandBase
dungeonHelper.registerDungeon(exportPath, dungeonHelper.getDungeonPack("ruins"), false, true);
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)

View file

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

View file

@ -1,16 +1,14 @@
package StevenDimDoors.mod_pocketDim.commands;
import java.util.ArrayList;
import java.util.HashSet;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.DimensionManager;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.LinkTypes;
import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
@SuppressWarnings("deprecation")
public class CommandResetDungeons extends DDCommandBase
{
private static CommandResetDungeons instance = null;
@ -31,61 +29,75 @@ public class CommandResetDungeons extends DDCommandBase
@Override
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{
if(sender.worldObj.isRemote)
{
return DDCommandResult.SUCCESS;
}
if (command.length > 0)
{
return DDCommandResult.TOO_FEW_ARGUMENTS;
return DDCommandResult.TOO_MANY_ARGUMENTS;
}
int id;
int resetCount = 0;
int dungeonCount = 0;
HashSet<Integer> deletedDimensions = new HashSet<Integer>();
ArrayList<NewDimData> loadedDungeons = new ArrayList<NewDimData>();
// 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);
}
int dungeonCount = 0;
int resetCount = 0;
ArrayList<Integer> dimsToDelete = new ArrayList<Integer>();
ArrayList<Integer> dimsToFix = new ArrayList<Integer>();
for (NewDimData data : PocketManager.getDimensions())
// 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(DimensionManager.getWorld(data.id())==null&&data.isDungeon())
if (dimension.isDungeon())
{
resetCount++;
dungeonCount++;
dimsToDelete.add(data.id());
}
else if(data.isDungeon())
{
dimsToFix.add(data.id());
dungeonCount++;
for(DimLink link : data.links())
id = dimension.id();
if (PocketManager.deletePocket(dimension, true))
{
if(link.linkType()==LinkTypes.REVERSE)
resetCount++;
deletedDimensions.add(id);
}
else
{
loadedDungeons.add(dimension);
}
}
}
// Modify the loaded dungeons to prevent bugs
for (NewDimData dungeon : loadedDungeons)
{
// 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)
{
data.createLink(link.source(), LinkTypes.DUNGEON_EXIT, link.orientation());
dungeon.createLink(link.source(), LinkTypes.DUNGEON, link.orientation());
}
if(link.linkType()==LinkTypes.DUNGEON)
else if (link.linkType() == LinkTypes.REVERSE)
{
data.createLink(link.source(), LinkTypes.DUNGEON, link.orientation());
dungeon.createLink(link.source(), LinkTypes.DUNGEON_EXIT, link.orientation());
}
}
}
}
for(Integer dimID:dimsToDelete)
{
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
// Notify the user of the results
sendChat(sender,("Reset complete. " + resetCount + " out of " + dungeonCount + " dungeons were reset."));
return DDCommandResult.SUCCESS;
}

View file

@ -1,23 +1,23 @@
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.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
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
{
private static CommandTeleportPlayer instance = null;
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()
@ -28,110 +28,120 @@ public class CommandTeleportPlayer extends DDCommandBase
return instance;
}
/**
* TODO- Change to accept variety of input, like just coords, just dim ID, or two player names.
*/
@Override
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{
EntityPlayer targetPlayer = sender;
int dimDestinationID = sender.worldObj.provider.dimensionId;
int x;
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++)
{
if(!isInteger(command[i]))
{
return DDCommandResult.INVALID_ARGUMENTS;
}
}
if(sender.worldObj.getPlayerEntityByName(command[0])!=null) //Gets the targeted player
{
targetPlayer = sender.worldObj.getPlayerEntityByName(command[0]);
}
else
{
return DDCommandResult.INVALID_ARGUMENTS;
}
dimDestinationID=Integer.parseInt(command[1]);//gets the target dim ID from the command string
if(!DimensionManager.isDimensionRegistered(dimDestinationID))
{
return DDCommandResult.INVALID_DIMENSION_ID;
}
PocketManager.loadDimension(dimDestinationID);
Point4D destination = new Point4D(Integer.parseInt(command[2]),Integer.parseInt(command[3]),Integer.parseInt(command[4]),dimDestinationID);
DDTeleporter.teleportEntity(targetPlayer, destination, false);
return DDCommandResult.TOO_FEW_ARGUMENTS;
}
else if(command.length == 2 && isInteger(command[1]))
if (command.length > 5)
{
if(sender.worldObj.getPlayerEntityByName(command[0])!=null) //Gets the targeted player
{
targetPlayer = sender.worldObj.getPlayerEntityByName(command[0]);
}
else
{
return DDCommandResult.INVALID_ARGUMENTS;
}
dimDestinationID=Integer.parseInt(command[1]);//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);
return DDCommandResult.TOO_MANY_ARGUMENTS;
}
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
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;
}
}
// Check if the target player is logged in
targetPlayer = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(command[0]);
if (targetPlayer == null)
{
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
{
dimensionID = targetPlayer.worldObj.provider.dimensionId;
// SenseiKiwi: Will not be used, but I prefer not to leave 'world' as null
world = targetPlayer.worldObj;
}
// If we teleport to a pocket dimension, set checkOrientation to true
// so the player is placed correctly relative to the entrance door.
checkOrientation = false;
// 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)
{
// Check if the destination is a pocket dimension
dimension = PocketManager.getDimensionData(dimensionID);
if (dimension.isPocketDimension())
{
// The destination is a pocket dimension.
// Teleport the player to its original entrance (the origin).
destination = dimension.origin();
checkOrientation = true;
}
else
{
// 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);
}
}
else if (command.length == 4)
{
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);
}
else
{
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;
}
public boolean isInteger( String input )
{
try
{
Integer.parseInt( input );
return true;
}
catch(Exception e )
{
return false;
}
}
private static boolean isInteger(String input)
{
try
{
Integer.parseInt(input);
return true;
}
catch(Exception e)
{
return false;
}
}
}

View file

@ -5,7 +5,6 @@ import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
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
@ -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?
* 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 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 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;

View file

@ -25,7 +25,6 @@ import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor;
import StevenDimDoors.mod_pocketDim.config.DDProperties;
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor;
import StevenDimDoors.mod_pocketDim.schematic.BlockRotator;
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor;
import StevenDimDoors.mod_pocketDim.util.Point4D;
@ -483,9 +482,33 @@ public class DDTeleporter
{
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
{
@ -499,7 +522,7 @@ public class DDTeleporter
case LinkTypes.DUNGEON:
return PocketBuilder.generateNewDungeonPocket(link, properties);
case LinkTypes.POCKET:
return PocketBuilder.generateNewPocket(link, properties,door);
return PocketBuilder.generateNewPocket(link, properties, door);
case LinkTypes.SAFE_EXIT:
return generateSafeExit(link, properties);
case LinkTypes.DUNGEON_EXIT:
@ -544,10 +567,7 @@ public class DDTeleporter
{
return matches.get( random.nextInt(matches.size()) );
}
else
{
return null;
}
return null;
}
private static boolean generateUnsafeExit(DimLink link)
@ -749,7 +769,7 @@ public class DDTeleporter
// Set up the warp door at the destination
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
// 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.Map;
import java.util.Random;
import java.util.Stack;
import java.util.TreeMap;
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
@ -516,11 +517,42 @@ public abstract class NewDimData
*/
public void setParentToRoot()
{
// Update this dimension's information
if (parent != null)
{
parent.children.remove(this);
}
this.depth = 1;
this.parent = this.root;
this.root.children.add(this);
this.root.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)
@ -549,10 +581,7 @@ public abstract class NewDimData
{
return parent.packDepth + 1;
}
else
{
return 1;
}
return 1;
}
public void initializePocket(int originX, int originY, int originZ, int orientation, DimLink incoming)
@ -589,10 +618,7 @@ public abstract class NewDimData
{
return linkList.get(random.nextInt(linkList.size()));
}
else
{
return linkList.get(0);
}
return linkList.get(0);
}
public boolean isModified()
@ -605,6 +631,7 @@ public abstract class NewDimData
this.modified = false;
}
@Override
public String toString()
{
return "DimID= " + this.id;

View file

@ -315,44 +315,48 @@ public class PocketManager
{
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);
deleteDimensionData(dimension.id);
deleteDimensionData(dimension);
return true;
}
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)
{
String saveRootPath = DimensionManager.getCurrentSaveRootDirectory().getAbsolutePath();
File saveDirectory = new File(saveRootPath + "/DimensionalDoors/pocketDimID" + dimension.id());
DeleteFolder.deleteFolder(saveDirectory);
File dataFile = new File(saveRootPath + "/DimensionalDoors/data/dim_" + dimension.id() + ".txt");
dataFile.delete();
return true;
}
return false;
// 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();
File saveDirectory = new File(saveRootPath + "/DimensionalDoors/pocketDimID" + dimension.id());
DeleteFolder.deleteFolder(saveDirectory);
File dataFile = new File(saveRootPath + "/DimensionalDoors/data/dim_" + dimension.id() + ".txt");
dataFile.delete();
}
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
getDimwatcher().onDeleted(new ClientDimData(dimension));
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)
@ -479,6 +483,11 @@ public class PocketManager
public static WorldServer loadDimension(int id)
{
if (!DimensionManager.isDimensionRegistered(id))
{
return null;
}
WorldServer world = DimensionManager.getWorld(id);
if (world == null)
{
@ -647,10 +656,7 @@ public class PocketManager
{
return dimension.getLink(x, y, z);
}
else
{
return null;
}
return null;
}
public static boolean isBlackListed(int dimensionID)
@ -715,9 +721,6 @@ public class PocketManager
// Load compacted client-side dimension data
load();
Compactor.readDimensions(input, new DimRegistrationCallback());
// Register pocket dimensions
DDProperties properties = DDProperties.instance();
isLoaded = true;
isLoading = false;

View file

@ -2,31 +2,33 @@ package StevenDimDoors.mod_pocketDim.helpers;
import java.io.File;
public class DeleteFolder
{
public static boolean deleteFolder(File file)
public static boolean deleteFolder(File directory)
{
try
{
File[] files = file.listFiles();
if(files==null)
File[] contents = directory.listFiles();
if (contents != null)
{
file.delete();
return true;
for (File entry : contents)
{
if (entry.isDirectory())
{
deleteFolder(entry);
}
else
{
entry.delete();
}
}
}
for(File inFile : files)
{
DeleteFolder.deleteFolder(inFile);
}
return directory.delete();
}
catch (Exception e)
{
e.printStackTrace();
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.CommandCreatePocket;
import StevenDimDoors.mod_pocketDim.commands.CommandCreateRandomRift;
import StevenDimDoors.mod_pocketDim.commands.CommandDeleteAllLinks;
import StevenDimDoors.mod_pocketDim.commands.CommandDeleteRifts;
import StevenDimDoors.mod_pocketDim.commands.CommandExportDungeon;
import StevenDimDoors.mod_pocketDim.commands.CommandListDungeons;
@ -350,16 +349,11 @@ public class mod_pocketDim
event.registerServerCommand( CommandCreateDungeonRift.instance() );
event.registerServerCommand( CommandListDungeons.instance() );
event.registerServerCommand( CommandCreateRandomRift.instance() );
event.registerServerCommand( CommandDeleteAllLinks.instance() );
//CommandDeleteDimensionData.instance().register(event);
event.registerServerCommand( CommandDeleteRifts.instance() );
event.registerServerCommand( CommandExportDungeon.instance() );
//CommandPrintDimensionData.instance().register(event);
//CommandPruneDimensions.instance().register(event);
event.registerServerCommand( CommandCreatePocket.instance() );
event.registerServerCommand( CommandTeleportPlayer.instance() );
try
{
ChunkLoaderHelper.loadChunkForcedWorlds(event);

View file

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