From 3292a1cf4fa9ad63d8bc0c49b89241aa59bc565b Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Thu, 28 Dec 2023 15:45:59 +0100 Subject: [PATCH] Fix EmptyModel.BAKED returning null quad list (#434) A `SimpleBakedModel` must always have a quad list for each face. If a `null` list is returned the game will typically crash (as I found out by using `EmptyModel.BAKED` in a mod of mine). --- .../neoforge/client/model/EmptyModel.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/neoforged/neoforge/client/model/EmptyModel.java b/src/main/java/net/neoforged/neoforge/client/model/EmptyModel.java index f67780f8a5..3ab7a6a5ef 100644 --- a/src/main/java/net/neoforged/neoforge/client/model/EmptyModel.java +++ b/src/main/java/net/neoforged/neoforge/client/model/EmptyModel.java @@ -5,9 +5,11 @@ package net.neoforged.neoforge.client.model; +import java.util.EnumMap; import java.util.List; import java.util.Map; import java.util.function.Function; +import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.ItemOverrides; import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite; @@ -18,6 +20,7 @@ import net.minecraft.client.resources.model.ModelBaker; import net.minecraft.client.resources.model.ModelState; import net.minecraft.client.resources.model.SimpleBakedModel; +import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; import net.neoforged.neoforge.client.RenderTypeGroup; import net.neoforged.neoforge.client.model.geometry.IGeometryBakingContext; @@ -51,8 +54,17 @@ public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Functio private static class Baked extends SimpleBakedModel { private static final Material MISSING_TEXTURE = new Material(TextureAtlas.LOCATION_BLOCKS, MissingTextureAtlasSprite.getLocation()); + // SimpleBakedModel must have a quad list per face in its map. + private static Map> makeEmptyCulledFaces() { + Map> map = new EnumMap<>(Direction.class); + for (Direction direction : Direction.values()) { + map.put(direction, List.of()); + } + return map; + } + public Baked() { - super(List.of(), Map.of(), false, false, false, UnitTextureAtlasSprite.INSTANCE, ItemTransforms.NO_TRANSFORMS, ItemOverrides.EMPTY, RenderTypeGroup.EMPTY); + super(List.of(), makeEmptyCulledFaces(), false, false, false, UnitTextureAtlasSprite.INSTANCE, ItemTransforms.NO_TRANSFORMS, ItemOverrides.EMPTY, RenderTypeGroup.EMPTY); } @Override