Working on dungeon deletion
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
package StevenDimDoors.mod_pocketDim.commands;
|
package StevenDimDoors.mod_pocketDim.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
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.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;
|
||||||
|
|
||||||
@@ -10,7 +15,7 @@ public class CommandResetDungeons extends DDCommandBase
|
|||||||
|
|
||||||
private CommandResetDungeons()
|
private CommandResetDungeons()
|
||||||
{
|
{
|
||||||
super("dd-rebuilddungeons", "");
|
super("dd-resetdungeons", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CommandResetDungeons instance()
|
public static CommandResetDungeons instance()
|
||||||
@@ -31,21 +36,39 @@ public class CommandResetDungeons extends DDCommandBase
|
|||||||
|
|
||||||
int dungeonCount = 0;
|
int dungeonCount = 0;
|
||||||
int resetCount = 0;
|
int resetCount = 0;
|
||||||
|
ArrayList<Integer> dimIdsToDelete= new ArrayList<Integer>();
|
||||||
|
|
||||||
for (NewDimData data : PocketManager.getDimensions())
|
for (NewDimData data : PocketManager.getDimensions())
|
||||||
|
{
|
||||||
|
dungeonCount++;
|
||||||
|
if(DimensionManager.getWorld(data.id())==null)
|
||||||
{
|
{
|
||||||
if (data.isDungeon())
|
if (data.isDungeon())
|
||||||
{
|
{
|
||||||
dungeonCount++;
|
PocketManager.deleteDimensionFolder(data);
|
||||||
if (PocketManager.resetDungeon(data))
|
dimIdsToDelete.add(data.id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
resetCount++;
|
for(DimLink link : data.links())
|
||||||
|
{
|
||||||
|
if(link.linkType()==LinkTypes.REVERSE)
|
||||||
|
{
|
||||||
|
data.createLink(link.source(), LinkTypes.DUNGEON_EXIT, link.orientation());
|
||||||
|
}
|
||||||
|
if(link.linkType()==LinkTypes.DUNGEON)
|
||||||
|
{
|
||||||
|
data.createLink(link.source(), LinkTypes.DUNGEON, link.orientation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
resetCount = PocketManager.deleteDimensionData(dimIdsToDelete);
|
||||||
|
//TODO implement blackList
|
||||||
|
|
||||||
//Notify the user of the results
|
//Notify the user of the results
|
||||||
sender.sendChatToPlayer("Reset complete. " + resetCount + " out of " + dungeonCount + " dungeons were rebuilt.");
|
sender.sendChatToPlayer("Reset complete. " + resetCount + " out of " + dungeonCount + " dungeons were reset.");
|
||||||
return DDCommandResult.SUCCESS;
|
return DDCommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -470,26 +470,11 @@ public class DDTeleporter
|
|||||||
|
|
||||||
private static boolean initializeDestination(DimLink link, DDProperties properties, Block door)
|
private static boolean initializeDestination(DimLink link, DDProperties properties, Block door)
|
||||||
{
|
{
|
||||||
|
//TODO implement blackList
|
||||||
|
|
||||||
if (link.hasDestination())
|
if (link.hasDestination())
|
||||||
{
|
{
|
||||||
//Need to check if the destination is a dungeon, not only the link because non-dungeon links could still link to a dungeon at this point.
|
|
||||||
if(PocketManager.getDimensionData(link.destination().getDimension()).isDungeon)
|
|
||||||
{
|
|
||||||
NewDimData dimData = PocketManager.getDimensionData(link.destination().getDimension());
|
|
||||||
if(!dimData.isFilled())
|
|
||||||
{
|
|
||||||
if(!PocketBuilder.regenerateDungeonPocket(dimData, link, properties))
|
|
||||||
{
|
|
||||||
//If we fail to regenerate, send the player to the parent dimension.
|
|
||||||
return generateSafeExit(link, properties);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the destination type and respond accordingly
|
// Check the destination type and respond accordingly
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public abstract class NewDimData
|
|||||||
tail = new LinkTail(0, null);
|
tail = new LinkTail(0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean overwrite(InnerDimLink nextParent)
|
public boolean overwrite(InnerDimLink nextParent,int orientation)
|
||||||
{
|
{
|
||||||
if (nextParent == null)
|
if (nextParent == null)
|
||||||
{
|
{
|
||||||
@@ -86,10 +86,11 @@ public abstract class NewDimData
|
|||||||
parent = nextParent;
|
parent = nextParent;
|
||||||
tail = nextParent.tail;
|
tail = nextParent.tail;
|
||||||
nextParent.children.add(this);
|
nextParent.children.add(this);
|
||||||
|
this.orientation=orientation;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void overwrite(int linkType)
|
public void overwrite(int linkType, int orientation)
|
||||||
{
|
{
|
||||||
//Release children
|
//Release children
|
||||||
for (DimLink child : children)
|
for (DimLink child : children)
|
||||||
@@ -107,6 +108,8 @@ public abstract class NewDimData
|
|||||||
//Attach to new parent
|
//Attach to new parent
|
||||||
parent = null;
|
parent = null;
|
||||||
tail = new LinkTail(linkType, null);
|
tail = new LinkTail(linkType, null);
|
||||||
|
//Set new orientation
|
||||||
|
this.orientation=orientation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +264,7 @@ public abstract class NewDimData
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
link.overwrite(linkType);
|
link.overwrite(linkType,orientation);
|
||||||
}
|
}
|
||||||
//Link created!
|
//Link created!
|
||||||
linkWatcher.onCreated(link.source);
|
linkWatcher.onCreated(link.source);
|
||||||
@@ -295,7 +298,7 @@ public abstract class NewDimData
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (link.overwrite(parent))
|
if (link.overwrite(parent, parent.orientation))
|
||||||
{
|
{
|
||||||
//Link created!
|
//Link created!
|
||||||
linkWatcher.onCreated(link.source);
|
linkWatcher.onCreated(link.source);
|
||||||
|
|||||||
@@ -185,25 +185,6 @@ public class PocketManager
|
|||||||
isLoaded = true;
|
isLoaded = true;
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean resetDungeon(NewDimData target)
|
|
||||||
{
|
|
||||||
// We can't reset the dimension if it's currently loaded or if it's not a dungeon.
|
|
||||||
// We cast to InnerDimData so that if anyone tries to be a smartass and create their
|
|
||||||
// own version of NewDimData, this will throw an exception.
|
|
||||||
InnerDimData dimension = (InnerDimData) target;
|
|
||||||
if (dimension.isDungeon() && DimensionManager.getWorld(dimension.id()) == null)
|
|
||||||
{
|
|
||||||
File saveDirectory = new File(DimensionManager.getCurrentSaveRootDirectory() + "/DimensionalDoors/pocketDimID" + dimension.id());
|
|
||||||
if (DeleteFolder.deleteFolder(saveDirectory))
|
|
||||||
{
|
|
||||||
dimension.setFilled(false);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean deletePocket(NewDimData target, boolean deleteFolder)
|
public static boolean deletePocket(NewDimData target, boolean deleteFolder)
|
||||||
{
|
{
|
||||||
// We can't delete the dimension if it's currently loaded or if it's not actually a pocket.
|
// We can't delete the dimension if it's currently loaded or if it's not actually a pocket.
|
||||||
@@ -213,11 +194,33 @@ public class PocketManager
|
|||||||
if (dimension.isPocketDimension() && DimensionManager.getWorld(dimension.id()) == null)
|
if (dimension.isPocketDimension() && DimensionManager.getWorld(dimension.id()) == null)
|
||||||
{
|
{
|
||||||
if (deleteFolder)
|
if (deleteFolder)
|
||||||
|
{
|
||||||
|
deleteDimensionFolder(target);
|
||||||
|
}
|
||||||
|
deleteDimensionData(dimension.id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public static boolean deleteDimensionFolder(NewDimData target)
|
||||||
|
{
|
||||||
|
InnerDimData dimension = (InnerDimData) target;
|
||||||
|
if (dimension.isPocketDimension() && DimensionManager.getWorld(dimension.id()) == null)
|
||||||
{
|
{
|
||||||
File saveDirectory = new File(DimensionManager.getCurrentSaveRootDirectory() + "/DimensionalDoors/pocketDimID" + dimension.id());
|
File saveDirectory = new File(DimensionManager.getCurrentSaveRootDirectory() + "/DimensionalDoors/pocketDimID" + dimension.id());
|
||||||
DeleteFolder.deleteFolder(saveDirectory);
|
DeleteFolder.deleteFolder(saveDirectory);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
dimensionData.remove(dimension.id());
|
return false;
|
||||||
|
}
|
||||||
|
public static boolean deleteDimensionData(int dimensionID)
|
||||||
|
{
|
||||||
|
if(dimensionData.containsKey(dimensionID)&& DimensionManager.getWorld(dimensionID) == null)
|
||||||
|
{
|
||||||
|
NewDimData target = PocketManager.getDimensionData(dimensionID);
|
||||||
|
InnerDimData dimension = (InnerDimData) target;
|
||||||
|
|
||||||
|
dimensionData.remove(dimensionID);
|
||||||
// Raise the dim deleted event
|
// Raise the dim deleted event
|
||||||
dimWatcher.onDeleted(new ClientDimData(dimension));
|
dimWatcher.onDeleted(new ClientDimData(dimension));
|
||||||
dimension.clear();
|
dimension.clear();
|
||||||
@@ -226,6 +229,18 @@ public class PocketManager
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int deleteDimensionData(ArrayList<Integer> dimensions)
|
||||||
|
{
|
||||||
|
int deletedCount=0;
|
||||||
|
for(int dimID : dimensions)
|
||||||
|
{
|
||||||
|
if(deleteDimensionData(dimID))
|
||||||
|
{
|
||||||
|
deletedCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deletedCount;
|
||||||
|
}
|
||||||
private static void registerPockets(DDProperties properties)
|
private static void registerPockets(DDProperties properties)
|
||||||
{
|
{
|
||||||
for (NewDimData dimension : dimensionData.values())
|
for (NewDimData dimension : dimensionData.values())
|
||||||
|
|||||||
Reference in New Issue
Block a user