Skip dynamic resources single blockstate optimization when outside world

This should improve performance of model baking events during launch
This commit is contained in:
embeddedt 2023-07-30 12:49:43 -04:00
parent 92a204c253
commit 377f59847e
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 4 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import com.google.common.collect.ImmutableList;
import com.mojang.math.Transformation;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import net.fabricmc.fabric.impl.client.model.ModelLoadingRegistryImpl;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.BlockModelDefinition;
import net.minecraft.client.renderer.block.model.ItemModelGenerator;
@ -443,7 +444,7 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
@Redirect(method = "loadModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/StateDefinition;getPossibleStates()Lcom/google/common/collect/ImmutableList;"))
private ImmutableList<BlockState> loadOnlyRelevantBlockState(StateDefinition<Block, BlockState> stateDefinition, ResourceLocation location) {
if(this.inTextureGatheringPass || !(location instanceof ModelResourceLocation))
if(this.inTextureGatheringPass || !(location instanceof ModelResourceLocation) || Minecraft.getInstance().level == null)
return stateDefinition.getPossibleStates();
else
return ModelBakeryHelpers.getBlockStatesForMRL(stateDefinition, (ModelResourceLocation)location);

View File

@ -6,6 +6,7 @@ import com.google.common.cache.RemovalNotification;
import com.google.common.collect.ImmutableList;
import com.google.gson.JsonElement;
import com.mojang.math.Transformation;
import net.minecraft.client.Minecraft;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.ItemModelGenerator;
@ -305,7 +306,7 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
}
@Redirect(method = "loadModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/StateDefinition;getPossibleStates()Lcom/google/common/collect/ImmutableList;"))
private ImmutableList<BlockState> loadOnlyRelevantBlockState(StateDefinition<Block, BlockState> stateDefinition, ResourceLocation location) {
if(!(location instanceof ModelResourceLocation))
if(!(location instanceof ModelResourceLocation) || Minecraft.getInstance().level == null)
return stateDefinition.getPossibleStates();
return ModelBakeryHelpers.getBlockStatesForMRL(stateDefinition, (ModelResourceLocation)location);
}