|
| 1 | +package com.plusls.ommc.mixin.feature.worldEaterMineHelper.sodium; |
| 2 | + |
| 3 | +import com.plusls.ommc.feature.worldEaterMineHelper.WorldEaterMineHelperUtil; |
| 4 | +import com.plusls.ommc.mixin.accessor.AccessorBlockRenderContext; |
| 5 | +import me.jellysquid.mods.sodium.client.render.chunk.compile.ChunkBuildBuffers; |
| 6 | +import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderContext; |
| 7 | +import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer; |
| 8 | +import me.jellysquid.mods.sodium.client.render.chunk.data.ChunkRenderBounds; |
| 9 | +import net.minecraft.client.resources.model.BakedModel; |
| 10 | +import org.jetbrains.annotations.NotNull; |
| 11 | +import org.spongepowered.asm.mixin.Dynamic; |
| 12 | +import org.spongepowered.asm.mixin.Mixin; |
| 13 | +import org.spongepowered.asm.mixin.Shadow; |
| 14 | +import org.spongepowered.asm.mixin.Unique; |
| 15 | +import org.spongepowered.asm.mixin.injection.At; |
| 16 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 17 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 18 | +import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; |
| 19 | +import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; |
| 20 | + |
| 21 | +/** |
| 22 | + * The implementation for mc [1.19.3, ~) |
| 23 | + */ |
| 24 | +@Dependencies(and = @Dependency(value = "sodium", versionPredicate = ">0.4.10 <0.5")) |
| 25 | +@Mixin(value = BlockRenderer.class, remap = false) |
| 26 | +public abstract class MixinBlockRenderer_0_4_11 { |
| 27 | + @Shadow(remap = false) |
| 28 | + public abstract void renderModel(BlockRenderContext ctx, ChunkBuildBuffers buffers, ChunkRenderBounds.Builder bounds); |
| 29 | + |
| 30 | + @Unique |
| 31 | + private final ThreadLocal<Boolean> ommc$renderTag = ThreadLocal.withInitial(() -> false); |
| 32 | + |
| 33 | + @Dynamic |
| 34 | + @Inject( |
| 35 | + method = "renderModel", |
| 36 | + at = @At( |
| 37 | + value = "RETURN" |
| 38 | + ) |
| 39 | + ) |
| 40 | + private void postRenderModel(@NotNull BlockRenderContext ctx, ChunkBuildBuffers buffers, ChunkRenderBounds.Builder bounds, CallbackInfo ci) { |
| 41 | + if (WorldEaterMineHelperUtil.shouldUseCustomModel(ctx.state(), ctx.pos()) && !this.ommc$renderTag.get()) { |
| 42 | + BakedModel customModel = WorldEaterMineHelperUtil.customModels.get(ctx.state().getBlock()); |
| 43 | + |
| 44 | + if (customModel != null) { |
| 45 | + this.ommc$renderTag.set(true); |
| 46 | + // This impl will break light system, so disable it. |
| 47 | + // int originalLightEmission = ctx.state().getLightEmission(); |
| 48 | + BakedModel originalModel = ctx.model(); |
| 49 | + // ((AccessorBlockStateBase) ctx.state()).setLightEmission(15); |
| 50 | + ((AccessorBlockRenderContext) ctx).setModel(customModel); |
| 51 | + this.renderModel(ctx, buffers, bounds); |
| 52 | + ((AccessorBlockRenderContext) ctx).setModel(originalModel); |
| 53 | + // ((AccessorBlockStateBase) ctx.state()).setLightEmission(originalLightEmission); |
| 54 | + this.ommc$renderTag.set(false); |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments