fix: more injection fix + bad culling

This commit is contained in:
Adrien1106 2024-06-14 16:51:25 +02:00
parent ddffd45a44
commit 42049047f7
5 changed files with 156 additions and 14 deletions

View File

@ -9,7 +9,7 @@ loader_version=0.15.11
# Mod Properties # Mod Properties
modrinth_id = jCpoCBpn modrinth_id = jCpoCBpn
mod_version = 1.6.1 mod_version = 1.6.2
maven_group = fr.adrien1106 maven_group = fr.adrien1106
archives_base_name = ReFramed archives_base_name = ReFramed
mod_id = reframed mod_id = reframed

View File

@ -6,11 +6,13 @@ import com.moulberry.axiom.utils.IntMatrix;
import com.moulberry.axiom.world_modification.CompressedBlockEntity; import com.moulberry.axiom.world_modification.CompressedBlockEntity;
import fr.adrien1106.reframed.client.model.MultiRetexturableModel; import fr.adrien1106.reframed.client.model.MultiRetexturableModel;
import fr.adrien1106.reframed.client.model.RetexturingBakedModel; import fr.adrien1106.reframed.client.model.RetexturingBakedModel;
import fr.adrien1106.reframed.util.DefaultList;
import fr.adrien1106.reframed.util.mixin.IAxiomChunkedBlockRegionMixin; import fr.adrien1106.reframed.util.mixin.IAxiomChunkedBlockRegionMixin;
import fr.adrien1106.reframed.util.mixin.IMultipartBakedModelMixin; import fr.adrien1106.reframed.util.mixin.IMultipartBakedModelMixin;
import fr.adrien1106.reframed.util.mixin.ThemedBlockEntity; import fr.adrien1106.reframed.util.mixin.ThemedBlockEntity;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Camera; import net.minecraft.client.render.Camera;
@ -78,15 +80,19 @@ public abstract class AxiomChunkedBlockRegionMixin implements IAxiomChunkedBlock
cancellable = true) cancellable = true)
private static void onRenderBlock(BufferBuilder blockBuilder, BlockRenderManager renderer, BlockPos.Mutable pos, Random rand, MatrixStack matrices, BlockRenderView world, Matrix4f currentPoseMatrix, Matrix4f basePoseMatrix, int x, int y, int z, BlockState state, boolean useAmbientOcclusion, CallbackInfo ci, @Local BakedModel model) { private static void onRenderBlock(BufferBuilder blockBuilder, BlockRenderManager renderer, BlockPos.Mutable pos, Random rand, MatrixStack matrices, BlockRenderView world, Matrix4f currentPoseMatrix, Matrix4f basePoseMatrix, int x, int y, int z, BlockState state, boolean useAmbientOcclusion, CallbackInfo ci, @Local BakedModel model) {
List<BakedModel> models; List<BakedModel> models;
if ((models = getModels(model, state)).isEmpty() // not a retexturable model if ((models = getModels(model, state)).isEmpty()) return;
|| !(world.getBlockEntity(pos) instanceof ThemedBlockEntity block_entity) // not a themed block entity
) return;
DefaultList<BlockState> themes = new DefaultList<>(
Blocks.AIR.getDefaultState(),
world.getBlockEntity(pos) instanceof ThemedBlockEntity themed
? themed.getThemes()
: List.of()
);
models.stream().flatMap(m -> m instanceof MultiRetexturableModel mm models.stream().flatMap(m -> m instanceof MultiRetexturableModel mm
? mm.models().stream() ? mm.models().stream()
: Stream.of((RetexturingBakedModel)m) : Stream.of((RetexturingBakedModel)m)
).forEach(m -> { ).forEach(m -> {
m.setCamo(world, block_entity.getTheme(m.getThemeIndex()), pos); m.setCamo(world, themes.get(m.getThemeIndex() - 1), pos);
if (useAmbientOcclusion && state.getLuminance() == 0 && m.useAmbientOcclusion()) renderer.getModelRenderer() if (useAmbientOcclusion && state.getLuminance() == 0 && m.useAmbientOcclusion()) renderer.getModelRenderer()
.renderSmooth(world, m, state, pos, matrices, blockBuilder, true, rand, state.getRenderingSeed(pos), OverlayTexture.DEFAULT_UV); .renderSmooth(world, m, state, pos, matrices, blockBuilder, true, rand, state.getRenderingSeed(pos), OverlayTexture.DEFAULT_UV);
else renderer.getModelRenderer() else renderer.getModelRenderer()

View File

@ -1,6 +1,5 @@
package fr.adrien1106.reframed.mixin.compat; package fr.adrien1106.reframed.mixin.compat;
import com.llamalad7.mixinextras.sugar.Local;
import fr.adrien1106.reframed.client.util.RenderHelper; import fr.adrien1106.reframed.client.util.RenderHelper;
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity; import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
import fr.adrien1106.reframed.util.mixin.IBlockRenderInfoMixin; import fr.adrien1106.reframed.util.mixin.IBlockRenderInfoMixin;
@ -24,7 +23,6 @@ public abstract class IndiumBlockRenderInfoMixin implements IBlockRenderInfoMixi
@Shadow public BlockPos blockPos; @Shadow public BlockPos blockPos;
@Shadow public BlockRenderView blockView; @Shadow public BlockRenderView blockView;
@Shadow public BlockState blockState; @Shadow public BlockState blockState;
@Shadow(remap = false) private int cullResultFlags;
@Unique private int theme_index = 0; @Unique private int theme_index = 0;
@Unique private int model_hash = 0; @Unique private int model_hash = 0;
@ -32,19 +30,18 @@ public abstract class IndiumBlockRenderInfoMixin implements IBlockRenderInfoMixi
@Inject( @Inject(
method = "shouldDrawFace", method = "shouldDrawFace",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE_ASSIGN",
target = "Llink/infra/indium/renderer/render/BlockRenderInfo;shouldDrawFaceInner(Lnet/minecraft/util/math/Direction;)Z" target = "Lnet/minecraft/util/math/Direction;getId()I",
shift = At.Shift.AFTER
), ),
cancellable = true cancellable = true
) )
private void shouldDrawInnerFace(Direction face, CallbackInfoReturnable<Boolean> cir, @Local int mask) { private void shouldDrawInnerFace(Direction face, CallbackInfoReturnable<Boolean> cir) {
BlockPos other_pos = blockPos.offset(face); BlockPos other_pos = blockPos.offset(face);
if (!(blockView.getBlockEntity(blockPos) instanceof ThemeableBlockEntity if (!(blockView.getBlockEntity(blockPos) instanceof ThemeableBlockEntity
|| blockView.getBlockEntity(other_pos) instanceof ThemeableBlockEntity) || blockView.getBlockEntity(other_pos) instanceof ThemeableBlockEntity)
) return; ) return;
boolean result = RenderHelper.shouldDrawSide(blockState, blockView, blockPos, face, other_pos, theme_index); cir.setReturnValue(RenderHelper.shouldDrawSide(blockState, blockView, blockPos, face, other_pos, theme_index));
if (result) cullResultFlags |= mask;
cir.setReturnValue(result);
} }
@Override @Override

View File

@ -42,7 +42,6 @@ public abstract class IndiumNonTerrainBlockRenderContextMixin extends AbstractBl
target = "Llink/infra/indium/renderer/render/BlockRenderInfo;prepareForWorld(Lnet/minecraft/world/BlockRenderView;Z)V", target = "Llink/infra/indium/renderer/render/BlockRenderInfo;prepareForWorld(Lnet/minecraft/world/BlockRenderView;Z)V",
shift = At.Shift.AFTER shift = At.Shift.AFTER
), ),
remap = false,
cancellable = true cancellable = true
) )
private void renderMultipleModels(BlockRenderView blockView, BakedModel wrapper, BlockState state, BlockPos pos, MatrixStack matrixStack, VertexConsumer buffer, boolean cull, Random random, long seed, int overlay, CallbackInfo ci) { private void renderMultipleModels(BlockRenderView blockView, BakedModel wrapper, BlockState state, BlockPos pos, MatrixStack matrixStack, VertexConsumer buffer, boolean cull, Random random, long seed, int overlay, CallbackInfo ci) {

View File

@ -0,0 +1,140 @@
package fr.adrien1106.reframed.util;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
public class DefaultList<T> implements List<T> {
protected T default_value;
protected List<T> elements;
public DefaultList(T default_value, List<T> elements) {
this.default_value = default_value;
this.elements = elements;
}
@Override
public int size() {
return elements.size();
}
@Override
public boolean isEmpty() {
return elements.isEmpty();
}
@Override
public boolean contains(Object o) {
return elements.contains(o) || default_value.equals(o);
}
@NotNull
@Override
public Iterator<T> iterator() {
return elements.iterator();
}
@NotNull
@Override
public Object[] toArray() {
return elements.toArray();
}
@NotNull
@Override
public <T1> T1[] toArray(@NotNull T1[] a) {
return elements.toArray(a);
}
@Override
public boolean add(T t) {
return elements.add(t);
}
@Override
public boolean remove(Object o) {
return elements.remove(o);
}
@Override
public boolean containsAll(@NotNull Collection<?> c) {
return elements.containsAll(c);
}
@Override
public boolean addAll(@NotNull Collection<? extends T> c) {
return elements.addAll(c);
}
@Override
public boolean addAll(int index, @NotNull Collection<? extends T> c) {
return elements.addAll(index, c);
}
@Override
public boolean removeAll(@NotNull Collection<?> c) {
return elements.removeAll(c);
}
@Override
public boolean retainAll(@NotNull Collection<?> c) {
return elements.retainAll(c);
}
@Override
public void clear() {
elements.clear();
}
@Override
public T get(int index) {
return index < elements.size() && index >= 0 ? elements.get(index) : default_value;
}
@Override
public T set(int index, T element) {
return elements.set(index, element);
}
@Override
public void add(int index, T element) {
elements.add(index, element);
}
@Override
public T remove(int index) {
return elements.remove(index);
}
@Override
public int indexOf(Object o) {
return elements.indexOf(o);
}
@Override
public int lastIndexOf(Object o) {
return elements.lastIndexOf(o);
}
@NotNull
@Override
public ListIterator<T> listIterator() {
return elements.listIterator();
}
@NotNull
@Override
public ListIterator<T> listIterator(int index) {
return elements.listIterator();
}
@NotNull
@Override
public List<T> subList(int fromIndex, int toIndex) {
return elements.subList(fromIndex, toIndex);
}
}