|
17 | 17 | */ |
18 | 18 | package com.viaversion.viaversion.protocols.v1_21_4to1_21_5.storage; |
19 | 19 |
|
| 20 | +import com.google.common.cache.Cache; |
20 | 21 | import com.google.common.cache.CacheBuilder; |
21 | 22 | import com.viaversion.viaversion.api.minecraft.codec.CodecContext; |
22 | 23 | import com.viaversion.viaversion.api.minecraft.codec.CodecContext.RegistryAccess; |
|
31 | 32 | import com.viaversion.viaversion.util.SerializerVersion; |
32 | 33 | import java.util.ArrayList; |
33 | 34 | import java.util.List; |
34 | | -import java.util.Map; |
| 35 | +import java.util.concurrent.ExecutionException; |
35 | 36 |
|
36 | 37 | public class ItemHashStorage1_21_5 implements ItemHasher { |
37 | 38 |
|
38 | | - private final Map<Long, StructuredData<?>> hashToStructuredData = CacheBuilder.newBuilder().concurrencyLevel(1).maximumSize(512).<Long, StructuredData<?>>build().asMap(); |
| 39 | + private final Cache<Long, StructuredData<?>> hashToStructuredData = CacheBuilder.newBuilder().concurrencyLevel(1).maximumSize(512).build(); |
39 | 40 | private final List<String> enchantmentRegistry = new ArrayList<>(); |
40 | 41 | private boolean processingClientboundInventoryPacket; |
41 | 42 | private final CodecContext context; |
@@ -63,12 +64,16 @@ public void trackStructuredData(final StructuredData<?> structuredData) { |
63 | 64 | } |
64 | 65 |
|
65 | 66 | final long key = (long) structuredData.id() << 32 | hash; |
66 | | - this.hashToStructuredData.computeIfAbsent(key, $ -> structuredData.copy()); |
| 67 | + try { |
| 68 | + this.hashToStructuredData.get(key, structuredData::copy); |
| 69 | + } catch (final ExecutionException e) { |
| 70 | + throw new RuntimeException(e); |
| 71 | + } |
67 | 72 | } |
68 | 73 |
|
69 | 74 | public StructuredData<?> dataFromHash(final int dataComponentId, final int hash) { |
70 | 75 | final long key = (long) dataComponentId << 32 | hash; |
71 | | - final StructuredData<?> data = this.hashToStructuredData.get(key); |
| 76 | + final StructuredData<?> data = this.hashToStructuredData.getIfPresent(key); |
72 | 77 | return data != null ? data.copy() : null; |
73 | 78 | } |
74 | 79 |
|
|
0 commit comments