Merge pull request #32 from SenseiKiwi/master

Fixed Rotation in Schematic Loader and Partially Overhauled Commands
This commit is contained in:
StevenRS11 2013-06-25 21:51:57 -07:00
commit 4c68f25838
18 changed files with 651 additions and 418 deletions

View file

@ -16,37 +16,37 @@ public class DimData implements Serializable
public int dimID; public int dimID;
public int depth; public int depth;
public int dimOrientation; public int dimOrientation;
public World world; public World world;
public LinkData exitDimLink; public LinkData exitDimLink;
public boolean isPocket; public boolean isPocket;
public boolean hasBeenFilled=false; public boolean hasBeenFilled=false;
public boolean hasDoor=false; public boolean hasDoor=false;
public boolean isDimRandomRift=false; public boolean isDimRandomRift=false;
public DungeonGenerator dungeonGenerator = null; public DungeonGenerator dungeonGenerator = null;
//public boolean isPrivatePocket = false; //public boolean isPrivatePocket = false;
public HashMap<Integer, HashMap<Integer, HashMap<Integer, LinkData>>> linksInThisDim=new HashMap(); public HashMap<Integer, HashMap<Integer, HashMap<Integer, LinkData>>> linksInThisDim = new HashMap();
HashMap<Integer, LinkData> dimX; HashMap<Integer, LinkData> dimX;
HashMap<Integer, HashMap<Integer, LinkData>> dimY ; HashMap<Integer, HashMap<Integer, LinkData>> dimY ;
static final long serialVersionUID = 454342L; static final long serialVersionUID = 454342L;
public DimData(int dimID, boolean isPocket, int depth, LinkData exitLinkData) public DimData(int dimID, boolean isPocket, int depth, LinkData exitLinkData)
{ {
this.dimID=dimID; this.dimID=dimID;
this.depth=depth; this.depth=depth;
this.isPocket=isPocket; this.isPocket=isPocket;
this.exitDimLink= exitLinkData; this.exitDimLink= exitLinkData;
} }
public DimData(int dimID, boolean isPocket, int depth, int exitLinkDimID, int exitX, int exitY, int exitZ) public DimData(int dimID, boolean isPocket, int depth, int exitLinkDimID, int exitX, int exitY, int exitZ)
{ {
this(dimID, isPocket, depth, new LinkData(exitLinkDimID, exitX, exitY, exitZ)); this(dimID, isPocket, depth, new LinkData(exitLinkDimID, exitX, exitY, exitZ));
} }
public LinkData findNearestRift(World world, int range, int x, int y, int z) public LinkData findNearestRift(World world, int range, int x, int y, int z)
{ {
LinkData nearest=null; LinkData nearest=null;
@ -55,7 +55,7 @@ public class DimData implements Serializable
int j=-range; int j=-range;
int k=-range; int k=-range;
DDProperties properties = DDProperties.instance(); DDProperties properties = DDProperties.instance();
while (i<range) while (i<range)
{ {
while (j<range) while (j<range)
@ -69,24 +69,24 @@ public class DimData implements Serializable
nearest=this.findLinkAtCoords(x+i, y+j, z+k); nearest=this.findLinkAtCoords(x+i, y+j, z+k);
distance=MathHelper.abs(i)+MathHelper.abs(j)+MathHelper.abs(k); distance=MathHelper.abs(i)+MathHelper.abs(j)+MathHelper.abs(k);
} }
} }
k++; k++;
} }
k=-range; k=-range;
j++; j++;
} }
j=-range; j=-range;
i++; i++;
} }
return nearest; return nearest;
} }
public ArrayList findRiftsInRange(World world, int range, int x, int y, int z) public ArrayList findRiftsInRange(World world, int range, int x, int y, int z)
{ {
LinkData nearest=null; LinkData nearest=null;
@ -95,7 +95,7 @@ public class DimData implements Serializable
int j=-range; int j=-range;
int k=-range; int k=-range;
DDProperties properties = DDProperties.instance(); DDProperties properties = DDProperties.instance();
while (i<range) while (i<range)
{ {
while (j<range) while (j<range)
@ -112,32 +112,32 @@ public class DimData implements Serializable
rifts.add(nearest); rifts.add(nearest);
} }
} }
} }
k++; k++;
} }
k=-range; k=-range;
j++; j++;
} }
j=-range; j=-range;
i++; i++;
} }
return rifts; return rifts;
} }
public LinkData addLinkToDim(LinkData link) public LinkData addLinkToDim(LinkData link)
{ {
if(this.linksInThisDim.containsKey(link.locZCoord)) if(this.linksInThisDim.containsKey(link.locZCoord))
{ {
this.dimY=this.linksInThisDim.get(link.locZCoord); this.dimY=this.linksInThisDim.get(link.locZCoord);
if(this.dimY.containsKey(link.locYCoord)) if(this.dimY.containsKey(link.locYCoord))
{ {
this.dimX=this.dimY.get(link.locYCoord); this.dimX=this.dimY.get(link.locYCoord);
@ -152,39 +152,39 @@ public class DimData implements Serializable
this.dimX=new HashMap<Integer, LinkData>(); this.dimX=new HashMap<Integer, LinkData>();
this.dimY=new HashMap<Integer, HashMap<Integer, LinkData>>(); this.dimY=new HashMap<Integer, HashMap<Integer, LinkData>>();
} }
this.dimX.put(link.locXCoord, link); this.dimX.put(link.locXCoord, link);
this.dimY.put(link.locYCoord, dimX); this.dimY.put(link.locYCoord, dimX);
this.linksInThisDim.put(link.locZCoord, dimY); this.linksInThisDim.put(link.locZCoord, dimY);
//System.out.println("added link to dim "+this.dimID); //System.out.println("added link to dim "+this.dimID);
return link; return link;
} }
public LinkData addLinkToDim( int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord, int linkOrientation) public LinkData addLinkToDim( int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord, int linkOrientation)
{ {
LinkData linkData= new LinkData(this.dimID, destinationDimID, locationXCoord, locationYCoord, locationZCoord, destinationXCoord, destinationYCoord,destinationZCoord,this.isPocket,linkOrientation); LinkData linkData= new LinkData(this.dimID, destinationDimID, locationXCoord, locationYCoord, locationZCoord, destinationXCoord, destinationYCoord,destinationZCoord,this.isPocket,linkOrientation);
return this.addLinkToDim(linkData); return this.addLinkToDim(linkData);
} }
public boolean isLimbo() public boolean isLimbo()
{ {
return (this.dimID == DDProperties.instance().LimboDimensionID); return (this.dimID == DDProperties.instance().LimboDimensionID);
} }
public void removeLinkAtCoords(LinkData link) public void removeLinkAtCoords(LinkData link)
{ {
this.removeLinkAtCoords(link.locDimID, link.locXCoord, link.locYCoord, link.locZCoord); this.removeLinkAtCoords(link.locDimID, link.locXCoord, link.locYCoord, link.locZCoord);
} }
public void removeLinkAtCoords(int locationID, int locationXCoord, int locationYCoord, int locationZCoord) public void removeLinkAtCoords(int locationID, int locationXCoord, int locationYCoord, int locationZCoord)
{ {
if (this.linksInThisDim.containsKey(locationZCoord)) if (this.linksInThisDim.containsKey(locationZCoord))
{ {
this.dimY=this.linksInThisDim.get(locationZCoord); this.dimY=this.linksInThisDim.get(locationZCoord);
if(this.dimY.containsKey(locationYCoord)) if(this.dimY.containsKey(locationYCoord))
{ {
this.dimX=this.dimY.get(locationYCoord); this.dimX=this.dimY.get(locationYCoord);
@ -199,80 +199,59 @@ public class DimData implements Serializable
this.dimX=new HashMap<Integer, LinkData>(); this.dimX=new HashMap<Integer, LinkData>();
this.dimY=new HashMap<Integer, HashMap<Integer, LinkData>>(); this.dimY=new HashMap<Integer, HashMap<Integer, LinkData>>();
} }
this.dimX.remove(locationXCoord); this.dimX.remove(locationXCoord);
this.dimY.put(locationYCoord, dimX); this.dimY.put(locationYCoord, dimX);
this.linksInThisDim.put(locationZCoord, dimY); this.linksInThisDim.put(locationZCoord, dimY);
} }
public LinkData findLinkAtCoords(int locationXCoord, int locationYCoord, int locationZCoord) public LinkData findLinkAtCoords(int locationXCoord, int locationYCoord, int locationZCoord)
{ {
try try
{ {
if(this.linksInThisDim.containsKey(locationZCoord)) if(this.linksInThisDim.containsKey(locationZCoord))
{
this.dimY=this.linksInThisDim.get(locationZCoord);
if(this.dimY.containsKey(locationYCoord))
{ {
this.dimX=this.dimY.get(locationYCoord); this.dimY=this.linksInThisDim.get(locationZCoord);
if(this.dimX.containsKey(locationXCoord)) if(this.dimY.containsKey(locationYCoord))
{ {
return this.dimX.get(locationXCoord); this.dimX=this.dimY.get(locationYCoord);
if(this.dimX.containsKey(locationXCoord))
{
return this.dimX.get(locationXCoord);
}
} }
} }
} }
}
catch(Exception E) catch(Exception E)
{ {
return null; return null;
} }
return null;
return null;
} }
public ArrayList<LinkData> printAllLinkData() public ArrayList<LinkData> printAllLinkData()
{ {
ArrayList links = new ArrayList(); //TODO: We might want to modify this function, but I'm afraid of breaking something right now.
if(this.linksInThisDim==null) //To begin with, the name is wrong. This doesn't print anything! >_o ~SenseiKiwi
ArrayList<LinkData> links = new ArrayList<LinkData>();
if (this.linksInThisDim == null)
{ {
return links; return links;
} }
for(HashMap<Integer, HashMap<Integer, LinkData>> first : this.linksInThisDim.values()) for (HashMap<Integer, HashMap<Integer, LinkData>> first : this.linksInThisDim.values())
{ {
for (HashMap<Integer, LinkData> second : first.values())
for(HashMap<Integer, LinkData> second : first.values())
{ {
for (LinkData linkData : second.values())
for(LinkData linkData :second.values())
{ {
links.add(linkData); links.add(linkData);
} }
} }
} }
return links; return links;
} }
} }

View file

@ -15,10 +15,7 @@ public class LinkData implements Serializable
public int numberofChildren; public int numberofChildren;
public boolean isLocPocket; public boolean isLocPocket;
public int linkOrientation; public int linkOrientation;
public int destDimID; public int destDimID;
public int locDimID; public int locDimID;
@ -43,8 +40,7 @@ public class LinkData implements Serializable
public LinkData(int locationDimID, int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord, boolean isPocket,int orientation) public LinkData(int locationDimID, int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord, boolean isPocket,int orientation)
{ {
this.exists = true;
this.exists=true;
this.locXCoord=locationXCoord; this.locXCoord=locationXCoord;
this.locYCoord=locationYCoord; this.locYCoord=locationYCoord;
this.locZCoord=locationZCoord; this.locZCoord=locationZCoord;
@ -57,20 +53,16 @@ public class LinkData implements Serializable
this.locDimID=locationDimID; this.locDimID=locationDimID;
this.isLocPocket=isPocket; this.isLocPocket=isPocket;
this.linkOrientation=orientation; this.linkOrientation=orientation;
} }
public String printLinkData() public String printLinkData()
{ {
//TODO: Rewrite this to make it prettier. @_@ I'm afraid of changing it to ToString() on the off
//chance it'll cause explosions and sadness. Damn serialization! ~SenseiKiwi
String linkInfo; String linkInfo;
linkInfo=String.valueOf(this.locDimID)+"locDimID "+String.valueOf(this.locXCoord)+":locXCoord "+String.valueOf(this.locYCoord)+":locYCoord "+String.valueOf(this.locZCoord)+":locZCoord "; linkInfo = String.valueOf(this.locDimID) + "locDimID "+String.valueOf(this.locXCoord)+":locXCoord "+String.valueOf(this.locYCoord)+":locYCoord "+String.valueOf(this.locZCoord)+":locZCoord ";
linkInfo.concat("\n"+ String.valueOf(this.destDimID)+"DestDimID "+String.valueOf(this.destXCoord)+":destXCoord "+String.valueOf(this.destYCoord)+":destYCoord "+String.valueOf(this.destZCoord)+":destZCoord "); linkInfo.concat("\n"+ String.valueOf(this.destDimID)+"DestDimID "+String.valueOf(this.destXCoord)+":destXCoord "+String.valueOf(this.destYCoord)+":destYCoord "+String.valueOf(this.destZCoord)+":destZCoord ");
return linkInfo; return linkInfo;
} }
} }

