Remove FullDataPointUtilV2

Not sure what happened to make me think we needed to change the data point format, but luckily we don't have to deal with it any more and can just stick with the single file.
This commit is contained in:
James Seibel
2024-04-06 08:17:09 -05:00
parent ae829cbe3e
commit ddbad36d8a
8 changed files with 68 additions and 211 deletions
@@ -32,7 +32,7 @@ import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.pos.DhLodPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.util.FullDataPointUtilV2;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.RayCastUtil;
import com.seibel.distanthorizons.core.world.AbstractDhWorld;
@@ -249,8 +249,8 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo
if (dataPoint != 0)
{
int requestedY = nullableBlockYPos;
int bottomY = FullDataPointUtilV2.getBottomY(dataPoint) + levelMinimumHeight;
int height = FullDataPointUtilV2.getHeight(dataPoint);
int bottomY = FullDataPointUtil.getBottomY(dataPoint) + levelMinimumHeight;
int height = FullDataPointUtil.getHeight(dataPoint);
int topY = bottomY + height;
// does this datapoint contain the requested Y position?
@@ -282,15 +282,15 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo
private static DhApiTerrainDataPoint generateApiDatapoint(IDhApiLevelWrapper levelWrapper, FullDataPointIdMap mapping, byte detailLevel, long dataPoint)
{
IBlockStateWrapper blockState = mapping.getBlockStateWrapper(FullDataPointUtilV2.getId(dataPoint));
IBiomeWrapper biomeWrapper = mapping.getBiomeWrapper(FullDataPointUtilV2.getId(dataPoint));
IBlockStateWrapper blockState = mapping.getBlockStateWrapper(FullDataPointUtil.getId(dataPoint));
IBiomeWrapper biomeWrapper = mapping.getBiomeWrapper(FullDataPointUtil.getId(dataPoint));
int bottomY = FullDataPointUtilV2.getBottomY(dataPoint) + levelWrapper.getMinHeight();
int height = FullDataPointUtilV2.getHeight(dataPoint);
int bottomY = FullDataPointUtil.getBottomY(dataPoint) + levelWrapper.getMinHeight();
int height = FullDataPointUtil.getHeight(dataPoint);
int topY = bottomY + height;
return new DhApiTerrainDataPoint(detailLevel,
FullDataPointUtilV2.getBlockLight(dataPoint), FullDataPointUtilV2.getSkyLight(dataPoint),
FullDataPointUtil.getBlockLight(dataPoint), FullDataPointUtil.getSkyLight(dataPoint),
topY, bottomY,
blockState, biomeWrapper);
}
@@ -25,7 +25,7 @@ import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV1DTO;
import com.seibel.distanthorizons.core.util.FullDataPointUtilV1;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataOutputStream;
@@ -43,7 +43,7 @@ import java.util.Arrays;
*
* Replaced by {@link FullDataSourceV2}.
*
* @see FullDataPointUtilV1
* @see FullDataPointUtil
* @see FullDataSourceV2
*/
public class FullDataSourceV1 implements IDataSource<IDhLevel>
@@ -29,8 +29,7 @@ import com.seibel.distanthorizons.core.file.IDataSource;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.util.FullDataPointUtilV2;
import com.seibel.distanthorizons.core.util.FullDataPointUtilV1;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
@@ -174,11 +173,11 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
{
long dataPoint = legacyDataColumn[i];
int id = FullDataPointUtilV1.getId(dataPoint);
int height = FullDataPointUtilV1.getHeight(dataPoint);
int bottomY = FullDataPointUtilV1.getBottomY(dataPoint);
byte blockLight = (byte) FullDataPointUtilV1.getBlockLight(dataPoint);
byte skyLight = (byte) FullDataPointUtilV1.getSkyLight(dataPoint);
int id = FullDataPointUtil.getId(dataPoint);
int height = FullDataPointUtil.getHeight(dataPoint);
int bottomY = FullDataPointUtil.getBottomY(dataPoint);
byte blockLight = (byte) FullDataPointUtil.getBlockLight(dataPoint);
byte skyLight = (byte) FullDataPointUtil.getSkyLight(dataPoint);
IBlockStateWrapper blockState = legacyData.mapping.getBlockStateWrapper(id);
if (blockState.isAir())
@@ -187,7 +186,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
blockLight = 0;
}
long newDataPoint = FullDataPointUtilV2.encode(id, height, bottomY, blockLight, skyLight);
long newDataPoint = FullDataPointUtil.encode(id, height, bottomY, blockLight, skyLight);
newDataColumn.set(i, newDataPoint);
@@ -551,8 +550,8 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
}
long datapoint = inputDataArray.getLong(dataPointIndex);
int datapointMinY = FullDataPointUtilV2.getBottomY(datapoint);
int numbOfBlocksTall = FullDataPointUtilV2.getHeight(datapoint);
int datapointMinY = FullDataPointUtil.getBottomY(datapoint);
int numbOfBlocksTall = FullDataPointUtil.getHeight(datapoint);
int datapointMaxY = (datapointMinY + numbOfBlocksTall);
@@ -595,9 +594,9 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
Arrays.fill(mergeSkyLights, 0);
for (int i = 0; i < 4; i++)
{
mergeIds[i] = FullDataPointUtilV2.getId(datapointsForYSlice[i]);
mergeBlockLights[i] = FullDataPointUtilV2.getBlockLight(datapointsForYSlice[i]);
mergeSkyLights[i] = FullDataPointUtilV2.getSkyLight(datapointsForYSlice[i]);
mergeIds[i] = FullDataPointUtil.getId(datapointsForYSlice[i]);
mergeBlockLights[i] = FullDataPointUtil.getBlockLight(datapointsForYSlice[i]);
mergeSkyLights[i] = FullDataPointUtil.getSkyLight(datapointsForYSlice[i]);
}
@@ -614,7 +613,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
{
if (height != 0)
{
newColumnList.add(FullDataPointUtilV2.encode(lastId, height, minY, lastBlockLight, lastSkyLight));
newColumnList.add(FullDataPointUtil.encode(lastId, height, minY, lastBlockLight, lastSkyLight));
}
lastId = id;
@@ -628,7 +627,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
// add the last slice if present
if (height != 0)
{
newColumnList.add(FullDataPointUtilV2.encode(lastId, height, minY, lastBlockLight, lastSkyLight));
newColumnList.add(FullDataPointUtil.encode(lastId, height, minY, lastBlockLight, lastSkyLight));
}
@@ -649,7 +648,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
LongArrayList dataColumn = this.dataPoints[dataPointIndex];
for (int i = 0; i < dataColumn.size(); i++)
{
dataColumn.set(i, FullDataPointUtilV2.remap(remappedIds, dataColumn.getLong(i)));
dataColumn.set(i, FullDataPointUtil.remap(remappedIds, dataColumn.getLong(i)));
}
}
private static boolean areDataColumnsDifferent(long[] oldDataArray, long[] newDataArray)
@@ -766,10 +765,10 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
public static void throwIfDataColumnInWrongOrder(DhSectionPos pos, LongArrayList dataArray) throws IllegalStateException
{
long firstDataPoint = dataArray.getLong(0);
int firstBottomY = FullDataPointUtilV2.getBottomY(firstDataPoint);
int firstBottomY = FullDataPointUtil.getBottomY(firstDataPoint);
long lastDataPoint = dataArray.getLong(dataArray.size() - 1);
int lastBottomY = FullDataPointUtilV2.getBottomY(lastDataPoint);
int lastBottomY = FullDataPointUtil.getBottomY(lastDataPoint);
if (firstBottomY < lastBottomY)
{
@@ -784,10 +783,10 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
private static void ensureDataColumnOrder(LongArrayList dataColumn)
{
long firstDataPoint = dataColumn.getLong(0);
int firstBottomY = FullDataPointUtilV2.getBottomY(firstDataPoint);
int firstBottomY = FullDataPointUtil.getBottomY(firstDataPoint);
long lastDataPoint = dataColumn.getLong(dataColumn.size() - 1);
int lastBottomY = FullDataPointUtilV2.getBottomY(lastDataPoint);
int lastBottomY = FullDataPointUtil.getBottomY(lastDataPoint);
if (firstBottomY < lastBottomY)
{
@@ -863,7 +862,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
for (int i = 0; i < longArray.size(); i++)
{
long dataPoint = longArray.getLong(i);
int id = FullDataPointUtilV2.getId(dataPoint);
int id = FullDataPointUtil.getId(dataPoint);
if (id > maxValidId)
{
LodUtil.assertNotReach("Column set with higher than possible ID. ID [" + id + "], max valid ID [" + maxValidId + "].");
@@ -31,7 +31,7 @@ import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.util.ColorUtil;
import com.seibel.distanthorizons.core.util.FullDataPointUtilV2;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
@@ -180,11 +180,11 @@ public class FullDataToRenderDataTransformer
for (int i = 0; i < fullColumnData.size(); i++)
{
long fullData = fullColumnData.getLong(i);
int bottomY = FullDataPointUtilV2.getBottomY(fullData);
int blockHeight = FullDataPointUtilV2.getHeight(fullData);
int id = FullDataPointUtilV2.getId(fullData);
int blockLight = FullDataPointUtilV2.getBlockLight(fullData);
int skyLight = FullDataPointUtilV2.getSkyLight(fullData);
int bottomY = FullDataPointUtil.getBottomY(fullData);
int blockHeight = FullDataPointUtil.getHeight(fullData);
int id = FullDataPointUtil.getId(fullData);
int blockLight = FullDataPointUtil.getBlockLight(fullData);
int skyLight = FullDataPointUtil.getSkyLight(fullData);
// TODO how should corrupted data be handled?
// TODO why is the full data corrupted in the first place? FullDataPointUtil hasn't been changed in a long time, could one of the full data point objects be corrupted?
@@ -33,7 +33,7 @@ import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.util.FullDataPointUtilV2;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
@@ -206,7 +206,7 @@ public class LodDataBuilder
// check if this block is visible from any direction
|| blockVisible(chunkWrapper, relBlockX, y, relBlockZ))
{
longs.add(FullDataPointUtilV2.encode(mappedId, lastY - y, y + 1 - chunkWrapper.getMinBuildHeight(), blockLight, skyLight));
longs.add(FullDataPointUtil.encode(mappedId, lastY - y, y + 1 - chunkWrapper.getMinBuildHeight(), blockLight, skyLight));
biome = newBiome;
blockState = newBlockState;
mappedId = dataSource.mapping.addIfNotPresentAndGetId(biome, blockState);
@@ -216,7 +216,7 @@ public class LodDataBuilder
}
}
}
longs.add(FullDataPointUtilV2.encode(mappedId, lastY - y, y + 1 - chunkWrapper.getMinBuildHeight(), blockLight, skyLight));
longs.add(FullDataPointUtil.encode(mappedId, lastY - y, y + 1 - chunkWrapper.getMinBuildHeight(), blockLight, skyLight));
dataSource.setSingleColumn(longs,
relBlockX + chunkOffsetX,
@@ -318,7 +318,7 @@ public class LodDataBuilder
(IBlockStateWrapper) (dataPoint.blockStateWrapper)
);
packedDataPoints.set(index, FullDataPointUtilV2.encode(
packedDataPoints.set(index, FullDataPointUtil.encode(
id,
dataPoint.topYBlockPos - dataPoint.bottomYBlockPos,
dataPoint.bottomYBlockPos - dataPoints.topYBlockPos,
@@ -21,7 +21,6 @@ package com.seibel.distanthorizons.core.file.subDimMatching;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.dataObjects.fullData.FullDataPointIdMap;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV1;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.file.structure.ClientOnlySaveStructure;
@@ -32,7 +31,7 @@ import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.dataObjects.transformers.LodDataBuilder;
import com.seibel.distanthorizons.core.util.FullDataPointUtilV2;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.ThreadUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
@@ -251,13 +250,13 @@ public class SubDimensionLevelMatcher implements AutoCloseable
long newDataPoint = newColumn.getLong(i);
long testDataPoint = testColumn.getLong(i);
int newId = FullDataPointUtilV2.getId(newDataPoint);
int testId = FullDataPointUtilV2.getId(testDataPoint);
int newId = FullDataPointUtil.getId(newDataPoint);
int testId = FullDataPointUtil.getId(testDataPoint);
// bottom Y
int newBottom = FullDataPointUtilV2.getBottomY(newDataPoint);
int testBottom = FullDataPointUtilV2.getBottomY(testDataPoint);
int newBottom = FullDataPointUtil.getBottomY(newDataPoint);
int testBottom = FullDataPointUtil.getBottomY(testDataPoint);
if (newBottom == testBottom)
{
equalDataPoints++;
@@ -265,8 +264,8 @@ public class SubDimensionLevelMatcher implements AutoCloseable
totalDataPointCount++;
// height
int newHeight = FullDataPointUtilV2.getHeight(newDataPoint);
int testHeight = FullDataPointUtilV2.getHeight(testDataPoint);
int newHeight = FullDataPointUtil.getHeight(newDataPoint);
int testHeight = FullDataPointUtil.getHeight(testDataPoint);
if (newHeight == testHeight)
{
equalDataPoints++;
@@ -1,24 +1,7 @@
/*
* This file is part of the Distant Horizons mod
* licensed under the GNU LGPL v3 License.
*
* Copyright (C) 2020-2023 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.distanthorizons.core.util;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV1;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.coreapi.ModInfo;
import org.jetbrains.annotations.Contract;
@@ -28,6 +11,12 @@ import org.jetbrains.annotations.Contract;
* A full data point contains the most information and is the
* source of truth used when creating render data. <br><br>
*
* Specifically used by the data sources: <br>
* - {@link FullDataSourceV2} <br>
* - {@link FullDataSourceV1} aka CompleteFullDataSource <br>
* - (Deleted) HighDetailIncompleteFullDataSource aka SparseDataSource <br>
* - (Deleted) LowDetailIncompleteFullDataSource aka SpottyDataSource <br><br>
*
* <strong>DataPoint Format: </strong><br>
* <code>
* ID: blockState id <br>
@@ -37,7 +26,7 @@ import org.jetbrains.annotations.Contract;
* SL: Sky light <br><br>
*
* =======Bit layout======= <br>
* BL BL BL BL SL SL SL SL <-- Top bits <br>
* SL SL SL SL BL BL BL BL <-- Top bits <br>
* MY MY MY MY MY MY MY MY <br>
* MY MY MY MY HI HI HI HI <br>
* HI HI HI HI HI HI HI HI <br>
@@ -46,11 +35,11 @@ import org.jetbrains.annotations.Contract;
* ID ID ID ID ID ID ID ID <br>
* ID ID ID ID ID ID ID ID <-- Bottom bits <br>
* </code>
*
* @see RenderDataPointUtil
* @see FullDataPointUtilV1
*
* @see FullDataSourceV1
* @see FullDataSourceV2
*/
public class FullDataPointUtilV2
public class FullDataPointUtil
{
public static final boolean RUN_VALIDATION = ModInfo.IS_DEV_BUILD;
@@ -60,23 +49,23 @@ public class FullDataPointUtilV2
public static final int ID_WIDTH = 32;
public static final int HEIGHT_WIDTH = 12;
public static final int MIN_Y_WIDTH = 12;
public static final int BLOCK_LIGHT_WIDTH = 4;
public static final int SKY_LIGHT_WIDTH = 4;
public static final int BLOCK_LIGHT_WIDTH = 4;
public static final int ID_OFFSET = 0;
public static final int HEIGHT_OFFSET = ID_OFFSET + ID_WIDTH;
/** indicates the Y position where the LOD starts relative to the level's minimum height */
public static final int MIN_Y_OFFSET = HEIGHT_OFFSET + HEIGHT_WIDTH;
public static final int BLOCK_LIGHT_OFFSET = MIN_Y_OFFSET + MIN_Y_WIDTH;
public static final int SKY_LIGHT_OFFSET = BLOCK_LIGHT_OFFSET + BLOCK_LIGHT_WIDTH;
public static final int SKY_LIGHT_OFFSET = MIN_Y_OFFSET + MIN_Y_WIDTH;
public static final int BLOCK_LIGHT_OFFSET = SKY_LIGHT_OFFSET + SKY_LIGHT_WIDTH;
public static final long ID_MASK = Integer.MAX_VALUE;
public static final long INVERSE_ID_MASK = ~ID_MASK;
public static final int HEIGHT_MASK = (int) Math.pow(2, HEIGHT_WIDTH) - 1;
public static final int MIN_Y_MASK = (int) Math.pow(2, MIN_Y_WIDTH) - 1;
public static final int BLOCK_LIGHT_MASK = (int) Math.pow(2, BLOCK_LIGHT_WIDTH) - 1;
public static final int SKY_LIGHT_MASK = (int) Math.pow(2, SKY_LIGHT_WIDTH) - 1;
public static final int BLOCK_LIGHT_MASK = (int) Math.pow(2, BLOCK_LIGHT_WIDTH) - 1;
/**
@@ -114,7 +103,7 @@ public class FullDataPointUtilV2
if (RUN_VALIDATION)
{
if (getId(data) != id || getHeight(data) != height || getBottomY(data) != relMinY
|| getBlockLight(data) != Byte.toUnsignedInt(blockLight) || getSkyLight(data) != Byte.toUnsignedInt(skyLight))
|| getBlockLight(data) != Byte.toUnsignedInt(blockLight) || getSkyLight(data) != Byte.toUnsignedInt(skyLight))
{
LodUtil.assertNotReach(
"Trying to create datapoint with " +
@@ -127,6 +116,7 @@ public class FullDataPointUtilV2
return data;
}
/** Returns the BlockState/Biome pair ID used to identify this LOD's color */
public static int getId(long data) { return (int) (data & ID_MASK); }
/** Returns how many blocks tall this LOD is. */
@@ -142,6 +132,8 @@ public class FullDataPointUtilV2
public static String toString(long data) { return "[ID:" + getId(data) + ",Y:" + getBottomY(data) + ",Height:" + getHeight(data) + ",BlockLight:" + getBlockLight(data) + ",SkyLight:" + getSkyLight(data) + "]"; }
/** Remaps the biome/blockState ID of the given datapoint */
@Contract(pure = true)
public static long remap(int[] newIdMapping, long data) throws IndexOutOfBoundsException
@@ -1,133 +0,0 @@
package com.seibel.distanthorizons.core.util;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV1;
import com.seibel.distanthorizons.coreapi.ModInfo;
/**
* <strong> Only for Legacy support </strong> <br>
* Used by DH versions 2.0.0 and 2.0.1. <br><br>
*
* Specifically used by the data sources: <br>
* - {@link FullDataSourceV1} aka CompleteFullDataSource <br>
* - (Deleted) HighDetailIncompleteFullDataSource <br>
* - (Deleted) LowDetailIncompleteFullDataSource <br><br>
*
* <strong>DataPoint Format: </strong><br>
* <code>
* ID: blockState id <br>
* MY: Min Y Height (unsigned, relative to the minimum level height) <br>
* HI: Height (how tall this data point is in blocks) <br>
* BL: Block light <br>
* SL: Sky light <br><br>
*
* =======Bit layout======= <br>
* SL SL SL SL BL BL BL BL <-- Top bits <br>
* MY MY MY MY MY MY MY MY <br>
* MY MY MY MY HI HI HI HI <br>
* HI HI HI HI HI HI HI HI <br>
* ID ID ID ID ID ID ID ID <br>
* ID ID ID ID ID ID ID ID <br>
* ID ID ID ID ID ID ID ID <br>
* ID ID ID ID ID ID ID ID <-- Bottom bits <br>
* </code>
*
* @see FullDataSourceV1
* @see FullDataPointUtilV2
*/
public class FullDataPointUtilV1
{
public static final boolean RUN_VALIDATION = ModInfo.IS_DEV_BUILD;
/** Represents the data held by an empty data point */
public static final int EMPTY_DATA_POINT = 0;
public static final int ID_WIDTH = 32;
public static final int HEIGHT_WIDTH = 12;
public static final int MIN_Y_WIDTH = 12;
public static final int SKY_LIGHT_WIDTH = 4;
public static final int BLOCK_LIGHT_WIDTH = 4;
public static final int ID_OFFSET = 0;
public static final int HEIGHT_OFFSET = ID_OFFSET + ID_WIDTH;
/** indicates the Y position where the LOD starts relative to the level's minimum height */
public static final int MIN_Y_OFFSET = HEIGHT_OFFSET + HEIGHT_WIDTH;
public static final int SKY_LIGHT_OFFSET = MIN_Y_OFFSET + MIN_Y_WIDTH;
public static final int BLOCK_LIGHT_OFFSET = SKY_LIGHT_OFFSET + SKY_LIGHT_WIDTH;
public static final long ID_MASK = Integer.MAX_VALUE;
public static final long INVERSE_ID_MASK = ~ID_MASK;
public static final int HEIGHT_MASK = (int) Math.pow(2, HEIGHT_WIDTH) - 1;
public static final int MIN_Y_MASK = (int) Math.pow(2, MIN_Y_WIDTH) - 1;
public static final int SKY_LIGHT_MASK = (int) Math.pow(2, SKY_LIGHT_WIDTH) - 1;
public static final int BLOCK_LIGHT_MASK = (int) Math.pow(2, BLOCK_LIGHT_WIDTH) - 1;
/**
* creates a new datapoint with the given values
* @param relMinY relative to the minimum level Y value
*
* @deprecated Should not be used anymore, just here as a reference for how the data points were constructed.
*/
@Deprecated
public static long encode(int id, int height, int relMinY, byte blockLight, byte skyLight)
{
if (RUN_VALIDATION)
{
// assertions are inside if-blocks to prevent unnecessary string concatenations
if (relMinY < 0 || relMinY >= RenderDataPointUtil.MAX_WORLD_Y_SIZE)
{
LodUtil.assertNotReach("Trying to create datapoint with y[" + relMinY + "] out of range!");
}
if (height <= 0 || height >= RenderDataPointUtil.MAX_WORLD_Y_SIZE)
{
LodUtil.assertNotReach("Trying to create datapoint with height[" + height + "] out of range!");
}
if (relMinY + height > RenderDataPointUtil.MAX_WORLD_Y_SIZE)
{
LodUtil.assertNotReach("Trying to create datapoint with y+depth[" + (relMinY + height) + "] out of range!");
}
}
long data = 0;
data |= id & ID_MASK;
data |= (long) (height & HEIGHT_MASK) << HEIGHT_OFFSET;
data |= (long) (relMinY & MIN_Y_MASK) << MIN_Y_OFFSET;
data |= (long) blockLight << BLOCK_LIGHT_OFFSET;
data |= (long) skyLight << SKY_LIGHT_OFFSET;
if (RUN_VALIDATION)
{
if (getId(data) != id || getHeight(data) != height || getBottomY(data) != relMinY
|| getBlockLight(data) != Byte.toUnsignedInt(blockLight) || getSkyLight(data) != Byte.toUnsignedInt(skyLight))
{
LodUtil.assertNotReach(
"Trying to create datapoint with " +
"id[" + id + "], height[" + height + "], minY[" + relMinY + "], blockLight[" + blockLight + "], skyLight[" + skyLight + "] " +
"but got " +
"id[" + getId(data) + "], height[" + getHeight(data) + "], minY[" + getBottomY(data) + "], blockLight[" + getBlockLight(data) + "], skyLight[" + getSkyLight(data) + "]!");
}
}
return data;
}
/** Returns the BlockState/Biome pair ID used to identify this LOD's color */
public static int getId(long data) { return (int) (data & ID_MASK); }
/** Returns how many blocks tall this LOD is. */
public static int getHeight(long data) { return (int) ((data >> HEIGHT_OFFSET) & HEIGHT_MASK); }
/**
* Returns the unsigned block position of the bottom vertices for this LOD relative to the level's minimum height.
* Should be between 0 and {@link RenderDataPointUtil#MAX_WORLD_Y_SIZE}
*/
public static int getBottomY(long data) { return (int) ((data >> MIN_Y_OFFSET) & MIN_Y_MASK); }
public static int getBlockLight(long data) { return (int) ((data >> BLOCK_LIGHT_OFFSET) & BLOCK_LIGHT_MASK); }
public static int getSkyLight(long data) { return (int) ((data >> SKY_LIGHT_OFFSET) & SKY_LIGHT_MASK); }
public static String toString(long data) { return "[ID:" + getId(data) + ",Y:" + getBottomY(data) + ",Height:" + getHeight(data) + ",BlockLight:" + getBlockLight(data) + ",SkyLight:" + getSkyLight(data) + "]"; }
}