From b8af1794a63b97e83abace6c3ed2fd41805ff7e9 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sun, 2 Oct 2022 21:42:02 -0500 Subject: [PATCH] rename FullDataPointIdMap setAndGetId -> addIfNotPresentAndGetId --- .../lod/core/datatype/full/FullDataPointIdMap.java | 13 ++++++++----- .../lod/core/datatype/transform/LodDataBuilder.java | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/com/seibel/lod/core/datatype/full/FullDataPointIdMap.java b/core/src/main/java/com/seibel/lod/core/datatype/full/FullDataPointIdMap.java index 00aa84a6f..c0af3691a 100644 --- a/core/src/main/java/com/seibel/lod/core/datatype/full/FullDataPointIdMap.java +++ b/core/src/main/java/com/seibel/lod/core/datatype/full/FullDataPointIdMap.java @@ -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; } diff --git a/core/src/main/java/com/seibel/lod/core/datatype/transform/LodDataBuilder.java b/core/src/main/java/com/seibel/lod/core/datatype/transform/LodDataBuilder.java index fd3b914d1..7b1fd19ab 100644 --- a/core/src/main/java/com/seibel/lod/core/datatype/transform/LodDataBuilder.java +++ b/core/src/main/java/com/seibel/lod/core/datatype/transform/LodDataBuilder.java @@ -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; }