View file

@ -37,15 +37,15 @@ public class SchematicLoader
private Random rand = new Random(); private Random rand = new Random();
public HashMap<Integer,HashMap<Integer, HashMap<Integer,Integer>>> rotationMap = new HashMap<Integer,HashMap<Integer, HashMap<Integer,Integer>>>(); public HashMap<Integer,HashMap<Integer, HashMap<Integer,Integer>>> rotationMap = new HashMap<Integer,HashMap<Integer, HashMap<Integer,Integer>>>();
public int transMeta; public int transMeta;
private DDProperties properties = DDProperties.instance(); private DDProperties properties = DDProperties.instance();
public SchematicLoader() { } public SchematicLoader() { }
public int transformMetadata(int metadata, int orientation, int blockID) public int transformMetadata(int metadata, int orientation, int blockID)
@ -733,17 +733,17 @@ public class SchematicLoader
public void generateSchematic(int incX, int incY, int incZ, int orientation, int destDimID, int originDimID, String schematicPath) public void generateSchematic(int incX, int incY, int incZ, int orientation, int destDimID, int originDimID, String schematicPath)
{ {
short width=0; short width=0;
short height=0; short height=0;
short length=0; short length=0;
//list of combined blockIds //list of combined blockIds
short[] blocks = new short[0]; short[] blocks = new short[0];
//block metaData //block metaData
byte[] blockData = new byte[0]; byte[] blockData = new byte[0];
//first 4 bytes of the block ID //first 4 bytes of the block ID
byte[] blockId = new byte[0]; byte[] blockId = new byte[0];
@ -756,19 +756,19 @@ public class SchematicLoader
NBTTagList entities; NBTTagList entities;
NBTTagList tileEntities=null; NBTTagList tileEntities=null;
//the wooden door leading into the pocket //the wooden door leading into the pocket
Point3D incomingLink= new Point3D(0,0,0); Point3D incomingLink= new Point3D(0,0,0);
//the iron dim doors leading to more pockets //the iron dim doors leading to more pockets
ArrayList<Point3D> sideLinks = new ArrayList<Point3D>(); ArrayList<Point3D> sideLinks = new ArrayList<Point3D>();
//the wooden dim doors leading to the surface //the wooden dim doors leading to the surface
ArrayList<Point3D> exitLinks = new ArrayList<Point3D>(); ArrayList<Point3D> exitLinks = new ArrayList<Point3D>();
//the locations to spawn monoliths //the locations to spawn monoliths
ArrayList<Point3D> monolithSpawns = new ArrayList<Point3D>(); ArrayList<Point3D> monolithSpawns = new ArrayList<Point3D>();
//load the schematic from disk //load the schematic from disk
try try
{ {
@ -793,7 +793,7 @@ public class SchematicLoader
width = nbtdata.getShort("Width"); width = nbtdata.getShort("Width");
height = nbtdata.getShort("Height"); height = nbtdata.getShort("Height");
length = nbtdata.getShort("Length"); length = nbtdata.getShort("Length");
//load block info //load block info
blockId = nbtdata.getByteArray("Blocks"); blockId = nbtdata.getByteArray("Blocks");
blockData = nbtdata.getByteArray("Data"); blockData = nbtdata.getByteArray("Data");
@ -814,7 +814,7 @@ public class SchematicLoader
entities = nbtdata.getTagList("Entities"); entities = nbtdata.getTagList("Entities");
tileentities = nbtdata.getTagList("TileEntities"); tileentities = nbtdata.getTagList("TileEntities");
**/ **/
input.close(); input.close();
//combine the split block IDs into a single short[] //combine the split block IDs into a single short[]
@ -871,16 +871,16 @@ public class SchematicLoader
{ {
for ( z = 0; z < length; ++z) for ( z = 0; z < length; ++z)
{ {
int index = y * width * length + z * width + x; int index = y * width * length + z * width + x;
int blockToReplace=blocks[index]; int blockToReplace=blocks[index];
int blockMetaData=blockData[index]; int blockMetaData=blockData[index];
//NBTTagList tileEntity = tileEntities; //NBTTagList tileEntity = tileEntities;
//int size = tileEntity.tagCount(); //int size = tileEntity.tagCount();
if(blockToReplace==Block.doorIron.blockID&&blocks[ (y-1) * width * length + z * width + x]==Block.doorIron.blockID) if(blockToReplace==Block.doorIron.blockID&&blocks[ (y-1) * width * length + z * width + x]==Block.doorIron.blockID)
{ {
sideLinks.add(new Point3D(x,y,z)); sideLinks.add(new Point3D(x,y,z));
@ -900,56 +900,52 @@ public class SchematicLoader
else if(blockToReplace==Block.endPortalFrame.blockID) else if(blockToReplace==Block.endPortalFrame.blockID)
{ {
monolithSpawns.add(new Point3D(x,y,z)); monolithSpawns.add(new Point3D(x,y,z));
} }
} }
} }
} }
//determines necessary rotation, reflection, and translation to build the .schematic by finding the difference between the
//.schematic incomingLink location which is relative to the .schematic only, and comparing it with the world incoming link coordinates
//must also factor in the orientation of the incoming door.
if(orientation==0) //TODO currently broken, only orientation 3 works atm
{
xCooe=-incomingLink.getX()+incX;
yCooe=-incomingLink.getY()+incY;
zCooe=-incomingLink.getZ()+incZ;
} //Compute the Y-axis translation that places our structure correctly
if(orientation==1)//TODO currently broken, only orientation 3 works atm yCooe = incY - incomingLink.getY();
{
xCooe=-incomingLink.getX()+incX;
yCooe=-incomingLink.getY()+incY;
zCooe=-incomingLink.getZ()+incZ;
}
if(orientation==2)//TODO currently broken, only orientation 3 works atm
{
xCooe=-incomingLink.getX()+incX;
yCooe=-incomingLink.getY()+incY;
zCooe=-incomingLink.getZ()+incZ;
}
if(orientation==3)//TODO this only works because it is the default orientation of the pocket dim
{
xCooe=-incomingLink.getX()+incX;
yCooe=-incomingLink.getY()+incY;
zCooe=-incomingLink.getZ()+incZ;
}
//loop to actually place the blocks //Loop to actually place the blocks
for ( x = 0; x < width; ++x) for ( x = 0; x < width; x++)
{ {
for ( y = 0; y < height; ++y) for ( z = 0; z < length; z++)
{ {
for ( z = 0; z < length; ++z) //Compute the X-axis and Z-axis translations that will shift
//and rotate our structure properly.
switch (orientation)
{ {
case 0:
xCooe = -incomingLink.getX() + incX;
zCooe = -incomingLink.getZ() + incZ;
break;
case 1:
xCooe = -incomingLink.getX() + incX;
zCooe = -incomingLink.getZ() + incZ;
break;
case 2:
xCooe = -incomingLink.getX() + incX;
zCooe = -incomingLink.getZ() + incZ;
break;
case 3:
xCooe = -incomingLink.getX() + incX;
zCooe = -incomingLink.getZ() + incZ;
break;
}
for ( y = 0; y < height; y++)
{
int index = y * width * length + z * width + x; int index = y * width * length + z * width + x;
int blockToReplace=blocks[index]; int blockToReplace=blocks[index];
int blockMetaData=blockData[index]; int blockMetaData=blockData[index];
NBTTagList tileEntity = tileEntities; NBTTagList tileEntity = tileEntities;
//replace tagging blocks with air, and mob blocks with FoR //replace tagging blocks with air, and mob blocks with FoR
if(blockToReplace==Block.endPortalFrame.blockID) if(blockToReplace==Block.endPortalFrame.blockID)
{ {
@ -959,7 +955,7 @@ public class SchematicLoader
{ {
blockToReplace=mod_pocketDim.blockDimWall.blockID; blockToReplace=mod_pocketDim.blockDimWall.blockID;
} }
//place blocks and metaData //place blocks and metaData
if(blockToReplace>0) if(blockToReplace>0)
{ {
@ -990,23 +986,23 @@ public class SchematicLoader
{ {
tile.readFromNBT(tag); tile.readFromNBT(tag);
} }
**/ **/
//fill chests
if(world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe) instanceof TileEntityChest)
{
TileEntityChest chest = (TileEntityChest) world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe);
ChestGenHooks info = DDLoot.DungeonChestInfo;
WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), (TileEntityChest)world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe), info.getCount(rand));
}
//fill dispensers
if(world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe) instanceof TileEntityDispenser)
{
TileEntityDispenser dispenser = (TileEntityDispenser) world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe);
dispenser.addItem(new ItemStack(Item.arrow, 64));
} //fill chests
if(world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe) instanceof TileEntityChest)
{
TileEntityChest chest = (TileEntityChest) world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe);
ChestGenHooks info = DDLoot.DungeonChestInfo;
WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), (TileEntityChest)world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe), info.getCount(rand));
}
//fill dispensers
if(world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe) instanceof TileEntityDispenser)
{
TileEntityDispenser dispenser = (TileEntityDispenser) world.getBlockTileEntity(x+xCooe, y+yCooe, z+zCooe);
dispenser.addItem(new ItemStack(Item.arrow, 64));
}
} }
} }
} }
@ -1016,39 +1012,39 @@ public class SchematicLoader
//generate the LinkData defined by the door placement, Iron Dim doors first //generate the LinkData defined by the door placement, Iron Dim doors first
for(Point3D point : sideLinks) for(Point3D point : sideLinks)
{ {
int depth = dimHelper.instance.getDimDepth(originDimID);
int xNoise = 0;
int zNoise =0;
switch(world.getBlockMetadata(point.getX()+xCooe, point.getY()+yCooe-1, point.getZ()+zCooe))
{
case 0:
xNoise = (int)rand.nextInt(depth+1*200)+depth*50;
zNoise = (int)rand.nextInt(depth+1*20)-(10)*depth;
break; int depth = dimHelper.instance.getDimDepth(originDimID);
case 1: int xNoise = 0;
xNoise = (int)rand.nextInt(depth+1*20)-(10)*depth; int zNoise =0;
zNoise = (int) rand.nextInt(depth+1*200)+depth*50; switch(world.getBlockMetadata(point.getX()+xCooe, point.getY()+yCooe-1, point.getZ()+zCooe))
{
case 0:
xNoise = (int)rand.nextInt(depth+1*200)+depth*50;
zNoise = (int)rand.nextInt(depth+1*20)-(10)*depth;
break; break;
case 2: case 1:
xNoise = - (rand.nextInt(depth+1*200)+depth*50); xNoise = (int)rand.nextInt(depth+1*20)-(10)*depth;
zNoise = (int)rand.nextInt(depth+1*20)-(10)*depth; zNoise = (int) rand.nextInt(depth+1*200)+depth*50;
break; break;
case 3: case 2:
xNoise = (int)rand.nextInt(depth+1*20)-(10)*depth; xNoise = - (rand.nextInt(depth+1*200)+depth*50);
zNoise = -(rand.nextInt(depth+1*200)+depth*50); zNoise = (int)rand.nextInt(depth+1*20)-(10)*depth;
break; break;
} case 3:
xNoise = (int)rand.nextInt(depth+1*20)-(10)*depth;
zNoise = -(rand.nextInt(depth+1*200)+depth*50);
LinkData sideLink = new LinkData(destDimID,0,point.getX()+xCooe, point.getY()+yCooe, point.getZ()+zCooe,xNoise+point.getX()+xCooe, point.getY()+yCooe+1, zNoise+point.getZ()+zCooe,true,world.getBlockMetadata(point.getX()+xCooe, point.getY()+yCooe-1, point.getZ()+zCooe)); break;
dimHelper.instance.createPocket(sideLink, true, true); }
LinkData sideLink = new LinkData(destDimID,0,point.getX()+xCooe, point.getY()+yCooe, point.getZ()+zCooe,xNoise+point.getX()+xCooe, point.getY()+yCooe+1, zNoise+point.getZ()+zCooe,true,world.getBlockMetadata(point.getX()+xCooe, point.getY()+yCooe-1, point.getZ()+zCooe));
dimHelper.instance.createPocket(sideLink, true, true);
} }
//generate linkData for wooden dim doors leading to the overworld //generate linkData for wooden dim doors leading to the overworld
for(Point3D point : exitLinks) for(Point3D point : exitLinks)
{ {
@ -1064,7 +1060,7 @@ public class SchematicLoader
else if((rand.nextBoolean()&&randomLink!=null)) else if((rand.nextBoolean()&&randomLink!=null))
{ {
sideLink.destDimID=randomLink.locDimID; sideLink.destDimID=randomLink.locDimID;
// System.out.println("randomLink"); // System.out.println("randomLink");
} }
sideLink.destYCoord=yCoordHelper.getFirstUncovered(sideLink.destDimID, point.getX()+xCooe,10,point.getZ()+zCooe); sideLink.destYCoord=yCoordHelper.getFirstUncovered(sideLink.destDimID, point.getX()+xCooe,10,point.getZ()+zCooe);
@ -1075,7 +1071,7 @@ public class SchematicLoader
} }
sideLink.linkOrientation=world.getBlockMetadata(point.getX()+xCooe, point.getY()+yCooe-1, point.getZ()+zCooe); sideLink.linkOrientation=world.getBlockMetadata(point.getX()+xCooe, point.getY()+yCooe-1, point.getZ()+zCooe);
dimHelper.instance.createLink(sideLink); dimHelper.instance.createLink(sideLink);
dimHelper.instance.createLink(sideLink.destDimID , sideLink.locDimID, sideLink.destXCoord, sideLink.destYCoord, sideLink.destZCoord, sideLink.locXCoord, sideLink.locYCoord, sideLink.locZCoord, dimHelper.instance.flipDoorMetadata(sideLink.linkOrientation)); dimHelper.instance.createLink(sideLink.destDimID , sideLink.locDimID, sideLink.destXCoord, sideLink.destYCoord, sideLink.destZCoord, sideLink.locXCoord, sideLink.locYCoord, sideLink.locZCoord, dimHelper.instance.flipDoorMetadata(sideLink.linkOrientation));
@ -1093,7 +1089,7 @@ public class SchematicLoader
E.printStackTrace(); E.printStackTrace();
} }
} }
//spawn monoliths //spawn monoliths
for(Point3D point : monolithSpawns) for(Point3D point : monolithSpawns)
{ {
@ -1102,7 +1098,7 @@ public class SchematicLoader
world.spawnEntityInWorld(mob); world.spawnEntityInWorld(mob);
} }
} }
public void generateDungeonPocket(LinkData link) public void generateDungeonPocket(LinkData link)
{ {
String filePath=DungeonHelper.instance().defaultBreak.schematicPath; String filePath=DungeonHelper.instance().defaultBreak.schematicPath;
@ -1124,15 +1120,15 @@ public class SchematicLoader
{ {
return; return;
} }
int cX; int cX;
int cZ; int cZ;
int cY; int cY;
Chunk chunk; Chunk chunk;
cX = x >> 4; cX = x >> 4;
cZ = z >> 4; cZ = z >> 4;
cY=y >>4; cY=y >>4;
int chunkX=(x % 16)< 0 ? ((x) % 16)+16 : ((x) % 16); int chunkX=(x % 16)< 0 ? ((x) % 16)+16 : ((x) % 16);
int chunkZ=((z) % 16)< 0 ? ((z) % 16)+16 : ((z) % 16); int chunkZ=((z) % 16)< 0 ? ((z) % 16)+16 : ((z) % 16);

View file

@ -1,9 +1,9 @@
package StevenDimDoors.mod_pocketDim.commands; package StevenDimDoors.mod_pocketDim.commands;
import java.io.File;
import java.util.Collection; import java.util.Collection;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
import StevenDimDoors.mod_pocketDim.DungeonGenerator; import StevenDimDoors.mod_pocketDim.DungeonGenerator;
import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.LinkData;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
@ -15,7 +15,7 @@ public class CommandCreateDungeonRift extends DDCommandBase
private CommandCreateDungeonRift() private CommandCreateDungeonRift()
{ {
super("dd-rift"); super("dd-rift", "<dungeon name | 'list' | 'random'>");
} }
public static CommandCreateDungeonRift instance() public static CommandCreateDungeonRift instance()
@ -27,71 +27,101 @@ public class CommandCreateDungeonRift extends DDCommandBase
} }
@Override @Override
public void processCommand(EntityPlayer sender, String[] command) protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{ {
DungeonHelper dungeonHelper = DungeonHelper.instance(); DungeonHelper dungeonHelper = DungeonHelper.instance();
if(command==null||sender.worldObj.isRemote) if (sender.worldObj.isRemote)
{ {
return; return DDCommandResult.SUCCESS;
}
if (command.length == 0)
{
return DDCommandResult.TOO_FEW_ARGUMENTS;
}
if (command.length > 1)
{
return DDCommandResult.TOO_MANY_ARGUMENTS;
} }
LinkData link = new LinkData(sender.worldObj.provider.dimensionId, 0, if (command[0].equals("list"))
(int) sender.posX,
(int) sender.posY + 1,
(int) sender.posZ,
(int) sender.posX,
(int) sender.posY + 1,
(int) sender.posZ,true,3);
if(command.length!=0&&command[0].equals("random"))
{
sender.sendChatToPlayer("Created dungeon rift");
dimHelper.instance.createLink(link);
link = dimHelper.instance.createPocket(link,true, true);
}
else if (command.length != 0 && command[0].equals("list"))
{ {
Collection<String> dungeonNames = dungeonHelper.getDungeonNames(); Collection<String> dungeonNames = dungeonHelper.getDungeonNames();
for (String name : dungeonNames) for (String name : dungeonNames)
{ {
getCommandSenderAsPlayer(sender).sendChatToPlayer(name); sender.sendChatToPlayer(name);
}
}
else if(command.length!=0)
{
for(DungeonGenerator dungeonGen : dungeonHelper.registeredDungeons)
{
String dungeonName =dungeonGen.schematicPath.toLowerCase();
if(dungeonName.contains(command[0].toLowerCase()))
{
link = dimHelper.instance.createPocket(link,true, true);
dimHelper.dimList.get(link.destDimID).dungeonGenerator=dungeonGen;
sender.sendChatToPlayer("Genned dungeon " +dungeonName);
return;
}
}
for(DungeonGenerator dungeonGen : dungeonHelper.customDungeons)
{
String dungeonName =dungeonGen.schematicPath.toLowerCase();
if(dungeonName.contains(command[0].toLowerCase()))
{
link = dimHelper.instance.createPocket(link,true, true);
dimHelper.dimList.get(link.destDimID).dungeonGenerator=dungeonGen;
sender.sendChatToPlayer("Genned dungeon " +dungeonName);
return;
}
}
if(command!=null&&!command[0].equals("random"))
{
sender.sendChatToPlayer("could not find dungeon, 'list' for list of dungeons");
} }
sender.sendChatToPlayer("");
} }
else else
{ {
sender.sendChatToPlayer("invalid arguments- 'random' for random dungeon, or 'list' for dungeon names"); DungeonGenerator result;
int x = (int) sender.posX;
int y = (int) sender.posY;
int z = (int) sender.posZ;
LinkData link = new LinkData(sender.worldObj.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3);
if (command[0].equals("random"))
{
dimHelper.instance.createLink(link);
link = dimHelper.instance.createPocket(link, true, true);
sender.sendChatToPlayer("Created a rift to a random dungeon (Dimension ID = " + link.destDimID + ").");
}
else
{
result = findDungeonByPartialName(command[0], dungeonHelper.registeredDungeons);
if (result == null)
{
result = findDungeonByPartialName(command[0], dungeonHelper.customDungeons);
}
//Check if we found any matches
if (result != null)
{
//Create a rift to our selected dungeon and notify the player
link = dimHelper.instance.createPocket(link, true, true);
dimHelper.dimList.get(link.destDimID).dungeonGenerator = result;
sender.sendChatToPlayer("Created a rift to \"" + getSchematicName(result) + "\" dungeon (Dimension ID = " + link.destDimID + ").");
}
else
{
//No matches!
return new DDCommandResult("Error: The specified dungeon was not found. Use 'list' to see a list of the available dungeons.");
}
}
} }
return DDCommandResult.SUCCESS;
}
private DungeonGenerator findDungeonByPartialName(String query, Collection<DungeonGenerator> dungeons)
{
//Search for the shortest dungeon name that contains the lowercase query string.
String dungeonName;
String normalQuery = query.toLowerCase();
DungeonGenerator bestMatch = null;
int matchLength = Integer.MAX_VALUE;
for (DungeonGenerator dungeon : dungeons)
{
//We need to extract the file's name. Comparing against schematicPath could
//yield false matches if the query string is contained within the path.
dungeonName = getSchematicName(dungeon).toLowerCase();
if (dungeonName.length() < matchLength && dungeonName.contains(normalQuery))
{
matchLength = dungeonName.length();
bestMatch = dungeon;
}
}
return bestMatch;
}
private static String getSchematicName(DungeonGenerator dungeon)
{
//TODO: Move this to DungeonHelper and use it for all schematic name parsing.
//In the future, we really should include the schematic's name as part of DungeonGenerator
//to avoid redoing this work constantly.
File schematic = new File(dungeon.schematicPath);
String fileName = schematic.getName();
return fileName.substring(0, fileName.length() - DungeonHelper.SCHEMATIC_FILE_EXTENSION.length());
} }
} }

