Slight abstraction on id gen
This commit is contained in:
@@ -176,12 +176,7 @@ public class Mapper {
|
|||||||
//TODO:FIXME: IS VERY SLOW NEED TO MAKE IT LOCK FREE, or at minimum use a concurrent map
|
//TODO:FIXME: IS VERY SLOW NEED TO MAKE IT LOCK FREE, or at minimum use a concurrent map
|
||||||
public long getBaseId(byte light, BlockState state, RegistryEntry<Biome> biome) {
|
public long getBaseId(byte light, BlockState state, RegistryEntry<Biome> biome) {
|
||||||
if (state.isAir()) return ((long)light)<<56;//Special case and fast return for air, dont care about the biome
|
if (state.isAir()) return ((long)light)<<56;//Special case and fast return for air, dont care about the biome
|
||||||
StateEntry sentry = this.block2stateEntry.computeIfAbsent(state, this::registerNewBlockState);
|
return composeMappingId(light, this.getIdForBlockState(state), this.getIdForBiome(biome));
|
||||||
|
|
||||||
String biomeId = biome.getKey().get().getValue().toString();
|
|
||||||
BiomeEntry bentry = this.biome2biomeEntry.computeIfAbsent(biomeId, this::registerNewBiome);
|
|
||||||
|
|
||||||
return (Byte.toUnsignedLong(light)<<56)|(Integer.toUnsignedLong(bentry.id) << 47)|(Integer.toUnsignedLong(sentry.id)<<27);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockState getBlockStateFromId(long id) {
|
public BlockState getBlockStateFromId(long id) {
|
||||||
@@ -189,12 +184,20 @@ public class Mapper {
|
|||||||
return this.blockId2stateEntry.get(blockId).state;
|
return this.blockId2stateEntry.get(blockId).state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIdFromBlockState(BlockState state) {
|
public int getIdForBlockState(BlockState state) {
|
||||||
var entry = this.block2stateEntry.get(state);
|
return this.block2stateEntry.computeIfAbsent(state, this::registerNewBlockState).id;
|
||||||
if (entry == null) {
|
}
|
||||||
return -1;
|
|
||||||
|
public int getIdForBiome(RegistryEntry<Biome> biome) {
|
||||||
|
String biomeId = biome.getKey().get().getValue().toString();
|
||||||
|
return this.biome2biomeEntry.computeIfAbsent(biomeId, this::registerNewBiome).id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long composeMappingId(byte light, int blockId, int biomeId) {
|
||||||
|
if (blockId == AIR) {//Dont care about biome for air
|
||||||
|
return Byte.toUnsignedLong(light)<<56;
|
||||||
}
|
}
|
||||||
return entry.id;
|
return (Byte.toUnsignedLong(light)<<56)|(Integer.toUnsignedLong(blockId) << 47)|(Integer.toUnsignedLong(biomeId)<<27);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: fixme: synchronize access to this.blockId2stateEntry
|
//TODO: fixme: synchronize access to this.blockId2stateEntry
|
||||||
|
|||||||
Reference in New Issue
Block a user