Skip to content

Commit

Permalink
Return missing model for null BlockState
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Jun 5, 2023
1 parent 5475900 commit b430b67
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit b430b67

Please sign in to comment.