View file

@ -14,7 +14,7 @@ public class CommandDeleteAllLinks extends DDCommandBase
private CommandDeleteAllLinks() private CommandDeleteAllLinks()
{ {
super("dd-deletelinks"); super("dd-deletelinks", "FIXME");
} }
public static CommandDeleteAllLinks instance() public static CommandDeleteAllLinks instance()
@ -26,7 +26,7 @@ public class CommandDeleteAllLinks extends DDCommandBase
} }
@Override @Override
protected void processCommand(EntityPlayer sender, String[] command) protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{ {
int linksRemoved=0; int linksRemoved=0;
int targetDim; int targetDim;
@ -80,5 +80,6 @@ public class CommandDeleteAllLinks extends DDCommandBase
sender.sendChatToPlayer("Removed " + linksRemoved + " links."); sender.sendChatToPlayer("Removed " + linksRemoved + " links.");
} }
} }
return DDCommandResult.SUCCESS; //TEMPORARY HACK
} }
} }

View file

@ -14,7 +14,7 @@ public class CommandDeleteDimensionData extends DDCommandBase
private CommandDeleteDimensionData() private CommandDeleteDimensionData()
{ {
super("dd-deletedimension"); super("dd-deletedimension", "FIXME");
} }
public static CommandDeleteDimensionData instance() public static CommandDeleteDimensionData instance()
@ -26,7 +26,7 @@ public class CommandDeleteDimensionData extends DDCommandBase
} }
@Override @Override
protected void processCommand(EntityPlayer sender, String[] command) protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{ {
int linksRemoved=0; int linksRemoved=0;
int targetDim; int targetDim;
@ -90,5 +90,6 @@ public class CommandDeleteDimensionData extends DDCommandBase
sender.sendChatToPlayer("Error- dimension "+targetDim+" not registered with dimDoors"); sender.sendChatToPlayer("Error- dimension "+targetDim+" not registered with dimDoors");
} }
} }
return DDCommandResult.SUCCESS; //TEMPORARY HACK
} }
} }

