From ae829cbe3e915bb834cc5b933f480e252d76b0fb Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 6 Apr 2024 07:54:47 -0500 Subject: [PATCH] Fix legacy migration conversion column order --- .../fullData/sources/FullDataSourceV2.java | 65 +++++++++++-------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV2.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV2.java index 4e3a57031..65b7ca659 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV2.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV2.java @@ -161,18 +161,18 @@ public class FullDataSourceV2 implements IDataSource { for (int z = 0; z < WIDTH; z++) { - long[] dataColumn = legacyData.get(x, z); - if (dataColumn != null && dataColumn.length != 0) + long[] legacyDataColumn = legacyData.get(x, z); + if (legacyDataColumn != null && legacyDataColumn.length != 0) { int index = relativePosToIndex(x, z); - dataPoints[index] = new LongArrayList(dataColumn); + LongArrayList newDataColumn = new LongArrayList(legacyDataColumn); // convert the data point format boolean columnHasNonAirBlock = false; - for (int i = 0; i < dataColumn.length; i++) + for (int i = 0; i < legacyDataColumn.length; i++) { - long dataPoint = dataColumn[i]; + long dataPoint = legacyDataColumn[i]; int id = FullDataPointUtilV1.getId(dataPoint); int height = FullDataPointUtilV1.getHeight(dataPoint); @@ -188,7 +188,7 @@ public class FullDataSourceV2 implements IDataSource } long newDataPoint = FullDataPointUtilV2.encode(id, height, bottomY, blockLight, skyLight); - dataColumn[i] = newDataPoint; + newDataColumn.set(i, newDataPoint); // check if this datapoint is air @@ -198,6 +198,11 @@ public class FullDataSourceV2 implements IDataSource } } + + // save the converted data point + ensureDataColumnOrder(newDataColumn); + dataPoints[index] = newDataColumn; + // the old data sources didn't have a generation step written down // if the column has any data points, assume it's fully generated, otherwise assume it's empty columnGenerationSteps[index] = (columnHasNonAirBlock ? EDhApiWorldGenerationStep.LIGHT.value : EDhApiWorldGenerationStep.EMPTY.value); @@ -627,30 +632,10 @@ public class FullDataSourceV2 implements IDataSource } - // flip the array if necessary // TODO why is this sometimes necessary? What did I (James) screw up that causes the mergedInputDataArray // to sometimes be in a different order? Is it potentially related to what detail level is coming in? - { - long firstDataPoint = newColumnList.getLong(0); - int firstBottomY = FullDataPointUtilV2.getBottomY(firstDataPoint); - - long lastDataPoint = newColumnList.getLong(newColumnList.size() - 1); - int lastBottomY = FullDataPointUtilV2.getBottomY(lastDataPoint); - - if (firstBottomY < lastBottomY) - { - // reverse the array so index 0 is the highest, - // this is necessary for later logic - // source: https://stackoverflow.com/questions/2137755/how-do-i-reverse-an-int-array-in-java - for(int i = 0; i < newColumnList.size() / 2; i++) - { - long temp = newColumnList.getLong(i); - newColumnList.set(i, newColumnList.getLong(newColumnList.size() - i - 1)); - newColumnList.set(newColumnList.size() - i - 1, temp); - } - } - } + ensureDataColumnOrder(newColumnList); return newColumnList; } @@ -792,6 +777,32 @@ public class FullDataSourceV2 implements IDataSource } } + /** + * Ensures the given data column is in the correct Y order, specifically + * top-to-bottom. + */ + private static void ensureDataColumnOrder(LongArrayList dataColumn) + { + long firstDataPoint = dataColumn.getLong(0); + int firstBottomY = FullDataPointUtilV2.getBottomY(firstDataPoint); + + long lastDataPoint = dataColumn.getLong(dataColumn.size() - 1); + int lastBottomY = FullDataPointUtilV2.getBottomY(lastDataPoint); + + if (firstBottomY < lastBottomY) + { + // reverse the array so index 0 is the highest, + // this is necessary for later logic + // source: https://stackoverflow.com/questions/2137755/how-do-i-reverse-an-int-array-in-java + for(int i = 0; i < dataColumn.size() / 2; i++) + { + long temp = dataColumn.getLong(i); + dataColumn.set(i, dataColumn.getLong(dataColumn.size() - i - 1)); + dataColumn.set(dataColumn.size() - i - 1, temp); + } + } + } + //=========//