diff --git a/src/main/java/fr/adrien1106/reframed/client/model/DoubleRetexturingBakedModel.java b/src/main/java/fr/adrien1106/reframed/client/model/DoubleRetexturingBakedModel.java index a50806c..c700b87 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/DoubleRetexturingBakedModel.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/DoubleRetexturingBakedModel.java @@ -17,8 +17,8 @@ import java.util.function.Supplier; @Environment(EnvType.CLIENT) public class DoubleRetexturingBakedModel extends ForwardingBakedModel implements MultiRetexturableModel { - private final ForwardingBakedModel model_1, model_2; - public DoubleRetexturingBakedModel(ForwardingBakedModel model_1, ForwardingBakedModel model_2) { + private final RetexturingBakedModel model_1, model_2; + public DoubleRetexturingBakedModel(RetexturingBakedModel model_1, RetexturingBakedModel model_2) { this.wrapped = model_1.getWrappedModel(); this.model_1 = model_1; this.model_2 = model_2; @@ -44,7 +44,7 @@ public class DoubleRetexturingBakedModel extends ForwardingBakedModel implements } @Override - public List models() { + public List models() { return List.of(model_1, model_2); } } diff --git a/src/main/java/fr/adrien1106/reframed/client/model/MultiRetexturableModel.java b/src/main/java/fr/adrien1106/reframed/client/model/MultiRetexturableModel.java index 17ea436..60f8c02 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/MultiRetexturableModel.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/MultiRetexturableModel.java @@ -6,5 +6,5 @@ import java.util.List; public interface MultiRetexturableModel { - List models(); + List models(); } diff --git a/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java b/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java index 9400b1a..45f4b67 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java @@ -153,7 +153,14 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { context.popTransform(); } } - + + public boolean useAmbientOcclusion(BlockRenderView view, BlockPos pos) { + if (!(view.getBlockEntity(pos) instanceof ThemeableBlockEntity frame_entity)) return false; + CamoAppearance appearance = appearance_manager + .getCamoAppearance(view, frame_entity.getTheme(theme_index), pos, theme_index, false); + return appearance.getAO(theme_index); + } + protected Mesh getRetexturedMesh(MeshCacheKey key, BlockState state) { if (RETEXTURED_MESH_CACHE.asMap().containsKey(key)) return RETEXTURED_MESH_CACHE.getIfPresent(key); Mesh mesh = transformMesh(key, state); diff --git a/src/main/java/fr/adrien1106/reframed/client/model/UnbakedDoubleRetexturedModel.java b/src/main/java/fr/adrien1106/reframed/client/model/UnbakedDoubleRetexturedModel.java index 70d53d6..b9e0784 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/UnbakedDoubleRetexturedModel.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/UnbakedDoubleRetexturedModel.java @@ -41,8 +41,8 @@ public class UnbakedDoubleRetexturedModel implements UnbakedModel { @Override public BakedModel bake(Baker baker, Function texture_getter, ModelBakeSettings model_bake_settings, Identifier identifier) { return new DoubleRetexturingBakedModel( - (ForwardingBakedModel) model_1.bake(baker, texture_getter, model_bake_settings, identifier), - (ForwardingBakedModel) model_2.bake(baker, texture_getter, model_bake_settings, identifier) + (RetexturingBakedModel) model_1.bake(baker, texture_getter, model_bake_settings, identifier), + (RetexturingBakedModel) model_2.bake(baker, texture_getter, model_bake_settings, identifier) ); } } diff --git a/src/main/java/fr/adrien1106/reframed/client/util/RenderHelper.java b/src/main/java/fr/adrien1106/reframed/client/util/RenderHelper.java index 12a4481..d990f70 100644 --- a/src/main/java/fr/adrien1106/reframed/client/util/RenderHelper.java +++ b/src/main/java/fr/adrien1106/reframed/client/util/RenderHelper.java @@ -5,6 +5,7 @@ import com.google.common.cache.CacheBuilder; import fr.adrien1106.reframed.block.ReFramedBlock; import fr.adrien1106.reframed.client.ReFramedClient; import fr.adrien1106.reframed.client.model.QuadPosBounds; +import fr.adrien1106.reframed.client.model.RetexturingBakedModel; import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -40,7 +41,7 @@ public class RenderHelper { * @param state - the state of the model * @param models - list of models on the same block */ - public static void computeInnerCull(BlockState state, List models) { + public static void computeInnerCull(BlockState state, List models) { if (!(state.getBlock() instanceof ReFramedBlock frame_block)) return; Object key = frame_block.getModelCacheKey(state); if (INNER_CULL_MAP.asMap().containsKey(new CullElement(frame_block, key, 1))) return; diff --git a/src/main/java/fr/adrien1106/reframed/compat/RebakedModel.java b/src/main/java/fr/adrien1106/reframed/compat/RebakedModel.java index cb5c54c..1a15c51 100644 --- a/src/main/java/fr/adrien1106/reframed/compat/RebakedModel.java +++ b/src/main/java/fr/adrien1106/reframed/compat/RebakedModel.java @@ -14,9 +14,11 @@ import java.util.Map; public class RebakedModel implements BakedModel { protected final Map> face_quads; + protected boolean ambient_occlusion = true; - public RebakedModel(Map> face_quads) { + public RebakedModel(Map> face_quads, boolean ambient_occlusion) { this.face_quads = face_quads; + this.ambient_occlusion = ambient_occlusion; } @Override @@ -26,7 +28,7 @@ public class RebakedModel implements BakedModel { @Override public boolean useAmbientOcclusion() { - return true; + return ambient_occlusion; } @Override diff --git a/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaBakedModelMixin.java b/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaBakedModelMixin.java index 20bd2f4..d2ab335 100644 --- a/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaBakedModelMixin.java +++ b/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaBakedModelMixin.java @@ -32,6 +32,8 @@ public abstract class AthenaBakedModelMixin implements DynamicBakedModel, BakedM @Shadow(remap = false) @Final private Int2ObjectMap textures; + @Shadow public abstract boolean useAmbientOcclusion(); + /** * Reuses the emitQuad method to compute the quads to be used by the frame * @@ -77,6 +79,6 @@ public abstract class AthenaBakedModelMixin implements DynamicBakedModel, BakedM })); }); - return new RebakedModel(face_quads); + return new RebakedModel(face_quads, useAmbientOcclusion()); } } diff --git a/src/main/java/fr/adrien1106/reframed/mixin/compat/ContinuityCTMBakedModelMixin.java b/src/main/java/fr/adrien1106/reframed/mixin/compat/ContinuityCTMBakedModelMixin.java index 4add74d..2c10205 100644 --- a/src/main/java/fr/adrien1106/reframed/mixin/compat/ContinuityCTMBakedModelMixin.java +++ b/src/main/java/fr/adrien1106/reframed/mixin/compat/ContinuityCTMBakedModelMixin.java @@ -89,6 +89,6 @@ public abstract class ContinuityCTMBakedModelMixin extends ForwardingBakedModel transform.getProcessingContext().reset(); // reset instead of outputting to emitter transform.invokeReset(); - return new RebakedModel(face_quads); + return new RebakedModel(face_quads, useAmbientOcclusion()); } } diff --git a/src/main/java/fr/adrien1106/reframed/mixin/compat/IndiumTerrainRenderContextMixin.java b/src/main/java/fr/adrien1106/reframed/mixin/compat/IndiumTerrainRenderContextMixin.java index 5855735..dec30dd 100644 --- a/src/main/java/fr/adrien1106/reframed/mixin/compat/IndiumTerrainRenderContextMixin.java +++ b/src/main/java/fr/adrien1106/reframed/mixin/compat/IndiumTerrainRenderContextMixin.java @@ -1,14 +1,13 @@ package fr.adrien1106.reframed.mixin.compat; import fr.adrien1106.reframed.client.model.MultiRetexturableModel; +import fr.adrien1106.reframed.client.model.RetexturingBakedModel; import fr.adrien1106.reframed.client.util.RenderHelper; import fr.adrien1106.reframed.util.mixin.IBlockRenderInfoMixin; import fr.adrien1106.reframed.util.mixin.IMultipartBakedModelMixin; import link.infra.indium.renderer.render.AbstractBlockRenderContext; import link.infra.indium.renderer.render.TerrainRenderContext; import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderContext; -import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; -import net.minecraft.client.render.model.BakedModel; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -31,13 +30,17 @@ public abstract class IndiumTerrainRenderContextMixin extends AbstractBlockRende if (!(ctx.model() instanceof IMultipartBakedModelMixin wrapped) || !(wrapped.getModel(ctx.state()) instanceof MultiRetexturableModel retexturing_model)) return; - List models = retexturing_model.models(); + List models = retexturing_model.models(); RenderHelper.computeInnerCull(ctx.state(), models); int i = 0; - for (BakedModel model : models) { + for (RetexturingBakedModel model : models) { i++; aoCalc.clear(); - ((IBlockRenderInfoMixin) blockInfo).prepareForBlock(ctx.state(), ctx.pos(), ctx.seed(), model.useAmbientOcclusion(), i); + ((IBlockRenderInfoMixin) blockInfo).prepareForBlock( + ctx.state(), ctx.pos(), ctx.seed(), + model.useAmbientOcclusion(blockInfo.blockView, ctx.pos()), + i + ); model.emitBlockQuads(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, blockInfo.randomSupplier, this); } ci.cancel(); diff --git a/src/main/java/fr/adrien1106/reframed/mixin/render/AbstractBlockRenderContextMixin.java b/src/main/java/fr/adrien1106/reframed/mixin/render/AbstractBlockRenderContextMixin.java index 388ea4a..3913a71 100644 --- a/src/main/java/fr/adrien1106/reframed/mixin/render/AbstractBlockRenderContextMixin.java +++ b/src/main/java/fr/adrien1106/reframed/mixin/render/AbstractBlockRenderContextMixin.java @@ -29,7 +29,11 @@ public abstract class AbstractBlockRenderContextMixin { ) ) private boolean shouldDrawInnerQuad(AbstractBlockRenderContext instance, Direction face, @Local(argsOnly = true) MutableQuadViewImpl quad) { - if (face != null || quad.tag() == 0 || !(blockInfo instanceof IBlockRenderInfoMixin info) || info.getThemeIndex() == 0) return isFaceCulled(face); + if (face != null + || quad.tag() == 0 + || !(blockInfo instanceof IBlockRenderInfoMixin info) + || info.getThemeIndex() == 0 + ) return isFaceCulled(face); return !RenderHelper.shouldDrawInnerFace(blockInfo.blockState, blockInfo.blockView, blockInfo.blockPos, quad.tag() >>> 8, info.getThemeIndex()); } diff --git a/src/main/java/fr/adrien1106/reframed/mixin/render/TerrainRenderContextMixin.java b/src/main/java/fr/adrien1106/reframed/mixin/render/TerrainRenderContextMixin.java index 41e1813..f4906c8 100644 --- a/src/main/java/fr/adrien1106/reframed/mixin/render/TerrainRenderContextMixin.java +++ b/src/main/java/fr/adrien1106/reframed/mixin/render/TerrainRenderContextMixin.java @@ -1,10 +1,10 @@ package fr.adrien1106.reframed.mixin.render; import fr.adrien1106.reframed.client.model.MultiRetexturableModel; +import fr.adrien1106.reframed.client.model.RetexturingBakedModel; import fr.adrien1106.reframed.client.util.RenderHelper; import fr.adrien1106.reframed.util.mixin.IBlockRenderInfoMixin; import fr.adrien1106.reframed.util.mixin.IMultipartBakedModelMixin; -import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; import net.fabricmc.fabric.impl.client.indigo.renderer.render.AbstractBlockRenderContext; import net.fabricmc.fabric.impl.client.indigo.renderer.render.TerrainRenderContext; import net.minecraft.block.BlockState; @@ -30,13 +30,17 @@ public abstract class TerrainRenderContextMixin extends AbstractBlockRenderConte if (!(wrapper instanceof IMultipartBakedModelMixin wrapped) || !(wrapped.getModel(state) instanceof MultiRetexturableModel retexturing_model)) return; - List models = retexturing_model.models(); + List models = retexturing_model.models(); RenderHelper.computeInnerCull(state, models); int i = 0; - for (BakedModel model : models) { + for (RetexturingBakedModel model : models) { i++; aoCalc.clear(); - ((IBlockRenderInfoMixin) blockInfo).prepareForBlock(state, pos, model.useAmbientOcclusion(), i); + ((IBlockRenderInfoMixin) blockInfo).prepareForBlock( + state, pos, + model.useAmbientOcclusion(blockInfo.blockView, pos), + i + ); model.emitBlockQuads(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, blockInfo.randomSupplier, this); } ci.cancel();