View file

@ -15,7 +15,7 @@ public class CommandDeleteRifts extends DDCommandBase
private CommandDeleteRifts() private CommandDeleteRifts()
{ {
super("dd-???"); super("dd-???", "FIXME");
} }
public static CommandDeleteRifts instance() public static CommandDeleteRifts instance()
@ -27,7 +27,7 @@ public class CommandDeleteRifts extends DDCommandBase
} }
@Override @Override
protected void processCommand(EntityPlayer sender, String[] command) protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{ {
int linksRemoved=0; int linksRemoved=0;
int targetDim; int targetDim;
@ -84,5 +84,6 @@ public class CommandDeleteRifts extends DDCommandBase
sender.sendChatToPlayer("Removed "+linksRemoved+" rifts."); sender.sendChatToPlayer("Removed "+linksRemoved+" rifts.");
} }
} }
return DDCommandResult.SUCCESS; //TEMPORARY HACK
} }
} }

View file

@ -12,7 +12,9 @@ public class CommandEndDungeonCreation extends DDCommandBase
private CommandEndDungeonCreation() private CommandEndDungeonCreation()
{ {
super("dd-export"); super("dd-export", new String[] {
"<dungeon type> <dungeon name> <'open' | 'closed'> [weight] ['override']",
"<schematic name> override" } );
} }
public static CommandEndDungeonCreation instance() public static CommandEndDungeonCreation instance()
@ -24,57 +26,160 @@ public class CommandEndDungeonCreation extends DDCommandBase
} }
@Override @Override
protected void processCommand(EntityPlayer sender, String[] command) protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{ {
/*
* There are two versions of this command. One version takes 3 to 5 arguments consisting
* of the information needed for a proper schematic name and an optional override argument.
* The override argument only allows the user to export any dimension, even if it wasn't
* meant for custom dungeon creation. It does not allow the user to export a dungeon with
* invalid tags.
*
* If the user wishes to name his schematic in a different format, then he will have to use
* the 2-argument version of this command, which accepts a schematic name and a mandatory
* override argument.
*/
DungeonHelper dungeonHelper = DungeonHelper.instance(); DungeonHelper dungeonHelper = DungeonHelper.instance();
DDProperties properties = DDProperties.instance();
if (!dungeonHelper.isCustomDungeon(sender.worldObj.provider.dimensionId)) if (command.length < 2)
{ {
if (command.length < 2) return DDCommandResult.TOO_FEW_ARGUMENTS;
{ }
sender.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway"); if (command.length > 5)
return; {
return DDCommandResult.TOO_MANY_ARGUMENTS;
}
else if (!command[1].contains("OVERRIDE"))
{
sender.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway");
return;
}
} }
int x = (int) sender.posX; //Check if we received the 2-argument version
int y = (int) sender.posY; if (command.length == 2)
int z = (int) sender.posZ;
if (command.length == 0)
{ {
sender.sendChatToPlayer("Must name file"); if (command[1].equalsIgnoreCase("override"))
}
else if(!sender.worldObj.isRemote)
{
//Check that the dungeon name is valid to prevent directory traversal and other forms of abuse
if (DungeonHelper.NamePattern.matcher(command[0]).matches())
{ {
String exportPath = properties.CustomSchematicDirectory + "/" + command[0] + ".schematic"; //Check that the schematic name is a legal name
if (dungeonHelper.exportDungeon(sender.worldObj, x, y, z, exportPath)) if (DungeonHelper.SchematicNamePattern.matcher(command[0]).matches())
{ {
sender.sendChatToPlayer("Saved dungeon schematic in " + exportPath); //Export the schematic
dungeonHelper.registerCustomDungeon(new File(exportPath)); return exportDungeon(sender, command[0]);
} }
else else
{ {
sender.sendChatToPlayer("Failed to save dungeon schematic!"); //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 else
{ {
sender.sendChatToPlayer("Invalid schematic name. Please use only letters, numbers, 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
//Check if the current dimension is a pocket for building custom dungeons or if the override argument was used.
if (!dungeonHelper.isCustomDungeon(sender.worldObj.provider.dimensionId) ||
!command[command.length - 1].equalsIgnoreCase("override"))
{
//This dimension may not be exported without overriding!
return new DDCommandResult("Error: The current dimension was not made for dungeon creation. Use the 'override' argument to export anyway.");
}
//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
//once the during the save file format rewrite. ~SenseiKiwi
if (!dungeonHelper.validateDungeonType(command[0]))
{
return new DDCommandResult("Error: Invalid dungeon type. Please use one of the existing types.");
}
if (!DungeonHelper.DungeonNamePattern.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 argument, export the dungeon.
if (command.length == 3)
{
return exportDungeon(sender, join(command, "_", 0, 3));
}
//Validate the 4th argument, which might be the weight or might be "override".
try
{
int weight = Integer.parseInt(command[3]);
if (weight >= 0 && weight <= DungeonHelper.MAX_DUNGEON_WEIGHT)
{
return exportDungeon(sender, join(command, "_", 0, 4));
}
}
catch (Exception e)
{
//The 4th argument could be "override", but only if it's the last argument.
//In that case, we assume the default dungeon weight.
if (command.length == 4 && command[3].equalsIgnoreCase("override"))
{
return exportDungeon(sender, join(command, "_", 0, 3));
}
}
//If we've reached this point, then we must have an invalid weight.
return new DDCommandResult("Invalid dungeon weight. Please specify a weight between 0 and " + DungeonHelper.MAX_DUNGEON_WEIGHT + ", inclusive.");
}
return DDCommandResult.SUCCESS;
}
private static DDCommandResult exportDungeon(EntityPlayer player, String name)
{
DDProperties properties = DDProperties.instance();
DungeonHelper dungeonHelper = DungeonHelper.instance();
int x = (int) player.posX;
int y = (int) player.posY;
int z = (int) player.posZ;
String exportPath = properties.CustomSchematicDirectory + File.separator + name + ".schematic";
if (dungeonHelper.exportDungeon(player.worldObj, x, y, z, exportPath))
{
player.sendChatToPlayer("Saved dungeon schematic in " + exportPath);
dungeonHelper.registerCustomDungeon(new File(exportPath));
return DDCommandResult.SUCCESS;
}
else
{
return new DDCommandResult("Error: Failed to save dungeon schematic!");
}
}
private static String join(String[] source, String delimiter, int start, int end)
{
//TODO: This function should be moved to a helper, but we have several single-function helpers as is.
//I find that to be worse than keeping this private. ~SenseiKiwi
int index;
int length = 0;
StringBuilder buffer;
for (index = start; index < end; index++)
{
length += source[index].length();
}
length += (end - start - 1) * delimiter.length();
buffer = new StringBuilder(length);
buffer.append(source[start]);
for (index = start + 1; index < end; index++)
{
buffer.append(delimiter);
buffer.append(source[index]);
}
return buffer.toString();
} }
} }

View file

@ -1,7 +1,6 @@
package StevenDimDoors.mod_pocketDim.commands; package StevenDimDoors.mod_pocketDim.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import StevenDimDoors.mod_pocketDim.DimData; import StevenDimDoors.mod_pocketDim.DimData;
@ -14,7 +13,7 @@ public class CommandPrintDimensionData extends DDCommandBase
private CommandPrintDimensionData() private CommandPrintDimensionData()
{ {
super("dd-dimensiondata"); super("dd-dimensiondata", "[dimension number]");
} }
public static CommandPrintDimensionData instance() public static CommandPrintDimensionData instance()
@ -26,45 +25,45 @@ public class CommandPrintDimensionData extends DDCommandBase
} }
@Override @Override
protected void processCommand(EntityPlayer sender, String[] command) protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{ {
int targetDim; int targetDim;
boolean shouldGo= true; DimData dimData;
if(command.length==0) if (command.length == 0)
{ {
targetDim= sender.worldObj.provider.dimensionId; targetDim = sender.worldObj.provider.dimensionId;
} }
else if(command.length==1) else if (command.length == 1)
{ {
targetDim = parseInt(sender, command[0]); try
if(!dimHelper.dimList.containsKey(targetDim))
{ {
sender.sendChatToPlayer("Error- dim "+targetDim+" not registered"); targetDim = Integer.parseInt(command[0]);
shouldGo=false; }
catch (Exception ex)
{
return DDCommandResult.INVALID_DIMENSION_ID;
} }
} }
else else
{ {
targetDim=0; return DDCommandResult.TOO_MANY_ARGUMENTS;
shouldGo=false; }
sender.sendChatToPlayer("Error-Invalid argument, print_dim_data <targetDimID> or blank for current dim");
dimData = dimHelper.dimList.get(targetDim);
if (dimData == null)
{
return DDCommandResult.UNREGISTERED_DIMENSION;
} }
if(shouldGo) ArrayList<LinkData> links = dimData.printAllLinkData();
{
if(dimHelper.dimList.containsKey(targetDim))
{
DimData dimData = dimHelper.dimList.get(targetDim);
Collection<LinkData> links = new ArrayList<LinkData>();
links.addAll( dimData.printAllLinkData());
for (LinkData link : links) sender.sendChatToPlayer("Dimension ID = " + dimData.dimID);
{ sender.sendChatToPlayer("Dimension Depth = " + dimData.depth);
sender.sendChatToPlayer(link.printLinkData()); for (LinkData link : links)
} {
sender.sendChatToPlayer("DimID= "+dimData.dimID+"Dim depth = "+dimData.depth); sender.sendChatToPlayer(link.printLinkData());
} }
} return DDCommandResult.SUCCESS;
} }
} }

View file

@ -2,6 +2,8 @@ package StevenDimDoors.mod_pocketDim.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import StevenDimDoors.mod_pocketDim.DimData; import StevenDimDoors.mod_pocketDim.DimData;
@ -14,7 +16,7 @@ public class CommandPruneDimensions extends DDCommandBase
private CommandPruneDimensions() private CommandPruneDimensions()
{ {
super("dd-prune"); super("dd-prune", "['delete']");
} }
public static CommandPruneDimensions instance() public static CommandPruneDimensions instance()
@ -26,38 +28,46 @@ public class CommandPruneDimensions extends DDCommandBase
} }
@Override @Override
protected void processCommand(EntityPlayer sender, String[] command) protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{ {
int numRemoved=0; if (command.length > 1)
ArrayList<Integer> dimsWithLinks = new ArrayList<Integer>(); {
return DDCommandResult.TOO_MANY_ARGUMENTS;
}
if (command.length == 1 && !command[0].equalsIgnoreCase("delete"))
{
return DDCommandResult.INVALID_ARGUMENTS;
}
int removedCount = 0;
boolean deleteFolders = (command.length == 1);
Set<Integer> linkedDimensions = new HashSet<Integer>();
Collection<DimData> allDims = new ArrayList<DimData>(); Collection<DimData> allDims = new ArrayList<DimData>();
allDims.addAll(dimHelper.dimList.values()); allDims.addAll(dimHelper.dimList.values());
for(DimData data: allDims)
for (DimData data : allDims)
{ {
for(LinkData link:data.printAllLinkData()) for (LinkData link : data.printAllLinkData())
{ {
if(!dimsWithLinks.contains(link.destDimID)) linkedDimensions.add(link.destDimID);
}
}
for (LinkData link : dimHelper.instance.interDimLinkList.values())
{
linkedDimensions.add(link.destDimID);
}
for (DimData data : allDims)
{
if (!linkedDimensions.contains(data.dimID))
{
if (dimHelper.instance.pruneDimension(data, deleteFolders))
{ {
dimsWithLinks.add(link.destDimID); removedCount++;
} }
} }
} }
for(LinkData link : dimHelper.instance.interDimLinkList.values())
{
if(!dimsWithLinks.contains(link.destDimID))
{
dimsWithLinks.add(link.destDimID);
}
}
for(DimData data : allDims)
{
if(!dimsWithLinks.contains(data.dimID))
{
dimHelper.dimList.remove(data.dimID);
numRemoved++;
}
}
dimHelper.instance.save(); dimHelper.instance.save();
sender.sendChatToPlayer("Removed " + numRemoved + " unreachable pocket dims."); sender.sendChatToPlayer("Removed " + removedCount + " unreachable pocket dims.");
return DDCommandResult.SUCCESS;
} }
} }

