Use ImmutableMap for model location cache since it never changes
This commit is contained in:
parent
395e14ba9b
commit
b20705a4c4
|
|
@ -1,5 +1,6 @@
|
|||
package org.embeddedt.modernfix.dynamicresources;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import net.minecraft.Util;
|
||||
|
|
@ -10,13 +11,13 @@ import net.minecraft.world.level.block.Block;
|
|||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ModelLocationCache {
|
||||
private static final Map<BlockState, ModelResourceLocation> locationCache = new Object2ObjectOpenHashMap<>();
|
||||
private static Map<BlockState, ModelResourceLocation> locationCache = Collections.emptyMap();
|
||||
public static void rebuildLocationCache() {
|
||||
locationCache.clear();
|
||||
ArrayList<CompletableFuture<Pair<BlockState, ModelResourceLocation>>> futures = new ArrayList<>();
|
||||
for(Block block : Registry.BLOCK) {
|
||||
block.getStateDefinition().getPossibleStates().forEach((state) -> {
|
||||
|
|
@ -25,10 +26,13 @@ public class ModelLocationCache {
|
|||
}, Util.backgroundExecutor()));
|
||||
});
|
||||
}
|
||||
|
||||
ImmutableMap.Builder<BlockState, ModelResourceLocation> builder = ImmutableMap.builder();
|
||||
for(CompletableFuture<Pair<BlockState, ModelResourceLocation>> future : futures) {
|
||||
Pair<BlockState, ModelResourceLocation> pair = future.join();
|
||||
locationCache.put(pair.getFirst(), pair.getSecond());
|
||||
builder.put(pair.getFirst(), pair.getSecond());
|
||||
}
|
||||
locationCache = builder.build();
|
||||
}
|
||||
|
||||
public static ModelResourceLocation get(BlockState state) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user