Fix race & stuck playerData in sub-dim, add dataPoint verify
This commit is contained in:
+4
@@ -51,6 +51,10 @@ public class CubicLodTemplate
|
||||
short dy = (short) (DataPointUtil.getHeight(data) - y);
|
||||
if (dy == 0)
|
||||
return;
|
||||
if (dy < 0)
|
||||
{
|
||||
throw new IllegalArgumentException("Negative y size for the data! Data: " + DataPointUtil.toString(data));
|
||||
}
|
||||
|
||||
int color;
|
||||
if (debugging != DebugMode.OFF && debugging != DebugMode.SHOW_WIREFRAME)
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Used to guess the world folder for the player's current dimension.
|
||||
@@ -56,7 +57,7 @@ public class LodDimensionFinder
|
||||
private volatile LodDimension foundLodDimension = null;
|
||||
|
||||
/** If true the LodDimensionFileHelper is attempting to determine the folder for this dimension */
|
||||
private boolean determiningWorldFolder = false;
|
||||
private AtomicBoolean determiningWorldFolder = new AtomicBoolean(false);
|
||||
|
||||
|
||||
|
||||
@@ -88,11 +89,11 @@ public class LodDimensionFinder
|
||||
public void AttemptToDetermineSubDimensionAsync(IDimensionTypeWrapper dimensionTypeWrapper)
|
||||
{
|
||||
// prevent multiple threads running at the same time
|
||||
if (determiningWorldFolder && !isDone())
|
||||
boolean v = determiningWorldFolder.getAndSet(true);
|
||||
if (v) {
|
||||
return;
|
||||
determiningWorldFolder = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// run asynchronously since this could take a while
|
||||
Thread thread = new Thread(() ->
|
||||
{
|
||||
@@ -127,7 +128,7 @@ public class LodDimensionFinder
|
||||
finally
|
||||
{
|
||||
// make sure we unlock this method
|
||||
determiningWorldFolder = false;
|
||||
determiningWorldFolder.set(false);
|
||||
}
|
||||
});
|
||||
thread.setName(THREAD_NAME);
|
||||
@@ -151,7 +152,7 @@ public class LodDimensionFinder
|
||||
}
|
||||
|
||||
// relevant positions
|
||||
AbstractChunkPosWrapper playerChunkPos = FACTORY.createChunkPos(firstSeenPlayerData.playerBlockPos);
|
||||
AbstractChunkPosWrapper playerChunkPos = FACTORY.createChunkPos(playerData.playerBlockPos);
|
||||
int startingBlockPosX = playerChunkPos.getMinBlockX();
|
||||
int startingBlockPosZ = playerChunkPos.getMinBlockZ();
|
||||
RegionPos playerRegionPos = new RegionPos(playerChunkPos);
|
||||
@@ -177,7 +178,7 @@ public class LodDimensionFinder
|
||||
|
||||
// log the start of this attempt
|
||||
LOGGER.info("Attempting to determine sub-dimension for [" + MC.getCurrentDimension().getDimensionName() + "]");
|
||||
LOGGER.info("First seen player block pos in dimension: [" + firstSeenPlayerData.playerBlockPos.getX() + "," + firstSeenPlayerData.playerBlockPos.getY() + "," + firstSeenPlayerData.playerBlockPos.getZ() + "]");
|
||||
LOGGER.info("Player block pos in dimension: [" + playerData.playerBlockPos.getX() + "," + playerData.playerBlockPos.getY() + "," + playerData.playerBlockPos.getZ() + "]");
|
||||
|
||||
|
||||
// new chunk data
|
||||
@@ -269,7 +270,7 @@ public class LodDimensionFinder
|
||||
LOGGER.info("Last known player pos: [" + testPlayerData.playerBlockPos.getX() + "," + testPlayerData.playerBlockPos.getY() + "," + testPlayerData.playerBlockPos.getZ() + "]");
|
||||
|
||||
// check if the block positions are close
|
||||
int playerBlockDist = testPlayerData.playerBlockPos.getManhattanDistance(firstSeenPlayerData.playerBlockPos);
|
||||
int playerBlockDist = testPlayerData.playerBlockPos.getManhattanDistance(playerData.playerBlockPos);
|
||||
ApiShared.LOGGER.info("Player block position distance between saved sub dimension and first seen is [" + playerBlockDist + "]");
|
||||
|
||||
|
||||
|
||||
@@ -108,6 +108,27 @@ public class DataPointUtil
|
||||
{
|
||||
if (generationMode == 0)
|
||||
throw new IllegalArgumentException("Trying to create datapoint with genMode 0, which is NOT allowed in DataPoint version 10!");
|
||||
if (height < 0 || height > 4096)
|
||||
throw new IllegalArgumentException("Height must be between 0 and 4096!");
|
||||
if (depth < 0 || depth > 4096)
|
||||
throw new IllegalArgumentException("Depth must be between 0 and 4096!");
|
||||
if (lightSky < 0 || lightSky > 15)
|
||||
throw new IllegalArgumentException("Sky light must be between 0 and 15!");
|
||||
if (lightBlock < 0 || lightBlock > 15)
|
||||
throw new IllegalArgumentException("Block light must be between 0 and 15!");
|
||||
if (alpha < 0 || alpha > 255)
|
||||
throw new IllegalArgumentException("Alpha must be between 0 and 255!");
|
||||
if (red < 0 || red > 255)
|
||||
throw new IllegalArgumentException("Red must be between 0 and 255!");
|
||||
if (green < 0 || green > 255)
|
||||
throw new IllegalArgumentException("Green must be between 0 and 255!");
|
||||
if (blue < 0 || blue > 255)
|
||||
throw new IllegalArgumentException("Blue must be between 0 and 255!");
|
||||
if (generationMode < 0 || generationMode > 7)
|
||||
throw new IllegalArgumentException("Generation mode must be between 0 and 7!");
|
||||
if (depth > height)
|
||||
throw new IllegalArgumentException("Depth must be less than or equal to height!");
|
||||
|
||||
return (long) (alpha >>> ALPHA_DOWNSIZE_SHIFT) << ALPHA_SHIFT
|
||||
| (red & RED_MASK) << RED_SHIFT
|
||||
| (green & GREEN_MASK) << GREEN_SHIFT
|
||||
@@ -249,7 +270,7 @@ public class DataPointUtil
|
||||
arraySize *= packetSize;
|
||||
//remove comment to not leave garbage at the end
|
||||
//array[start + packetSize + i] = 0;
|
||||
if (arraySize - start >= 0) System.arraycopy(array, start + length + 0, array, start + 0, arraySize - start);
|
||||
if (arraySize - start >= 0) System.arraycopy(array, start + length, array, start, arraySize - start);
|
||||
}
|
||||
|
||||
public static void extendArray(short[] array, int packetSize, int start, int length, int arraySize)
|
||||
|
||||
Reference in New Issue
Block a user