Rewrote CommandDeleteRifts

Rewrote CommandDeleteRifts for clarity and to remove several flaws.
Previously, the command would have removed non-immune blocks that were
in the same location as a rift. It also set blocks in the command
sender's dimension rather than the target dimension, so blocks would
have potentially disappeared from the wrong world.
This commit is contained in:
SenseiKiwi 2014-07-03 14:19:08 -04:00
parent c5a77268fc
commit 80bb87dac6

View file

@ -8,6 +8,7 @@ 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;
public class CommandDeleteRifts extends DDCommandBase public class CommandDeleteRifts extends DDCommandBase
{ {
@ -15,7 +16,7 @@ public class CommandDeleteRifts extends DDCommandBase
private CommandDeleteRifts() private CommandDeleteRifts()
{ {
super("dd-???", "???"); super("dd-deleterifts", "[dimension number]");
} }
public static CommandDeleteRifts instance() public static CommandDeleteRifts instance()
@ -29,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;
} }
} }