Skip to content

Commit 66a93ce

Browse files
committed
Add caching for key-mapping
1 parent fcd3927 commit 66a93ce

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

  • core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack

core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/ResourcePack.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public interface Extension<T extends ResourcePackExtension> extends Keyed {
8787

8888
@Getter private final BlockColorCalculatorFactory colorCalculatorFactory;
8989
private final BlockPropertiesConfig blockPropertiesConfig;
90+
91+
private final LoadingCache<de.bluecolored.bluemap.core.world.BlockState, BlockState> blockStateCache;
9092
private final LoadingCache<de.bluecolored.bluemap.core.world.BlockState, BlockProperties> blockPropertiesCache;
9193

9294
private final Map<Extension<?>, ResourcePackExtension> extensions;
@@ -104,6 +106,11 @@ public ResourcePack(PackVersion packVersion) {
104106
this.colorCalculatorFactory = new BlockColorCalculatorFactory();
105107
this.blockPropertiesConfig = new BlockPropertiesConfig();
106108

109+
this.blockStateCache = Caffeine.newBuilder()
110+
.executor(BlueMap.THREAD_POOL)
111+
.maximumSize(10000)
112+
.expireAfterAccess(1, TimeUnit.MINUTES)
113+
.build(this::loadBlockState);
107114
this.blockPropertiesCache = Caffeine.newBuilder()
108115
.executor(BlueMap.THREAD_POOL)
109116
.maximumSize(10000)
@@ -356,6 +363,10 @@ private Atlas getBlocksAtlas() {
356363
}
357364

358365
public BlockState getBlockState(de.bluecolored.bluemap.core.world.BlockState blockState) {
366+
return blockStateCache.get(blockState);
367+
}
368+
369+
private BlockState loadBlockState(de.bluecolored.bluemap.core.world.BlockState blockState) {
359370
Key key = blockState.getId();
360371
for (ResourcePackExtension extension : extensions.values()) {
361372
key = extension.getBlockStateKey(key);

0 commit comments

Comments
 (0)