Reviewed and Rewrote Commands #169
@@ -1,9 +1,10 @@
|
||||
package StevenDimDoors.mod_pocketDim.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Stack;
|
||||
|
||||
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;
|
||||
@@ -31,55 +32,73 @@ public class CommandResetDungeons extends DDCommandBase
|
||||
{
|
||||
if (command.length > 0)
|
||||
{
|
||||
return DDCommandResult.TOO_FEW_ARGUMENTS;
|
||||
return DDCommandResult.TOO_MANY_ARGUMENTS;
|
||||
}
|
||||
|
||||
int dungeonCount = 0;
|
||||
int id;
|
||||
int resetCount = 0;
|
||||
ArrayList<Integer> dimsToDelete = new ArrayList<Integer>();
|
||||
ArrayList<Integer> dimsToFix = new ArrayList<Integer>();
|
||||
int dungeonCount = 0;
|
||||
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++;
|
||||
dungeonCount++;
|
||||
dimsToDelete.add(data.id());
|
||||
deletedDimensions.add(id);
|
||||
}
|
||||
else if(data.isDungeon())
|
||||
else
|
||||
{
|
||||
dimsToFix.add(data.id());
|
||||
dungeonCount++;
|
||||
for(DimLink link : data.links())
|
||||
{
|
||||
if(link.linkType()==LinkTypes.REVERSE)
|
||||
{
|
||||
data.createLink(link.source(), LinkTypes.DUNGEON_EXIT, link.orientation());
|
||||
loadedDungeons.add(dimension);
|
||||
}
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user