hibiscus/src/main/java/codes/som/hibiscus/mixins/xray/MixinBlockOcclusionCache.java

44 lines
1.6 KiB
Java

package codes.som.hibiscus.mixins.xray;
import codes.som.hibiscus.subsystems.xray.XrayBlockView;
import codes.som.hibiscus.subsystems.xray.XraySystem;
import me.jellysquid.mods.sodium.client.render.occlusion.BlockOcclusionCache;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(BlockOcclusionCache.class)
public abstract class MixinBlockOcclusionCache {
@Shadow
public abstract boolean shouldDrawSide(BlockState selfState, BlockView view, BlockPos pos, Direction facing);
private boolean ignoreShouldDrawSide = false;
@Inject(method = "shouldDrawSide", at = @At("RETURN"), cancellable = true)
private void onShouldDrawSide(BlockState selfState, BlockView view, BlockPos pos, Direction facing, CallbackInfoReturnable<Boolean> cir) {
if (ignoreShouldDrawSide)
return;
if (!XraySystem.shouldRenderXray())
return;
if (!XraySystem.isXrayBlock(selfState)) {
cir.setReturnValue(false);
return;
}
var xrayView = new XrayBlockView(view);
ignoreShouldDrawSide = true;
boolean xrayShouldDrawSide = this.shouldDrawSide(selfState, xrayView, pos, facing);
ignoreShouldDrawSide = false;
cir.setReturnValue(xrayShouldDrawSide);
}
}