From b430b670524793d15bc47475a9b4b44a05e983be Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Mon, 5 Jun 2023 19:43:25 -0400 Subject: [PATCH] Return missing model for null BlockState --- .../perf/dynamic_resources/BlockModelShaperMixin.java | 8 +++++++- .../modernfix/dynamicresources/ModelLocationCache.java | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/BlockModelShaperMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/BlockModelShaperMixin.java index c5c70db9c..3f737e530 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/BlockModelShaperMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/BlockModelShaperMixin.java @@ -3,6 +3,7 @@ import net.minecraft.client.renderer.block.BlockModelShaper; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.ModelManager; +import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.world.level.block.state.BlockState; import org.embeddedt.modernfix.annotation.ClientOnlyMixin; import org.embeddedt.modernfix.dynamicresources.ModelLocationCache; @@ -37,9 +38,14 @@ private void replaceModelMap(CallbackInfo ci) { public void rebuildCache() { } + /** + * @author embeddedt + * @reason get the model from the dynamic model provider + */ @Overwrite public BakedModel getBlockModel(BlockState state) { - BakedModel model = modelManager.getModel(ModelLocationCache.get(state)); + ModelResourceLocation mrl = ModelLocationCache.get(state); + BakedModel model = mrl == null ? null : modelManager.getModel(mrl); if (model == null) { model = modelManager.getMissingModel(); } diff --git a/common/src/main/java/org/embeddedt/modernfix/dynamicresources/ModelLocationCache.java b/common/src/main/java/org/embeddedt/modernfix/dynamicresources/ModelLocationCache.java index 7370d58a0..2d737bbde 100644 --- a/common/src/main/java/org/embeddedt/modernfix/dynamicresources/ModelLocationCache.java +++ b/common/src/main/java/org/embeddedt/modernfix/dynamicresources/ModelLocationCache.java @@ -31,6 +31,8 @@ public ModelResourceLocation load(Item key) throws Exception { }); public static ModelResourceLocation get(BlockState state) { + if(state == null) + return null; try { return blockLocationCache.get(state); } catch(ExecutionException e) { @@ -39,6 +41,8 @@ public static ModelResourceLocation get(BlockState state) { } public static ModelResourceLocation get(Item item) { + if(item == null) + return null; try { return itemLocationCache.get(item); } catch(ExecutionException e) {