From 42049047f7641714ac39d653f5f4e2f81ffbb767 Mon Sep 17 00:00:00 2001 From: Adrien1106 Date: Fri, 14 Jun 2024 16:51:25 +0200 Subject: [PATCH] fix: more injection fix + bad culling --- gradle.properties | 2 +- .../compat/AxiomChunkedBlockRegionMixin.java | 14 +- .../compat/IndiumBlockRenderInfoMixin.java | 13 +- ...diumNonTerrainBlockRenderContextMixin.java | 1 - .../adrien1106/reframed/util/DefaultList.java | 140 ++++++++++++++++++ 5 files changed, 156 insertions(+), 14 deletions(-) create mode 100644 src/main/java/fr/adrien1106/reframed/util/DefaultList.java diff --git a/gradle.properties b/gradle.properties index 1768ec4..91ac973 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ loader_version=0.15.11 # Mod Properties modrinth_id = jCpoCBpn -mod_version = 1.6.1 +mod_version = 1.6.2 maven_group = fr.adrien1106 archives_base_name = ReFramed mod_id = reframed diff --git a/src/main/java/fr/adrien1106/reframed/mixin/compat/AxiomChunkedBlockRegionMixin.java b/src/main/java/fr/adrien1106/reframed/mixin/compat/AxiomChunkedBlockRegionMixin.java index f38b81e..2285f1f 100644 --- a/src/main/java/fr/adrien1106/reframed/mixin/compat/AxiomChunkedBlockRegionMixin.java +++ b/src/main/java/fr/adrien1106/reframed/mixin/compat/AxiomChunkedBlockRegionMixin.java @@ -6,11 +6,13 @@ import com.moulberry.axiom.utils.IntMatrix; import com.moulberry.axiom.world_modification.CompressedBlockEntity; import fr.adrien1106.reframed.client.model.MultiRetexturableModel; 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.IMultipartBakedModelMixin; import fr.adrien1106.reframed.util.mixin.ThemedBlockEntity; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; import net.minecraft.block.entity.BlockEntity; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Camera; @@ -78,15 +80,19 @@ public abstract class AxiomChunkedBlockRegionMixin implements IAxiomChunkedBlock 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) { List models; - if ((models = getModels(model, state)).isEmpty() // not a retexturable model - || !(world.getBlockEntity(pos) instanceof ThemedBlockEntity block_entity) // not a themed block entity - ) return; + if ((models = getModels(model, state)).isEmpty()) return; + DefaultList themes = new DefaultList<>( + Blocks.AIR.getDefaultState(), + world.getBlockEntity(pos) instanceof ThemedBlockEntity themed + ? themed.getThemes() + : List.of() + ); models.stream().flatMap(m -> m instanceof MultiRetexturableModel mm ? mm.models().stream() : Stream.of((RetexturingBakedModel)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() .renderSmooth(world, m, state, pos, matrices, blockBuilder, true, rand, state.getRenderingSeed(pos), OverlayTexture.DEFAULT_UV); else renderer.getModelRenderer() diff --git a/src/main/java/fr/adrien1106/reframed/mixin/compat/IndiumBlockRenderInfoMixin.java b/src/main/java/fr/adrien1106/reframed/mixin/compat/IndiumBlockRenderInfoMixin.java index cfe0aaf..c004fd4 100644 --- a/src/main/java/fr/adrien1106/reframed/mixin/compat/IndiumBlockRenderInfoMixin.java +++ b/src/main/java/fr/adrien1106/reframed/mixin/compat/IndiumBlockRenderInfoMixin.java @@ -1,6 +1,5 @@ package fr.adrien1106.reframed.mixin.compat; -import com.llamalad7.mixinextras.sugar.Local; import fr.adrien1106.reframed.client.util.RenderHelper; import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity; import fr.adrien1106.reframed.util.mixin.IBlockRenderInfoMixin; @@ -24,7 +23,6 @@ public abstract class IndiumBlockRenderInfoMixin implements IBlockRenderInfoMixi @Shadow public BlockPos blockPos; @Shadow public BlockRenderView blockView; @Shadow public BlockState blockState; - @Shadow(remap = false) private int cullResultFlags; @Unique private int theme_index = 0; @Unique private int model_hash = 0; @@ -32,19 +30,18 @@ public abstract class IndiumBlockRenderInfoMixin implements IBlockRenderInfoMixi @Inject( method = "shouldDrawFace", at = @At( - value = "INVOKE", - target = "Llink/infra/indium/renderer/render/BlockRenderInfo;shouldDrawFaceInner(Lnet/minecraft/util/math/Direction;)Z" + value = "INVOKE_ASSIGN", + target = "Lnet/minecraft/util/math/Direction;getId()I", + shift = At.Shift.AFTER ), cancellable = true ) - private void shouldDrawInnerFace(Direction face, CallbackInfoReturnable cir, @Local int mask) { + private void shouldDrawInnerFace(Direction face, CallbackInfoReturnable cir) { BlockPos other_pos = blockPos.offset(face); if (!(blockView.getBlockEntity(blockPos) instanceof ThemeableBlockEntity || blockView.getBlockEntity(other_pos) instanceof ThemeableBlockEntity) ) return; - boolean result = RenderHelper.shouldDrawSide(blockState, blockView, blockPos, face, other_pos, theme_index); - if (result) cullResultFlags |= mask; - cir.setReturnValue(result); + cir.setReturnValue(RenderHelper.shouldDrawSide(blockState, blockView, blockPos, face, other_pos, theme_index)); } @Override diff --git a/src/main/java/fr/adrien1106/reframed/mixin/compat/IndiumNonTerrainBlockRenderContextMixin.java b/src/main/java/fr/adrien1106/reframed/mixin/compat/IndiumNonTerrainBlockRenderContextMixin.java index f435b3d..d392cb7 100644 --- a/src/main/java/fr/adrien1106/reframed/mixin/compat/IndiumNonTerrainBlockRenderContextMixin.java +++ b/src/main/java/fr/adrien1106/reframed/mixin/compat/IndiumNonTerrainBlockRenderContextMixin.java @@ -42,7 +42,6 @@ public abstract class IndiumNonTerrainBlockRenderContextMixin extends AbstractBl target = "Llink/infra/indium/renderer/render/BlockRenderInfo;prepareForWorld(Lnet/minecraft/world/BlockRenderView;Z)V", shift = At.Shift.AFTER ), - remap = false, 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) { diff --git a/src/main/java/fr/adrien1106/reframed/util/DefaultList.java b/src/main/java/fr/adrien1106/reframed/util/DefaultList.java new file mode 100644 index 0000000..6213dcf --- /dev/null +++ b/src/main/java/fr/adrien1106/reframed/util/DefaultList.java @@ -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 implements List { + + protected T default_value; + protected List elements; + + public DefaultList(T default_value, List 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 iterator() { + return elements.iterator(); + } + + @NotNull + @Override + public Object[] toArray() { + return elements.toArray(); + } + + @NotNull + @Override + public 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 c) { + return elements.addAll(c); + } + + @Override + public boolean addAll(int index, @NotNull Collection 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 listIterator() { + return elements.listIterator(); + } + + @NotNull + @Override + public ListIterator listIterator(int index) { + return elements.listIterator(); + } + + @NotNull + @Override + public List subList(int fromIndex, int toIndex) { + return elements.subList(fromIndex, toIndex); + } +} -- 2.39.5