From c1840abb0a8b11dcf1fe863d03aa3a5d4aa53d3e Mon Sep 17 00:00:00 2001 From: David Quintana Date: Mon, 13 Jan 2020 19:38:52 +0100 Subject: [PATCH] Fix multi-layer model loader to actually work in a sane way. No more "base" model involved, and now transforms and overrides work as expected. --- .../client/model/MultiLayerModel.java | 54 +++++++++---------- .../client/model/MultiLayerModelTest.java | 2 +- .../models/block/test_layer_block.json | 15 ++---- 3 files changed, 32 insertions(+), 39 deletions(-) diff --git a/src/main/java/net/minecraftforge/client/model/MultiLayerModel.java b/src/main/java/net/minecraftforge/client/model/MultiLayerModel.java index d5a801c7f..135408bcc 100644 --- a/src/main/java/net/minecraftforge/client/model/MultiLayerModel.java +++ b/src/main/java/net/minecraftforge/client/model/MultiLayerModel.java @@ -60,12 +60,9 @@ public final class MultiLayerModel implements IModelGeometry private static final Logger LOGGER = LogManager.getLogger(); private final ImmutableMap models; - @Nullable - private final IUnbakedModel base; - public MultiLayerModel(@Nullable IUnbakedModel base, ImmutableMap models) + public MultiLayerModel(ImmutableMap models) { - this.base = base; this.models = models; } @@ -73,11 +70,9 @@ public final class MultiLayerModel implements IModelGeometry public Collection getTextures(IModelConfiguration owner, Function modelGetter, Set> missingTextureErrors) { Set materials = Sets.newHashSet(); - if (base != null) - materials.addAll(base.func_225614_a_(modelGetter, missingTextureErrors)); for (IUnbakedModel m : models.values()) materials.addAll(m.func_225614_a_(modelGetter, missingTextureErrors)); - return Collections.emptyList(); + return materials; } private static ImmutableMap buildModels(ImmutableMap models, IModelTransform modelTransform, ModelBakery bakery, Function spriteGetter, ResourceLocation modelLocation) @@ -94,27 +89,36 @@ public final class MultiLayerModel implements IModelGeometry public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation) { IUnbakedModel missing = ModelLoader.instance().getMissingModel(); + return new MultiLayerBakedModel( - base != null ? base.func_225613_a_(bakery, spriteGetter, modelTransform, modelLocation) : null, - buildModels(models, modelTransform, bakery, spriteGetter, modelLocation), - missing.func_225613_a_(bakery, spriteGetter, modelTransform, modelLocation), - PerspectiveMapWrapper.getTransforms(modelTransform) - ); + owner.useSmoothLighting(), owner.isShadedInGui(), + spriteGetter.apply(owner.resolveTexture("particle")), overrides, + buildModels(models, modelTransform, bakery, spriteGetter, modelLocation), + missing.func_225613_a_(bakery, spriteGetter, modelTransform, modelLocation), + PerspectiveMapWrapper.getTransforms(new ModelTransformComposition(owner.getCombinedTransform(), modelTransform))); } private static final class MultiLayerBakedModel implements IBakedModel { private final ImmutableMap models; private final ImmutableMap cameraTransforms; - private final IBakedModel base; + protected final boolean ambientOcclusion; + protected final boolean gui3d; + protected final TextureAtlasSprite particle; + protected final ItemOverrideList overrides; private final IBakedModel missing; - public MultiLayerBakedModel(@Nullable IBakedModel base, ImmutableMap models, IBakedModel missing, ImmutableMap cameraTransforms) + public MultiLayerBakedModel( + boolean ambientOcclusion, boolean isGui3d, TextureAtlasSprite particle, ItemOverrideList overrides, + ImmutableMap models, IBakedModel missing, ImmutableMap cameraTransforms) { this.models = models; this.cameraTransforms = cameraTransforms; this.missing = missing; - this.base = base != null ? base : missing; + this.ambientOcclusion = ambientOcclusion; + this.gui3d = isGui3d; + this.particle = particle; + this.overrides = overrides; } @Override @@ -138,38 +142,37 @@ public final class MultiLayerModel implements IModelGeometry return builder.build(); } // assumes that child model will handle this state properly. FIXME? - List quads = models.getOrDefault(layer, missing).getQuads(state, side, rand, extraData); - return quads; + return models.getOrDefault(layer, missing).getQuads(state, side, rand, extraData); } @Override public boolean isAmbientOcclusion() { - return base.isAmbientOcclusion(); + return ambientOcclusion; } @Override public boolean isAmbientOcclusion(BlockState state) { - return base.isAmbientOcclusion(state); + return ambientOcclusion; } @Override public boolean isGui3d() { - return base.isGui3d(); + return gui3d; } @Override public boolean isBuiltInRenderer() { - return base.isBuiltInRenderer(); + return false; } @Override public TextureAtlasSprite getParticleTexture() { - return base.getParticleTexture(); + return particle; } @Override @@ -208,11 +211,6 @@ public final class MultiLayerModel implements IModelGeometry { ImmutableMap.Builder builder = ImmutableMap.builder(); JsonObject layersObject = JSONUtils.getJsonObject(modelContents, "layers"); - BlockModel base = null; - if(layersObject.has("base")) - { - base = deserializationContext.deserialize(JSONUtils.getJsonObject(layersObject, "base"), BlockModel.class); - } for(RenderType layer : RenderType.func_228661_n_()) // block layers { String layerName = layer.toString(); // mc overrides toString to return the ID for the layer @@ -222,7 +220,7 @@ public final class MultiLayerModel implements IModelGeometry } } ImmutableMap models = builder.build(); - return new MultiLayerModel(base, models); + return new MultiLayerModel(models); } } } \ No newline at end of file diff --git a/src/test/java/net/minecraftforge/debug/client/model/MultiLayerModelTest.java b/src/test/java/net/minecraftforge/debug/client/model/MultiLayerModelTest.java index bc15d3635..20cee4eff 100644 --- a/src/test/java/net/minecraftforge/debug/client/model/MultiLayerModelTest.java +++ b/src/test/java/net/minecraftforge/debug/client/model/MultiLayerModelTest.java @@ -53,7 +53,7 @@ public class MultiLayerModelTest if (!ENABLED) return; event.getRegistry().register( - new Block(Block.Properties.create(Material.WOOD)) + new Block(Block.Properties.create(Material.WOOD).func_226896_b_()) { }.setRegistryName(blockId) ); diff --git a/src/test/resources/assets/forgedebugmultilayermodel/models/block/test_layer_block.json b/src/test/resources/assets/forgedebugmultilayermodel/models/block/test_layer_block.json index 7413d2d65..fa7501f28 100644 --- a/src/test/resources/assets/forgedebugmultilayermodel/models/block/test_layer_block.json +++ b/src/test/resources/assets/forgedebugmultilayermodel/models/block/test_layer_block.json @@ -2,20 +2,15 @@ "parent": "block/block", "loader": "forge:multi-layer", "layers": { - "__comment": "base is used for model properties - camera transforms, isGui3d, e.t.c.", - "base": { - "parent": "block/cube_all", - "textures": { "all": "block/slime_block" } - }, - - "__comment": "per-layer models", "solid": { "parent": "block/cube_all", "textures": { "all": "block/slime_block" }, - "transform": { "scale": 0.5 } + "transform": { "scale": 0.5, "translation": [-0.25,-0.25,-0.25] } }, "translucent": { - "parent": "minecraft:block/pink_stained_glass_pane_noside" + "parent": "block/cube_all", + "textures": { "all": "block/slime_block" } } - } + }, + "textures": { "particle": "block/slime_block" } } \ No newline at end of file