Skip to content

Commit

Permalink
Redirect getRenderTypes calls from the Sodium & vanilla chunk meshers
Browse files Browse the repository at this point in the history
Fixes glass not being translucent with mods like XyCraft, as they
override these methods
  • Loading branch information
embeddedt committed Jan 4, 2024
1 parent 1b2097a commit 7063ff9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.coderbot.iris.mixin;

import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Holder;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.ChunkRenderTypeSet;
import net.minecraftforge.client.model.data.ModelData;
import net.minecraftforge.registries.ForgeRegistries;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.Map;

@Mixin(ChunkRenderDispatcher.RenderChunk.RebuildTask.class)
public class MixinChunkRenderDispatcherRebuildTask {
@Redirect(method = "compile", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/BakedModel;getRenderTypes(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/util/RandomSource;Lnet/minecraftforge/client/model/data/ModelData;)Lnet/minecraftforge/client/ChunkRenderTypeSet;"))
private ChunkRenderTypeSet oculus$overrideRenderTypes(BakedModel instance, BlockState blockState, RandomSource randomSource, ModelData modelData) {
Map<Holder.Reference<Block>, ChunkRenderTypeSet> idMap = BlockRenderingSettings.INSTANCE.getBlockTypeIds();
if (idMap != null) {
ChunkRenderTypeSet type = idMap.get(ForgeRegistries.BLOCKS.getDelegateOrThrow(blockState.getBlock()));
if (type != null) {
return type;
}
}

return instance.getRenderTypes(blockState, randomSource, modelData);
}
}
1 change: 1 addition & 0 deletions src/main/resources/mixins.oculus.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"MixinChainedJsonException",
"MixinBooleanState",
"MixinBiomes",
"MixinChunkRenderDispatcherRebuildTask",
"MixinClientLanguage",
"MixinClientPacketListener",
"MixinDebugScreenOverlay",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.coderbot.iris.compat.sodium.mixin.shader_overrides;

import me.jellysquid.mods.sodium.client.render.chunk.compile.tasks.ChunkBuilderMeshingTask;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Holder;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.ChunkRenderTypeSet;
import net.minecraftforge.client.model.data.ModelData;
import net.minecraftforge.registries.ForgeRegistries;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.Map;

@Mixin(ChunkBuilderMeshingTask.class)
public class MixinChunkBuilderMeshingTask {
/**
* @author embeddedt
* @reason On Forge, render types are not intended to be driven by a central registry like in vanilla; instead, they
* get queried from the block model during meshing. Only the default baked models defer to the vanilla registry;
* specifying a render type in the model JSON or using a custom model will return its own value. Thus, we need
* to redirect the access at a higher level.
*/
@Redirect(method = "execute(Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildContext;Lme/jellysquid/mods/sodium/client/util/task/CancellationToken;)Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildOutput;",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/BakedModel;getRenderTypes(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/util/RandomSource;Lnet/minecraftforge/client/model/data/ModelData;)Lnet/minecraftforge/client/ChunkRenderTypeSet;"),
remap = false)
private ChunkRenderTypeSet oculus$overrideRenderTypes(BakedModel instance, BlockState blockState, RandomSource randomSource, ModelData modelData) {
Map<Holder.Reference<Block>, ChunkRenderTypeSet> idMap = BlockRenderingSettings.INSTANCE.getBlockTypeIds();
if (idMap != null) {
ChunkRenderTypeSet type = idMap.get(ForgeRegistries.BLOCKS.getDelegateOrThrow(blockState.getBlock()));
if (type != null) {
return type;
}
}

return instance.getRenderTypes(blockState, randomSource, modelData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"copyEntity.shadows.EntityRenderDispatcherMixin",
"font.MixinGlyphRenderer",
"pbr_animation.MixinSpriteContents",
"shader_overrides.MixinChunkBuilderMeshingTask",
"shader_overrides.MixinGlProgram",
"shader_overrides.MixinRegionChunkRenderer",
"shader_overrides.MixinShaderChunkRenderer",
Expand Down

0 comments on commit 7063ff9

Please sign in to comment.