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.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.util.Point4D;
public class CommandDeleteRifts extends DDCommandBase
{
@ -15,7 +16,7 @@ public class CommandDeleteRifts extends DDCommandBase
private CommandDeleteRifts()
{
super("dd-???", "???");
super("dd-deleterifts", "[dimension number]");
}
public static CommandDeleteRifts instance()
@ -29,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;
}
}