rename FullDataPointIdMap setAndGetId -> addIfNotPresentAndGetId

This commit is contained in:
James Seibel
2022-10-02 21:42:02 -05:00
parent 9fcced23e4
commit b8af1794a6
2 changed files with 10 additions and 7 deletions
@@ -16,7 +16,7 @@ import java.util.concurrent.ConcurrentHashMap;
* Used to map a numerical ID to a Biome/BlockState pair.
*
* @author Leetom
* @version 2022-9-30
* @version 2022-10-2
*/
public class FullDataPointIdMap
{
@@ -28,9 +28,12 @@ public class FullDataPointIdMap
public IBiomeWrapper getBiomeWrapper(int id) { return entries.get(id).biome; }
public IBlockStateWrapper getBlockStateWrapper(int id) { return entries.get(id).blockState; }
/** Adds a new entry to the map and returns its numerical ID */
public int setAndGetId(IBiomeWrapper biome, IBlockStateWrapper blockState) { return setAndGetId(new Entry(biome, blockState)); }
private int setAndGetId(Entry biomeBlockStateEntry)
/**
* If an entry with the given values already exists nothing will
* be added but the existing item's ID will still be returned.
*/
public int addIfNotPresentAndGetId(IBiomeWrapper biome, IBlockStateWrapper blockState) { return addIfNotPresentAndGetId(new Entry(biome, blockState)); }
private int addIfNotPresentAndGetId(Entry biomeBlockStateEntry)
{
return idMap.computeIfAbsent(biomeBlockStateEntry, (entry) -> {
int id = entries.size();
@@ -51,7 +54,7 @@ public class FullDataPointIdMap
int[] remappedEntryIds = new int[entriesToMerge.size()];
for (int i = 0; i < entriesToMerge.size(); i++)
{
remappedEntryIds[i] = setAndGetId(entriesToMerge.get(i));
remappedEntryIds[i] = addIfNotPresentAndGetId(entriesToMerge.get(i));
}
return remappedEntryIds;
}
@@ -23,7 +23,7 @@ public class LodDataBuilder {
int lastY = chunk.getMaxBuildHeight();
IBiomeWrapper biome = chunk.getBiome(x, lastY, z);
IBlockStateWrapper blockState = AIR;
int mappedId = chunkData.getMapping().setAndGetId(biome, blockState);
int mappedId = chunkData.getMapping().addIfNotPresentAndGetId(biome, blockState);
// FIXME: The +1 offset to reproduce the old behavior. Remove this when we get per-face lighting
byte light = (byte) ((chunk.getBlockLight(x,lastY+1,z) << 4) + chunk.getSkyLight(x,lastY+1,z));
int y=chunk.getMaxY(x, z);
@@ -37,7 +37,7 @@ public class LodDataBuilder {
longs.add(FullDataPoint.encode(mappedId, lastY-y, y+1 - chunk.getMinBuildHeight(), light));
biome = newBiome;
blockState = newBlockState;
mappedId = chunkData.getMapping().setAndGetId(biome, blockState);
mappedId = chunkData.getMapping().addIfNotPresentAndGetId(biome, blockState);
light = newLight;
lastY = y;
}