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;
|
package org.embeddedt.modernfix.dynamicresources;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
import net.minecraft.Util;
|
import net.minecraft.Util;
|
||||||
|
|
@ -10,13 +11,13 @@ import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class ModelLocationCache {
|
public class ModelLocationCache {
|
||||||
private static final Map<BlockState, ModelResourceLocation> locationCache = new Object2ObjectOpenHashMap<>();
|
private static Map<BlockState, ModelResourceLocation> locationCache = Collections.emptyMap();
|
||||||
public static void rebuildLocationCache() {
|
public static void rebuildLocationCache() {
|
||||||
locationCache.clear();
|
|
||||||
ArrayList<CompletableFuture<Pair<BlockState, ModelResourceLocation>>> futures = new ArrayList<>();
|
ArrayList<CompletableFuture<Pair<BlockState, ModelResourceLocation>>> futures = new ArrayList<>();
|
||||||
for(Block block : Registry.BLOCK) {
|
for(Block block : Registry.BLOCK) {
|
||||||
block.getStateDefinition().getPossibleStates().forEach((state) -> {
|
block.getStateDefinition().getPossibleStates().forEach((state) -> {
|
||||||
|
|
@ -25,10 +26,13 @@ public class ModelLocationCache {
|
||||||
}, Util.backgroundExecutor()));
|
}, Util.backgroundExecutor()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImmutableMap.Builder<BlockState, ModelResourceLocation> builder = ImmutableMap.builder();
|
||||||
for(CompletableFuture<Pair<BlockState, ModelResourceLocation>> future : futures) {
|
for(CompletableFuture<Pair<BlockState, ModelResourceLocation>> future : futures) {
|
||||||
Pair<BlockState, ModelResourceLocation> pair = future.join();
|
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) {
|
public static ModelResourceLocation get(BlockState state) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user