View file

@ -1,43 +0,0 @@
package StevenDimDoors.mod_pocketDim.commands;
import java.io.File;
import net.minecraft.entity.player.EntityPlayer;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.DimData;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
public class CommandRegenPocket extends DDCommandBase
{
private static CommandRegenPocket instance = null;
private CommandRegenPocket()
{
super("dd-regenDungeons");
}
public static CommandRegenPocket instance()
{
if (instance == null)
instance = new CommandRegenPocket();
return instance;
}
@Override
protected void processCommand(EntityPlayer sender, String[] command)
{
DungeonHelper dungeonHelper = DungeonHelper.instance();
DDProperties properties = DDProperties.instance();
for(DimData data : dimHelper.dimList.values())
{
if(data.isDimRandomRift)
{
dimHelper.instance.regenPocket(data);
}
}
}
}

View file

@ -0,0 +1,51 @@
package StevenDimDoors.mod_pocketDim.commands;
import net.minecraft.entity.player.EntityPlayer;
import StevenDimDoors.mod_pocketDim.DimData;
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
public class CommandResetDungeons extends DDCommandBase
{
private static CommandResetDungeons instance = null;
private CommandResetDungeons()
{
super("dd-resetdungeons", "");
}
public static CommandResetDungeons instance()
{
if (instance == null)
instance = new CommandResetDungeons();
return instance;
}
@Override
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{
if (command.length > 0)
{
return DDCommandResult.TOO_FEW_ARGUMENTS;
}
int dungeonCount = 0;
int resetCount = 0;
for (DimData data : dimHelper.dimList.values())
{
if (data.isDimRandomRift)
{
dungeonCount++;
if (dimHelper.instance.resetPocket(data))
{
resetCount++;
}
}
}
//Notify the user of the results
sender.sendChatToPlayer("Reset complete. " + resetCount + " out of " + dungeonCount + " dungeons were reset.");
return DDCommandResult.SUCCESS;
}
}

