2013-02-18 03:46:16 +01:00
|
|
|
package StevenDimDoors.mod_pocketDim;
|
|
|
|
/**Class that contains all the information about a specific dim that is pertienent to Dim Doors. Holds all the rifts present in the dim sorted by x,y,z and
|
|
|
|
* wether or not the dim is a pocket or not, along with its depth.
|
|
|
|
* @Return
|
|
|
|
*/
|
|
|
|
import java.io.Serializable;
|
2013-03-23 06:25:50 +01:00
|
|
|
import java.util.ArrayList;
|
2013-02-18 03:46:16 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public class DimData implements Serializable
|
|
|
|
{
|
|
|
|
public int dimID;
|
|
|
|
public int depth;
|
|
|
|
public int dimOrientation;
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
public World world;
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
public LinkData exitDimLink;
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
public boolean isPocket;
|
|
|
|
public boolean hasBeenFilled=false;
|
|
|
|
public boolean hasDoor=false;
|
|
|
|
public boolean isDimRandomRift=false;
|
2013-06-11 20:42:11 +02:00
|
|
|
public DungeonGenerator dungeonGenerator = null;
|
2013-05-05 00:58:51 +02:00
|
|
|
//public boolean isPrivatePocket = false;
|
2013-06-25 19:55:13 +02:00
|
|
|
public HashMap<Integer, HashMap<Integer, HashMap<Integer, LinkData>>> linksInThisDim = new HashMap();
|
2013-02-18 03:46:16 +01:00
|
|
|
HashMap<Integer, LinkData> dimX;
|
|
|
|
HashMap<Integer, HashMap<Integer, LinkData>> dimY ;
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
static final long serialVersionUID = 454342L;
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
public DimData(int dimID, boolean isPocket, int depth, LinkData exitLinkData)
|
|
|
|
{
|
|
|
|
this.dimID=dimID;
|
|
|
|
this.depth=depth;
|
|
|
|
this.isPocket=isPocket;
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
this.exitDimLink= exitLinkData;
|
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
public DimData(int dimID, boolean isPocket, int depth, int exitLinkDimID, int exitX, int exitY, int exitZ)
|
|
|
|
{
|
2013-06-14 01:01:54 +02:00
|
|
|
this(dimID, isPocket, depth, new LinkData(exitLinkDimID, exitX, exitY, exitZ));
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
public LinkData findNearestRift(World world, int range, int x, int y, int z)
|
|
|
|
{
|
|
|
|
LinkData nearest=null;
|
|
|
|
float distance=range+1;
|
|
|
|
int i=-range;
|
|
|
|
int j=-range;
|
|
|
|
int k=-range;
|
2013-06-14 11:14:34 +02:00
|
|
|
DDProperties properties = DDProperties.instance();
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
while (i<range)
|
|
|
|
{
|
|
|
|
while (j<range)
|
|
|
|
{
|
|
|
|
while (k<range)
|
|
|
|
{
|
2013-06-14 11:14:34 +02:00
|
|
|
if (world.getBlockId(x+i, y+j, z+k) == properties.RiftBlockID && MathHelper.abs(i)+MathHelper.abs(j)+MathHelper.abs(k)<distance)
|
2013-02-18 03:46:16 +01:00
|
|
|
{
|
|
|
|
if(MathHelper.abs(i)+MathHelper.abs(j)+MathHelper.abs(k)!=0)
|
|
|
|
{
|
|
|
|
nearest=this.findLinkAtCoords(x+i, y+j, z+k);
|
|
|
|
distance=MathHelper.abs(i)+MathHelper.abs(j)+MathHelper.abs(k);
|
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
k=-range;
|
|
|
|
j++;
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
|
|
|
j=-range;
|
|
|
|
i++;
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
return nearest;
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-05-28 02:08:42 +02:00
|
|
|
public ArrayList findRiftsInRange(World world, int range, int x, int y, int z)
|
|
|
|
{
|
|
|
|
LinkData nearest=null;
|
|
|
|
ArrayList rifts = new ArrayList();
|
|
|
|
int i=-range;
|
|
|
|
int j=-range;
|
|
|
|
int k=-range;
|
2013-06-14 11:14:34 +02:00
|
|
|
DDProperties properties = DDProperties.instance();
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-05-28 02:08:42 +02:00
|
|
|
while (i<range)
|
|
|
|
{
|
|
|
|
while (j<range)
|
|
|
|
{
|
|
|
|
while (k<range)
|
|
|
|
{
|
2013-06-14 01:01:54 +02:00
|
|
|
if(world.getBlockId(x+i, y+j, z+k)==properties.RiftBlockID)
|
2013-05-28 02:08:42 +02:00
|
|
|
{
|
|
|
|
if(MathHelper.abs(i)+MathHelper.abs(j)+MathHelper.abs(k)!=0)
|
|
|
|
{
|
|
|
|
nearest=this.findLinkAtCoords(x+i, y+j, z+k);
|
|
|
|
if(nearest!=null)
|
|
|
|
{
|
|
|
|
rifts.add(nearest);
|
|
|
|
}
|
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-05-28 02:08:42 +02:00
|
|
|
}
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
k=-range;
|
|
|
|
j++;
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-05-28 02:08:42 +02:00
|
|
|
}
|
|
|
|
j=-range;
|
|
|
|
i++;
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-05-28 02:08:42 +02:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
|
|
|
|
2013-05-28 02:08:42 +02:00
|
|
|
return rifts;
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-05-28 02:08:42 +02:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
public LinkData addLinkToDim(LinkData link)
|
|
|
|
{
|
|
|
|
if(this.linksInThisDim.containsKey(link.locZCoord))
|
|
|
|
{
|
|
|
|
this.dimY=this.linksInThisDim.get(link.locZCoord);
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
if(this.dimY.containsKey(link.locYCoord))
|
|
|
|
{
|
|
|
|
this.dimX=this.dimY.get(link.locYCoord);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.dimX=new HashMap<Integer, LinkData>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.dimX=new HashMap<Integer, LinkData>();
|
|
|
|
this.dimY=new HashMap<Integer, HashMap<Integer, LinkData>>();
|
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
this.dimX.put(link.locXCoord, link);
|
|
|
|
this.dimY.put(link.locYCoord, dimX);
|
|
|
|
this.linksInThisDim.put(link.locZCoord, dimY);
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
//System.out.println("added link to dim "+this.dimID);
|
|
|
|
return link;
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
public LinkData addLinkToDim( int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord, int linkOrientation)
|
|
|
|
{
|
2013-05-04 01:34:01 +02:00
|
|
|
LinkData linkData= new LinkData(this.dimID, destinationDimID, locationXCoord, locationYCoord, locationZCoord, destinationXCoord, destinationYCoord,destinationZCoord,this.isPocket,linkOrientation);
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
return this.addLinkToDim(linkData);
|
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
public boolean isLimbo()
|
|
|
|
{
|
2013-06-14 11:14:34 +02:00
|
|
|
return (this.dimID == DDProperties.instance().LimboDimensionID);
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
public void removeLinkAtCoords(LinkData link)
|
|
|
|
{
|
|
|
|
this.removeLinkAtCoords(link.locDimID, link.locXCoord, link.locYCoord, link.locZCoord);
|
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
public void removeLinkAtCoords(int locationID, int locationXCoord, int locationYCoord, int locationZCoord)
|
|
|
|
{
|
2013-06-14 11:14:34 +02:00
|
|
|
if (this.linksInThisDim.containsKey(locationZCoord))
|
2013-02-18 03:46:16 +01:00
|
|
|
{
|
|
|
|
this.dimY=this.linksInThisDim.get(locationZCoord);
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
if(this.dimY.containsKey(locationYCoord))
|
|
|
|
{
|
|
|
|
this.dimX=this.dimY.get(locationYCoord);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.dimX=new HashMap<Integer, LinkData>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.dimX=new HashMap<Integer, LinkData>();
|
|
|
|
this.dimY=new HashMap<Integer, HashMap<Integer, LinkData>>();
|
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
this.dimX.remove(locationXCoord);
|
|
|
|
this.dimY.put(locationYCoord, dimX);
|
|
|
|
this.linksInThisDim.put(locationZCoord, dimY);
|
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
public LinkData findLinkAtCoords(int locationXCoord, int locationYCoord, int locationZCoord)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-06-25 19:55:13 +02:00
|
|
|
if(this.linksInThisDim.containsKey(locationZCoord))
|
2013-02-18 03:46:16 +01:00
|
|
|
{
|
2013-06-25 19:55:13 +02:00
|
|
|
this.dimY=this.linksInThisDim.get(locationZCoord);
|
|
|
|
|
|
|
|
if(this.dimY.containsKey(locationYCoord))
|
2013-02-18 03:46:16 +01:00
|
|
|
{
|
2013-06-25 19:55:13 +02:00
|
|
|
this.dimX=this.dimY.get(locationYCoord);
|
|
|
|
|
|
|
|
if(this.dimX.containsKey(locationXCoord))
|
|
|
|
{
|
|
|
|
return this.dimX.get(locationXCoord);
|
|
|
|
}
|
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception E)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
return null;
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
2013-07-12 02:42:57 +02:00
|
|
|
public ArrayList<LinkData> getLinksInDim()
|
2013-02-18 03:46:16 +01:00
|
|
|
{
|
2013-06-25 19:55:13 +02:00
|
|
|
//TODO: We might want to modify this function, but I'm afraid of breaking something right now.
|
|
|
|
//To begin with, the name is wrong. This doesn't print anything! >_o ~SenseiKiwi
|
|
|
|
|
|
|
|
ArrayList<LinkData> links = new ArrayList<LinkData>();
|
|
|
|
if (this.linksInThisDim == null)
|
2013-04-01 22:43:11 +02:00
|
|
|
{
|
|
|
|
return links;
|
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
for (HashMap<Integer, HashMap<Integer, LinkData>> first : this.linksInThisDim.values())
|
2013-02-18 03:46:16 +01:00
|
|
|
{
|
2013-06-25 19:55:13 +02:00
|
|
|
for (HashMap<Integer, LinkData> second : first.values())
|
2013-02-18 03:46:16 +01:00
|
|
|
{
|
2013-06-25 19:55:13 +02:00
|
|
|
for (LinkData linkData : second.values())
|
2013-02-18 03:46:16 +01:00
|
|
|
{
|
2013-04-01 22:43:11 +02:00
|
|
|
links.add(linkData);
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
2013-04-01 22:43:11 +02:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
}
|
2013-03-23 06:25:50 +01:00
|
|
|
return links;
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
|
|
|
}
|