Fixed file saving not working
This commit is contained in:
@@ -249,12 +249,11 @@ public class LodQuadTreeDimensionFileHandler
|
||||
private void saveRegionToDisk(LodQuadTree region)
|
||||
{
|
||||
// convert to region coordinates
|
||||
RegionPos regionPos = new RegionPos(new ChunkPos(region.getLodNodeData().center));
|
||||
int x = regionPos.x;
|
||||
int z = regionPos.z;
|
||||
int x = region.getLodNodeData().posX;
|
||||
int z = region.getLodNodeData().posZ;
|
||||
|
||||
File f = new File(getFileNameAndPathForRegion(x, z));
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
// make sure the file and folder exists
|
||||
|
||||
@@ -330,9 +330,8 @@ public class LodQuadTreeDimension
|
||||
*/
|
||||
public Boolean addNode(LodQuadTreeNode lodNode)
|
||||
{
|
||||
int[] temp = LodUtil.convertAbsolutePosToQuadTreeRelativePos(lodNode.posX, lodNode.posZ, lodNode.detailLevel, LodQuadTreeNode.REGION_LEVEL);
|
||||
// don't continue if the region can't be saved
|
||||
RegionPos regionPos = new RegionPos(temp[0],temp[1]);
|
||||
RegionPos regionPos = LodUtil.convertGenericPosToRegionPos(lodNode.posX, lodNode.posZ, lodNode.detailLevel);
|
||||
if (!regionIsInRange(regionPos.x, regionPos.z))
|
||||
{
|
||||
return false;
|
||||
@@ -385,8 +384,7 @@ public class LodQuadTreeDimension
|
||||
if (detailLevel > LodQuadTreeNode.REGION_LEVEL)
|
||||
throw new IllegalArgumentException("getLodFromCoordinates given a level of \"" + detailLevel + "\" when \"" + LodQuadTreeNode.REGION_LEVEL + "\" is the max.");
|
||||
|
||||
int[] relativePos = LodUtil.convertAbsolutePosToQuadTreeRelativePos(chunkPos.x, chunkPos.z, LodQuadTreeNode.CHUNK_LEVEL);
|
||||
LodQuadTree region = getRegion(new RegionPos(relativePos[0], relativePos[1]));
|
||||
LodQuadTree region = getRegion(LodUtil.convertGenericPosToRegionPos(chunkPos.x, chunkPos.z, LodQuadTreeNode.CHUNK_LEVEL));
|
||||
|
||||
if(region == null)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.io.File;
|
||||
|
||||
import com.seibel.lod.objects.LodQuadTreeNode;
|
||||
|
||||
import com.seibel.lod.objects.RegionPos;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.server.integrated.IntegratedServer;
|
||||
@@ -97,23 +98,22 @@ public class LodUtil
|
||||
/**
|
||||
* Convert a 2D absolute position into a quad tree relative position.
|
||||
*/
|
||||
public static int[] convertAbsolutePosToQuadTreeRelativePos(int x, int z, int detailLevel)
|
||||
public static RegionPos convertGenericPosToRegionPos(int x, int z, int detailLevel)
|
||||
{
|
||||
int relativePosX = Math.floorDiv(x, (int) Math.pow(2, LodQuadTreeNode.REGION_LEVEL - detailLevel));
|
||||
int relativePosZ = Math.floorDiv(z, (int) Math.pow(2, LodQuadTreeNode.REGION_LEVEL - detailLevel));
|
||||
|
||||
return new int[] {relativePosX, relativePosZ};
|
||||
return new RegionPos(relativePosX, relativePosZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a 2D absolute position into a quad tree relative position.
|
||||
*/
|
||||
public static int[] convertAbsolutePosToQuadTreeRelativePos(int x, int z, int currectDetailLevel, int targetDetailLevel)
|
||||
public static int convertLevelPos(int pos, int currectDetailLevel, int targetDetailLevel)
|
||||
{
|
||||
int relativePosX = Math.floorDiv(x, (int) Math.pow(2, targetDetailLevel - currectDetailLevel));
|
||||
int relativePosZ = Math.floorDiv(z, (int) Math.pow(2, targetDetailLevel - currectDetailLevel));
|
||||
int newPos = Math.floorDiv(pos, (int) Math.pow(2, targetDetailLevel - currectDetailLevel));
|
||||
|
||||
return new int[] {relativePosX, relativePosZ};
|
||||
return newPos;
|
||||
}
|
||||
/**
|
||||
* Return whether the given chunk
|
||||
|
||||
Reference in New Issue
Block a user