Improvement for cache fixing issues + 4 new blocks #14

Merged
Adrien1106 merged 6 commits from dev into master 2024-05-14 15:53:29 +02:00
11 changed files with 45 additions and 22 deletions
Showing only changes of commit c6f2244826 - Show all commits

View File

@ -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<ForwardingBakedModel> models() {
public List<RetexturingBakedModel> models() {
return List.of(model_1, model_2);
}
}

View File

@ -6,5 +6,5 @@ import java.util.List;
public interface MultiRetexturableModel {
List<ForwardingBakedModel> models();
List<RetexturingBakedModel> models();
}

View File

@ -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);

View File

@ -41,8 +41,8 @@ public class UnbakedDoubleRetexturedModel implements UnbakedModel {
@Override
public BakedModel bake(Baker baker, Function<SpriteIdentifier, Sprite> 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)
);
}
}

View File

@ -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<ForwardingBakedModel> models) {
public static void computeInnerCull(BlockState state, List<RetexturingBakedModel> 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;

View File

@ -14,9 +14,11 @@ import java.util.Map;
public class RebakedModel implements BakedModel {
protected final Map<Direction, List<BakedQuad>> face_quads;
protected boolean ambient_occlusion = true;
public RebakedModel(Map<Direction, List<BakedQuad>> face_quads) {
public RebakedModel(Map<Direction, List<BakedQuad>> 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

View File

@ -32,6 +32,8 @@ public abstract class AthenaBakedModelMixin implements DynamicBakedModel, BakedM
@Shadow(remap = false) @Final private Int2ObjectMap<Sprite> 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());
}
}

View File

@ -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());
}
}

View File

@ -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<ForwardingBakedModel> models = retexturing_model.models();
List<RetexturingBakedModel> 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();

View File

@ -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());
}

View File

@ -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<ForwardingBakedModel> models = retexturing_model.models();
List<RetexturingBakedModel> 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();