View file

@ -10,7 +10,7 @@ public class CommandStartDungeonCreation extends DDCommandBase
private CommandStartDungeonCreation() private CommandStartDungeonCreation()
{ {
super("dd-create"); super("dd-create", "");
} }
public static CommandStartDungeonCreation instance() public static CommandStartDungeonCreation instance()
@ -22,10 +22,18 @@ public class CommandStartDungeonCreation extends DDCommandBase
} }
@Override @Override
protected void processCommand(EntityPlayer sender, String[] command) 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 (!sender.worldObj.isRemote)
{ {
if (command.length > 0)
{
return DDCommandResult.TOO_MANY_ARGUMENTS;
}
//Place a door leading to a pocket dimension where the player is standing. //Place a door leading to a pocket dimension where the player is standing.
//The pocket dimension will be serve as a room for the player to build a dungeon. //The pocket dimension will be serve as a room for the player to build a dungeon.
int x = (int) sender.posX; int x = (int) sender.posX;
@ -34,7 +42,8 @@ public class CommandStartDungeonCreation extends DDCommandBase
LinkData link = DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z); LinkData link = DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z);
//Notify the player //Notify the player
sender.sendChatToPlayer("Created a door to a pocket dimension (ID = " + link.destDimID + "). Please build your dungeon there."); sender.sendChatToPlayer("Created a door to a pocket dimension (Dimension ID = " + link.destDimID + "). Please build your dungeon there.");
} }
return DDCommandResult.SUCCESS;
} }
} }

