Added LevelPosUtil, now the node are added using it and not with the LevelPos object
This commit is contained in:
@@ -23,6 +23,7 @@ import java.security.InvalidParameterException;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.apache.commons.lang3.mutable.MutableBoolean;
|
||||
|
||||
@@ -284,6 +285,27 @@ public class LodDimension
|
||||
return regions[xIndex][zIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region at the given X and Z
|
||||
* <br>
|
||||
* Returns null if the region doesn't exist
|
||||
* or is outside the loaded area.
|
||||
*/
|
||||
public LodRegion getRegion(int[] levelPos)
|
||||
{
|
||||
|
||||
int xIndex = (LevelPosUtil.getRegionPosX(levelPos) - center.x) + halfWidth;
|
||||
int zIndex = (LevelPosUtil.getRegionPosZ(levelPos) - center.z) + halfWidth;
|
||||
|
||||
if (!regionIsInRange(LevelPosUtil.getRegionPosX(levelPos), LevelPosUtil.getRegionPosZ(levelPos)))
|
||||
throw new ArrayIndexOutOfBoundsException("Region for level pos " + levelPos + " out of range");
|
||||
else if (regions[xIndex][zIndex] == null)
|
||||
throw new InvalidParameterException("Region for level pos " + levelPos + " not currently initialized");
|
||||
else if (regions[xIndex][zIndex].getMinDetailLevel() > LevelPosUtil.getDetailLevel(levelPos))
|
||||
throw new InvalidParameterException("Region for level pos " + levelPos + " currently only reach level " + regions[xIndex][zIndex].getMinDetailLevel());
|
||||
return regions[xIndex][zIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region at the given X and Z
|
||||
* <br>
|
||||
@@ -439,12 +461,13 @@ public class LodDimension
|
||||
* stored in the LOD. If an LOD already exists at the given
|
||||
* coordinates it will be overwritten.
|
||||
*/
|
||||
public synchronized Boolean addData(LevelPos levelPos, short[] lodDataPoint, boolean dontSave, boolean serverQuality)
|
||||
public synchronized Boolean addData(int[] levelPos, short[] lodDataPoint, boolean dontSave, boolean serverQuality)
|
||||
{
|
||||
|
||||
// don't continue if the region can't be saved
|
||||
RegionPos regionPos = levelPos.getRegionPos();
|
||||
if (!regionIsInRange(regionPos.x, regionPos.z))
|
||||
int xRegion = LevelPosUtil.getRegionPosX(levelPos);
|
||||
int zRegion = LevelPosUtil.getRegionPosZ(levelPos);
|
||||
if (!regionIsInRange(xRegion, zRegion))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -458,8 +481,8 @@ public class LodDimension
|
||||
try
|
||||
{
|
||||
// mark the region as dirty so it will be saved to disk
|
||||
int xIndex = (regionPos.x - center.x) + halfWidth;
|
||||
int zIndex = (regionPos.z - center.z) + halfWidth;
|
||||
int xIndex = (xRegion - center.x) + halfWidth;
|
||||
int zIndex = (zRegion - center.z) + halfWidth;
|
||||
isRegionDirty[xIndex][zIndex] = true;
|
||||
regen[xIndex][zIndex] = true;
|
||||
regenDimension = true;
|
||||
@@ -582,10 +605,10 @@ public class LodDimension
|
||||
* Returns null if the LodChunk doesn't exist or
|
||||
* is outside the loaded area.
|
||||
*/
|
||||
public void updateData(LevelPos levelPos)
|
||||
public void updateData(int[] levelPos)
|
||||
{
|
||||
if (levelPos.detailLevel > LodUtil.REGION_DETAIL_LEVEL)
|
||||
throw new IllegalArgumentException("getLodFromCoordinates given a level of \"" + levelPos.detailLevel + "\" when \"" + LodUtil.REGION_DETAIL_LEVEL + "\" is the max.");
|
||||
if (LevelPosUtil.getDetailLevel(levelPos) > LodUtil.REGION_DETAIL_LEVEL)
|
||||
throw new IllegalArgumentException("getLodFromCoordinates given a level of \"" + LevelPosUtil.getDetailLevel(levelPos) + "\" when \"" + LodUtil.REGION_DETAIL_LEVEL + "\" is the max.");
|
||||
|
||||
LodRegion region = getRegion(levelPos);
|
||||
|
||||
@@ -611,7 +634,7 @@ public class LodDimension
|
||||
return false;
|
||||
}
|
||||
|
||||
return region.doesDataExist(levelPos.clone());
|
||||
return region.doesDataExist(LevelPosUtil.createLevelPos(levelPos.detailLevel,levelPos.posX,levelPos.posZ));
|
||||
} catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user