From ac210a320188800e6599b0dc7b5065fc0ef98043 Mon Sep 17 00:00:00 2001 From: Ben Staddon Date: Fri, 19 Oct 2018 00:21:26 +0100 Subject: [PATCH] Make Forge blockstate variants correctly inherit AO setting from vanilla models (#5190) --- .../client/model/BlockStateLoader.java | 21 +++++++++---------- .../client/model/ForgeBlockStateV1.java | 5 +++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/minecraftforge/client/model/BlockStateLoader.java b/src/main/java/net/minecraftforge/client/model/BlockStateLoader.java index 05c5d125d6..790a5d9bab 100644 --- a/src/main/java/net/minecraftforge/client/model/BlockStateLoader.java +++ b/src/main/java/net/minecraftforge/client/model/BlockStateLoader.java @@ -28,6 +28,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import net.minecraft.client.renderer.model.IUnbakedModel; import net.minecraft.client.renderer.model.ModelBlockDefinition; @@ -95,14 +96,12 @@ public class BlockStateLoader for (ForgeBlockStateV1.Variant var : entry.getValue()) { boolean uvLock = var.getUvLock().orElse(false); - boolean smooth = var.getSmooth().orElse(true); - boolean gui3d = var.getGui3d().orElse(true); int weight = var.getWeight().orElse(1); - if (var.getModel() != null && var.getSubmodels().size() == 0 && var.getTextures().size() == 0 && var.getCustomData().size() == 0 && var.getState().orElse(ModelRotation.X0_Y0) instanceof ModelRotation) + if (var.isVanillaCompatible()) mcVars.add(new Variant(var.getModel(), (ModelRotation)var.getState().orElse(ModelRotation.X0_Y0), uvLock, weight)); else - mcVars.add(new ForgeVariant(location, var.getModel(), var.getState().orElse(TRSRTransformation.identity()), uvLock, smooth, gui3d, weight, var.getTextures(), var.getOnlyPartsVariant(), var.getCustomData())); + mcVars.add(new ForgeVariant(location, var.getModel(), var.getState().orElse(TRSRTransformation.identity()), uvLock, var.getSmooth(), var.getGui3d(), weight, var.getTextures(), var.getOnlyPartsVariant(), var.getCustomData())); } variants.put(entry.getKey(), new VariantList(mcVars)); } @@ -161,11 +160,11 @@ public class BlockStateLoader private final ImmutableMap textures; private final ImmutableMap parts; private final ImmutableMap customData; - private final boolean smooth; - private final boolean gui3d; + private final Optional smooth; + private final Optional gui3d; private final IModelState state; - public ForgeVariant(ResourceLocation blockstateLocation, @Nullable ResourceLocation model, IModelState state, boolean uvLock, boolean smooth, boolean gui3d, int weight, ImmutableMap textures, ImmutableMap parts, ImmutableMap customData) + ForgeVariant(ResourceLocation blockstateLocation, @Nullable ResourceLocation model, IModelState state, boolean uvLock, Optional smooth, Optional gui3d, int weight, ImmutableMap textures, ImmutableMap parts, ImmutableMap customData) { super(model == null ? new ResourceLocation("builtin/missing") : model, state instanceof ModelRotation ? (ModelRotation)state : ModelRotation.X0_Y0, uvLock, weight); this.blockstateLocation = blockstateLocation; @@ -177,12 +176,12 @@ public class BlockStateLoader this.gui3d = gui3d; } - private IUnbakedModel runModelHooks(IUnbakedModel base, boolean smooth, boolean gui3d, ImmutableMap textureMap, ImmutableMap customData) + private IUnbakedModel runModelHooks(IUnbakedModel base, Optional smooth, Optional gui3d, ImmutableMap textureMap, ImmutableMap customData) { base = base.process(customData); base = base.retexture(textureMap); - base = base.smoothLighting(smooth); - base = base.gui3d(gui3d); + base = smooth.map(base::smoothLighting).orElse(base); + base = gui3d.map(base::gui3d).orElse(base); return base; } @@ -221,7 +220,7 @@ public class BlockStateLoader model = ModelLoaderRegistry.getModelOrLogError(modelLocation, "Unable to load block sub-model: \'" + modelLocation); } - models.put(entry.getKey(), Pair.of(runModelHooks(model, part.smooth, part.gui3d, part.getTextures(), part.getCustomData()), part.getState())); + models.put(entry.getKey(), Pair.of(runModelHooks(model, Optional.of(part.smooth), Optional.of(part.gui3d), part.getTextures(), part.getCustomData()), part.getState())); } return new MultiModel(getModelLocation(), hasBase ? base : null, models.build()); diff --git a/src/main/java/net/minecraftforge/client/model/ForgeBlockStateV1.java b/src/main/java/net/minecraftforge/client/model/ForgeBlockStateV1.java index 56cddec336..d315a91d36 100644 --- a/src/main/java/net/minecraftforge/client/model/ForgeBlockStateV1.java +++ b/src/main/java/net/minecraftforge/client/model/ForgeBlockStateV1.java @@ -388,6 +388,11 @@ public class ForgeBlockStateV1 extends Marker return output; } + boolean isVanillaCompatible() + { + return model != null && submodels.isEmpty() && textures.isEmpty() && customData.isEmpty() && !smooth.isPresent() && !gui3d.isPresent() && state.orElse(ModelRotation.X0_Y0) instanceof ModelRotation; + } + protected SubModel asGenericSubModel() { return new SubModel(state.orElse(TRSRTransformation.identity()), uvLock.orElse(false), smooth.orElse(true), gui3d.orElse(true), getTextures(), model, getCustomData());