View file

@ -12,16 +12,25 @@ import cpw.mods.fml.common.event.FMLServerStartingEvent;
public abstract class DDCommandBase extends CommandBase public abstract class DDCommandBase extends CommandBase
{ {
private String name; private String name;
private String[] formats;
public DDCommandBase(String name) public DDCommandBase(String name, String format)
{ {
this.name = name; this.name = name;
this.formats = new String[] { format };
} }
public DDCommandBase(String name, String[] formats)
{
this.name = name;
this.formats = formats;
}
/* /*
* When overridden in a derived class, processes the command sent by the server. * When overridden in a derived class, processes the command sent by the server
* and returns a status code and message for the result of the operation.
*/ */
protected abstract void processCommand(EntityPlayer sender, String[] command); protected abstract DDCommandResult processCommand(EntityPlayer sender, String[] command);
public final String getCommandName() public final String getCommandName()
{ {
@ -43,6 +52,21 @@ public abstract class DDCommandBase extends CommandBase
public final void processCommand(ICommandSender sender, String[] command) public final void processCommand(ICommandSender sender, String[] command)
{ {
//Forward the command //Forward the command
processCommand(getCommandSenderAsPlayer(sender), command); EntityPlayer player = getCommandSenderAsPlayer(sender);
DDCommandResult result = processCommand(player, command);
//If the command failed, send the player a status message.
if (result.failed())
{
if (result.shouldPrintUsage())
{
//Send the argument formats for this command
for (String format : formats)
{
player.sendChatToPlayer("Usage: " + name + " " + format);
}
}
player.sendChatToPlayer(result.getMessage());
}
} }
} }

View file

@ -0,0 +1,55 @@
package StevenDimDoors.mod_pocketDim.commands;
public class DDCommandResult {
public static final DDCommandResult SUCCESS = new DDCommandResult(0, "", false);
public static final DDCommandResult TOO_FEW_ARGUMENTS = new DDCommandResult(1, "Error: Too few arguments passed to the command", true);
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 int CUSTOM_ERROR_CODE = -1;
private int code;
private String message;
private boolean printUsage;
private DDCommandResult(int code, String message, boolean printUsage)
{
this.code = code;
this.message = message;
this.printUsage = printUsage;
}
public DDCommandResult(String message)
{
this(CUSTOM_ERROR_CODE, message, false);
}
public DDCommandResult(String message, boolean printUsage)
{
this(CUSTOM_ERROR_CODE, message, printUsage);
}
public boolean failed()
{
return (code != 0);
}
public int getCode()
{
return code;
}
public String getMessage()
{
return message;
}
public boolean shouldPrintUsage()
{
return printUsage;
}
}

View file

@ -31,11 +31,12 @@ public class DungeonHelper
{ {
private static DungeonHelper instance = null; private static DungeonHelper instance = null;
private static DDProperties properties = null; private static DDProperties properties = null;
public static final Pattern NamePattern = Pattern.compile("[A-Za-z0-9_\\-]+"); public static final Pattern SchematicNamePattern = Pattern.compile("[A-Za-z0-9_\\-]+");
public static final Pattern DungeonNamePattern = Pattern.compile("[A-Za-z0-9\\-]+");
private static final String SCHEMATIC_FILE_EXTENSION = ".schematic"; public static final String SCHEMATIC_FILE_EXTENSION = ".schematic";
private static final int DEFAULT_DUNGEON_WEIGHT = 100; private static final int DEFAULT_DUNGEON_WEIGHT = 100;
private static final int MAX_DUNGEON_WEIGHT = 10000; //Used to prevent overflows and math breaking down public static final int MAX_DUNGEON_WEIGHT = 10000; //Used to prevent overflows and math breaking down
private static final String HUB_DUNGEON_TYPE = "Hub"; private static final String HUB_DUNGEON_TYPE = "Hub";
private static final String TRAP_DUNGEON_TYPE = "Trap"; private static final String TRAP_DUNGEON_TYPE = "Trap";
@ -166,6 +167,12 @@ public class DungeonHelper
return customDungeonStatus.containsKey(dimensionID); return customDungeonStatus.containsKey(dimensionID);
} }
public boolean validateDungeonType(String type)
{
//Check if the dungeon type is valid
return dungeonTypeChecker.contains(type.toLowerCase());
}
public boolean validateSchematicName(String name) public boolean validateSchematicName(String name)
{ {
String[] dungeonData; String[] dungeonData;
@ -184,7 +191,7 @@ public class DungeonHelper
return false; return false;
//Check if the name is valid //Check if the name is valid
if (!NamePattern.matcher(dungeonData[1]).matches()) if (!SchematicNamePattern.matcher(dungeonData[1]).matches())
return false; return false;
//Check if the open/closed flag is present //Check if the open/closed flag is present

View file

@ -38,6 +38,7 @@ import StevenDimDoors.mod_pocketDim.DimData;
import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.LinkData;
import StevenDimDoors.mod_pocketDim.ObjectSaveInputStream; import StevenDimDoors.mod_pocketDim.ObjectSaveInputStream;
import StevenDimDoors.mod_pocketDim.PacketHandler; import StevenDimDoors.mod_pocketDim.PacketHandler;
import StevenDimDoors.mod_pocketDim.Point3D;
import StevenDimDoors.mod_pocketDim.TileEntityRift; import StevenDimDoors.mod_pocketDim.TileEntityRift;
import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.world.LimboProvider; import StevenDimDoors.mod_pocketDim.world.LimboProvider;
@ -64,7 +65,7 @@ public class dimHelper extends DimensionManager
* ArrayList containing any blocks in limbo that have been placed by the player. Cycled through in the common tick manager * ArrayList containing any blocks in limbo that have been placed by the player. Cycled through in the common tick manager
* @Return * @Return
*/ */
public static ArrayList blocksToDecay= new ArrayList(); public static ArrayList<Point3D> blocksToDecay = new ArrayList<Point3D>();
/** /**
* instance of the dimHelper * instance of the dimHelper
@ -812,33 +813,48 @@ public class dimHelper extends DimensionManager
} }
} }
public void regenPocket(DimData dimData) public boolean resetPocket(DimData dimData)
{ {
if(this.getWorld(dimData.dimID)!=null ||!dimData.isPocket) //TODO: Should we add a check to see if the dimension is currently loaded? How could we check that? ~SenseiKiwi
if (!dimData.isPocket || getWorld(dimData.dimID) != null)
{ {
return; return false;
} }
File save = new File( this.getCurrentSaveRootDirectory()+"/DimensionalDoors/pocketDimID" + dimData.dimID); File save = new File(getCurrentSaveRootDirectory() + "/DimensionalDoors/pocketDimID" + dimData.dimID);
DeleteFolder.deleteFolder(save); DeleteFolder.deleteFolder(save);
dimData.hasBeenFilled=false; dimData.hasBeenFilled = false;
dimData.hasDoor=false; dimData.hasDoor = false;
for(LinkData link : dimData.printAllLinkData()) for(LinkData link : dimData.printAllLinkData())
{ {
link.hasGennedDoor=false; link.hasGennedDoor = false;
LinkData linkOut =this.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID); LinkData linkOut = this.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID);
if(linkOut!=null) if (linkOut != null)
{ {
linkOut.hasGennedDoor=false; linkOut.hasGennedDoor = false;
} }
} }
return true;
} }
public boolean pruneDimension(DimData dimData, boolean deleteFolder)
{
//TODO: Should we add a check to see if the dimension is currently loaded? How could we check that? ~SenseiKiwi
//TODO: All the logic for checking that this is an isolated pocket should be moved in here.
if (!dimData.isPocket || getWorld(dimData.dimID) != null)
{
return false;
}
dimList.remove(dimData.dimID);
if (deleteFolder)
{
File save = new File(getCurrentSaveRootDirectory() + "/DimensionalDoors/pocketDimID" + dimData.dimID);
DeleteFolder.deleteFolder(save);
}
return true;
}
/** /**
* method called when the client disconects/server stops to unregister dims. * method called when the client disconnects/server stops to unregister dims.
* @Return * @Return
*/ */
public void unregsisterDims() public void unregsisterDims()

View file

@ -29,7 +29,7 @@ import StevenDimDoors.mod_pocketDim.commands.CommandDeleteRifts;
import StevenDimDoors.mod_pocketDim.commands.CommandEndDungeonCreation; import StevenDimDoors.mod_pocketDim.commands.CommandEndDungeonCreation;
import StevenDimDoors.mod_pocketDim.commands.CommandPrintDimensionData; import StevenDimDoors.mod_pocketDim.commands.CommandPrintDimensionData;
import StevenDimDoors.mod_pocketDim.commands.CommandPruneDimensions; import StevenDimDoors.mod_pocketDim.commands.CommandPruneDimensions;
import StevenDimDoors.mod_pocketDim.commands.CommandRegenPocket; import StevenDimDoors.mod_pocketDim.commands.CommandResetDungeons;
import StevenDimDoors.mod_pocketDim.commands.CommandStartDungeonCreation; import StevenDimDoors.mod_pocketDim.commands.CommandStartDungeonCreation;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
@ -391,7 +391,7 @@ public class mod_pocketDim
@ServerStarting @ServerStarting
public void serverStarting(FMLServerStartingEvent event) public void serverStarting(FMLServerStartingEvent event)
{ {
CommandRegenPocket.instance().register(event); CommandResetDungeons.instance().register(event);
CommandCreateDungeonRift.instance().register(event); CommandCreateDungeonRift.instance().register(event);
CommandDeleteAllLinks.instance().register(event); CommandDeleteAllLinks.instance().register(event);
CommandDeleteDimensionData.instance().register(event); CommandDeleteDimensionData.instance().register(event);