Parallel model loading
This commit is contained in:
parent
b5ebabd824
commit
185da209ce
1 changed files with 32 additions and 25 deletions
|
@ -1,5 +1,6 @@
|
|||
package ru.bclib.mixin.client;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.renderer.block.BlockModelShaper;
|
||||
|
@ -47,11 +48,10 @@ public abstract class ModelBakeryMixin {
|
|||
)
|
||||
)
|
||||
private void bclib_initCustomModels(ResourceManager resourceManager, BlockColors blockColors, ProfilerFiller profiler, int mipmap, CallbackInfo info) {
|
||||
Map<ResourceLocation, UnbakedModel> cache = Maps.newHashMap();
|
||||
Map<ResourceLocation, UnbakedModel> topLevel = Maps.newHashMap();
|
||||
Map<ResourceLocation, UnbakedModel> cache = Maps.newConcurrentMap();
|
||||
Map<ResourceLocation, UnbakedModel> topLevel = Maps.newConcurrentMap();
|
||||
|
||||
Registry.BLOCK.forEach(block -> {
|
||||
if (block instanceof BlockModelProvider) {
|
||||
Registry.BLOCK.stream().filter(block -> block instanceof BlockModelProvider).parallel().forEach(block -> {
|
||||
ResourceLocation blockID = Registry.BLOCK.getKey(block);
|
||||
ResourceLocation storageID = new ResourceLocation(blockID.getNamespace(), "blockstates/" + blockID.getPath() + ".json");
|
||||
BlockModelProvider provider = (BlockModelProvider) block;
|
||||
|
@ -64,12 +64,20 @@ public abstract class ModelBakeryMixin {
|
|||
cache.put(blockID, defaultModel);
|
||||
topLevel.put(blockID, defaultModel);
|
||||
|
||||
block.getStateDefinition().getPossibleStates().forEach(blockState -> {
|
||||
ImmutableList<BlockState> states = block.getStateDefinition().getPossibleStates();
|
||||
if (states.size() == 1) {
|
||||
ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, block.defaultBlockState());
|
||||
cache.put(stateID, defaultModel);
|
||||
topLevel.put(stateID, defaultModel);
|
||||
}
|
||||
else {
|
||||
states.forEach(blockState -> {
|
||||
ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, blockState);
|
||||
BlockModel model = provider.getBlockModel(stateID, blockState);
|
||||
cache.put(stateID, model != null ? model : defaultModel);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (Registry.ITEM.get(blockID) != Items.AIR) {
|
||||
storageID = new ResourceLocation(blockID.getNamespace(), "models/item/" + blockID.getPath() + ".json");
|
||||
|
@ -80,7 +88,6 @@ public abstract class ModelBakeryMixin {
|
|||
topLevel.put(itemID, model);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Registry.ITEM.forEach(item -> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue